【发布时间】:2015-06-29 06:06:49
【问题描述】:
在我的配置中 Spring Boot WebSecurityConfig 有一个过滤器,我需要查看用户是否有过期的密码,如果在应用程序上启用了它..
@Configuration
@EnableWebMvcSecurity
public class WebSecurityConfig extends WebSecurityConfigurerAdapter {
@Autowired
IdentityService userDetailsService;
@Autowired
AccountFilter accountFilter;
@Override
protected void configure(HttpSecurity http) throws Exception {
http
.csrf()
.and()
.authorizeRequests()
.antMatchers("/login", "/recover-credntial",
"/logout", "/resources/**").permitAll()
.and()
.formLogin()
.loginPage("/login").failureUrl("/login?error")
.usernameParameter("username")
.passwordParameter("password")
.permitAll()
.and()
.logout()
.logoutSuccessUrl("/login?logout")
.permitAll()
.and()
.exceptionHandling()
.accessDeniedPage("/403")
.and().addFilterAfter(accountFilter, UsernamePasswordAuthenticationFilter.class);
}
@Override
protected void configure(AuthenticationManagerBuilder authManagerBuilder)
throws Exception {
authManagerBuilder.userDetailsService(userDetailsService).passwordEncoder(passwordEncoder());
}
@Bean
@Override
public AuthenticationManager authenticationManagerBean() throws Exception {
return super.authenticationManagerBean();
}
@Bean
public PasswordEncoder passwordEncoder() {
PasswordEncoder encoder = new BCryptPasswordEncoder();
return encoder;
}
}
如您所见,我在 HTTP 配置中有 .and().addFilterAfter(Account Filter, UsernamePasswordAuthenticationFilter.class);。
如何定义我的过滤器,以便它可以重定向到我的某些控制器的 URL?
我在 Java Web 应用程序“Spring Boot”中使用 Java 配置,而不是文件 xml!
【问题讨论】:
标签: spring servlets redirect filter spring-boot