|
@@ -13,8 +13,7 @@ import org.springframework.security.config.annotation.web.configuration.WebSecur
|
|
|
import org.springframework.security.core.userdetails.UserDetailsService;
|
|
|
import org.springframework.security.crypto.password.PasswordEncoder;
|
|
|
import org.springframework.security.web.access.intercept.FilterSecurityInterceptor;
|
|
|
-import org.springframework.security.web.authentication.AuthenticationFailureHandler;
|
|
|
-import org.springframework.security.web.authentication.AuthenticationSuccessHandler;
|
|
|
+import org.springframework.security.web.authentication.UsernamePasswordAuthenticationFilter;
|
|
|
|
|
|
import javax.annotation.Resource;
|
|
|
|
|
@@ -59,6 +58,10 @@ public class WebSecurityConfig extends WebSecurityConfigurerAdapter {
|
|
|
@Autowired
|
|
|
CustomizeFilterInvocationSecurityMetadataSource securityMetadataSource;
|
|
|
|
|
|
+ //图片验证码过滤器
|
|
|
+ @Autowired
|
|
|
+ private ValidateImageCodeFilter validateImageCodeFilter;
|
|
|
+
|
|
|
@Autowired
|
|
|
private CustomizeAbstractSecurityInterceptor securityInterceptor;
|
|
|
|
|
@@ -76,7 +79,9 @@ public class WebSecurityConfig extends WebSecurityConfigurerAdapter {
|
|
|
@Override
|
|
|
protected void configure(HttpSecurity http) throws Exception {
|
|
|
http.cors().and().csrf().disable();
|
|
|
- http.authorizeRequests().antMatchers("/login").permitAll().anyRequest().authenticated().
|
|
|
+ //注册自定义图片验证码过滤器
|
|
|
+ http.addFilterBefore(validateImageCodeFilter, UsernamePasswordAuthenticationFilter.class);
|
|
|
+ http.authorizeRequests().antMatchers("/login","/image/getImage").permitAll().anyRequest().authenticated().
|
|
|
// antMatchers("/login").anonymous().
|
|
|
// antMatchers("/**").fullyAuthenticated().
|
|
|
withObjectPostProcessor(new ObjectPostProcessor<FilterSecurityInterceptor>() {
|
|
@@ -88,23 +93,24 @@ public class WebSecurityConfig extends WebSecurityConfigurerAdapter {
|
|
|
}
|
|
|
}).
|
|
|
//登出
|
|
|
- and().logout().logoutSuccessUrl("/logout").
|
|
|
+ and().logout().logoutSuccessUrl("/logout")
|
|
|
// permitAll().//允许所有用户
|
|
|
- logoutSuccessHandler(logoutSuccessHandler).//登出成功处理逻辑
|
|
|
- deleteCookies("JSESSIONID").//登出之后删除cookie
|
|
|
+ .logoutSuccessHandler(logoutSuccessHandler)//登出成功处理逻辑
|
|
|
+ .deleteCookies("JSESSIONID")//登出之后删除cookie
|
|
|
//登入
|
|
|
- and().formLogin().loginProcessingUrl("/login").
|
|
|
+ .and().formLogin().loginProcessingUrl("/login")
|
|
|
// permitAll().//允许所有用户
|
|
|
- successHandler(authenticationSuccessHandler).//登录成功处理逻辑
|
|
|
- failureHandler(authenticationFailureHandler).//登录失败处理逻辑
|
|
|
+ .successHandler(authenticationSuccessHandler)//登录成功处理逻辑
|
|
|
+ .failureHandler(authenticationFailureHandler)//登录失败处理逻辑
|
|
|
//异常处理(权限拒绝、登录失效等)
|
|
|
- and().exceptionHandling().accessDeniedHandler(accessDeniedHandler).//权限拒绝处理逻辑
|
|
|
- authenticationEntryPoint(authenticationEntryPoint).//匿名用户访问无权限资源时的异常处理
|
|
|
+ .and().exceptionHandling().accessDeniedHandler(accessDeniedHandler)//权限拒绝处理逻辑
|
|
|
+ .authenticationEntryPoint(authenticationEntryPoint)//匿名用户访问无权限资源时的异常处理
|
|
|
//会话管理
|
|
|
- and().sessionManagement().
|
|
|
- maximumSessions(1).//同一账号同时登录最大用户数
|
|
|
- expiredSessionStrategy(sessionInformationExpiredStrategy);//会话失效(账号被挤下线)处理逻辑
|
|
|
- http.addFilterBefore(securityInterceptor, FilterSecurityInterceptor.class);
|
|
|
+ .and().sessionManagement()
|
|
|
+ .maximumSessions(1)//同一账号同时登录最大用户数
|
|
|
+ .expiredSessionStrategy(sessionInformationExpiredStrategy)//会话失效(账号被挤下线)处理逻辑
|
|
|
+ ;
|
|
|
+// http.addFilterBefore(securityInterceptor, FilterSecurityInterceptor.class);
|
|
|
}
|
|
|
|
|
|
/**
|