java重写重定向_java – 重写spring-security重定向URL

我正在尝试让Tuckey UrlRewriteFilter为我的webapp整理网址.我遇到的一个问题是,当

spring-security注意到匿名用户试图访问受保护资源时,它会重定向到包含servlet路径的URL.

我想要的是,例如:

> GET http://localhost:8080/my-context/protected-resource

< Location: http://localhost:8080/my-context/login

我目前得到的是:

> GET http://localhost:8080/my-context/protected-resource

< Location: http://localhost:8080/my-context/-/login

到目前为止我找到的相关文件:

我想知道的是:

>可以/应该说服Tuckey重写Location标头. 在这里似乎没有任何帮助.

>可以/我应该以某种方式调整SS配置以发出重写的URL.我认为这不是很整洁,因为如果禁用重写就会中断.

web.xml看起来像

UrlRewriteFilter

org.tuckey.web.filters.urlrewrite.UrlRewriteFilter

LogLevel

log4j

UrlRewriteFilter

/*

REQUEST

springSecurityFilterChain

org.springframework.web.filter.DelegatingFilterProxy

springSecurityFilterChain

/*

REQUEST

FORWARD

INCLUDE

ERROR

my-servlet

org.springframework.web.servlet.DispatcherServlet

1

psms

/-/*

urlrewrite.xml看起来像:

^/(.*)$

/-/$1

applicationContent-security.xml看起来像:

login-processing-url="/-/login.do"

authentication-failure-url="/-/login?login_error"

default-target-url="/-/index"

always-use-default-target="true"/>

logout-success-url="/-/login"/>

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Spring Boot整合Spring Security可以实现对应用程序的安全认证和授权功能。下面是一个简单的示例: 1. 添加Spring Security依赖:在pom.xml文件中添加以下依赖: ```xml <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-security</artifactId> </dependency> ``` 2. 创建一个配置类:创建一个继承自WebSecurityConfigurerAdapter的配置类,并重写configure方法来配置安全策略。以下是一个示例: ```java @Configuration @EnableWebSecurity public class SecurityConfig extends WebSecurityConfigurerAdapter { @Override protected void configure(HttpSecurity http) throws Exception { http .authorizeRequests() .antMatchers("/", "/home").permitAll() .anyRequest().authenticated() .and() .formLogin() .loginPage("/login") .permitAll() .and() .logout() .permitAll(); } @Autowired public void configureGlobal(AuthenticationManagerBuilder auth) throws Exception { auth .inMemoryAuthentication() .withUser("user").password("password").roles("USER"); } } ``` 上述示例中的configure方法配置了对应用程序路径的访问权限,configureGlobal方法配置了一个简单的内存用户认证。 3. 创建登录页面:在src/main/resources/static目录下创建一个login.html文件作为登录页面。 4. 运行应用程序:启动Spring Boot应用程序,并访问相应的URL(例如,http://localhost:8080/login)试图访问受保护的资源。系统将会自动重定向到登录页面,输入用户名和密码后即可访问受保护的资源。 上述步骤是一个简单的Spring Boot整合Spring Security的示例。你可以根据自己的需求进行更复杂的配置和定制。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值