|
|
@@ -3,7 +3,7 @@ package com.ningdatech.pmapi.user.security.auth; |
|
|
|
import com.ningdatech.basic.util.NdJsonUtil; |
|
|
|
import com.ningdatech.basic.util.StrPool; |
|
|
|
import com.ningdatech.pmapi.common.constant.BizConst; |
|
|
|
import com.ningdatech.pmapi.user.security.auth.config.AuthProperties; |
|
|
|
import com.ningdatech.pmapi.common.constant.CommonConstant; |
|
|
|
import com.ningdatech.pmapi.user.security.auth.handler.DefaultExpiredSessionStrategy; |
|
|
|
import com.ningdatech.pmapi.user.security.auth.password.UsernamePasswordAuthSecurityConfig; |
|
|
|
import org.springframework.beans.factory.annotation.Qualifier; |
|
|
@@ -46,30 +46,30 @@ public class WebSecurityConfig extends WebSecurityConfigurerAdapter { |
|
|
|
protected void configure(HttpSecurity http) throws Exception { |
|
|
|
assemblerPreAuthUrls(http); |
|
|
|
http.formLogin() |
|
|
|
.and() |
|
|
|
.exceptionHandling() |
|
|
|
.authenticationEntryPoint(authenticationEntryPoint()) |
|
|
|
.loginPage(authProperties.getAuthRequireUrl()) |
|
|
|
.and().apply(usernamePasswordAuthSecurityConfig) |
|
|
|
.and() |
|
|
|
.authorizeRequests() |
|
|
|
.antMatchers(authProperties.getIgnoreAuthUrlsArray()).permitAll() |
|
|
|
.anyRequest() |
|
|
|
.authenticated() |
|
|
|
.and() |
|
|
|
.authorizeRequests().antMatchers(authProperties.getIgnoreAuthUrlsArray()).permitAll().anyRequest() |
|
|
|
.authenticated().and() |
|
|
|
// 防止固定会话攻击,Spring security的默认配置就是如此: |
|
|
|
// 登陆成功之后会创建一个新的会话,然后将旧的session信息复制到新的session中(客户端的sessionId变了) |
|
|
|
.sessionManagement().invalidSessionUrl(authProperties.getInvalidSessionUrl()).sessionFixation() |
|
|
|
.migrateSession() |
|
|
|
// .invalidSessionStrategy(defaultInvalidSessionStrategy) |
|
|
|
.maximumSessions(10).maxSessionsPreventsLogin(true).expiredSessionStrategy(defaultExpiredSessionStrategy) |
|
|
|
.and().and().logout().logoutUrl(authProperties.getLogoutUrl()).logoutSuccessHandler(logoutSuccessHandler) |
|
|
|
.deleteCookies(BizConst.COOKIE_KEY) |
|
|
|
.maximumSessions(10) |
|
|
|
.maxSessionsPreventsLogin(true) |
|
|
|
.expiredSessionStrategy(defaultExpiredSessionStrategy) |
|
|
|
.and().and() |
|
|
|
.logout().logoutUrl(authProperties.getLogoutUrl()).logoutSuccessHandler(logoutSuccessHandler) |
|
|
|
.deleteCookies(CommonConstant.COOKIE_KEY) |
|
|
|
// .and() |
|
|
|
// .cors().configurationSource(corsConfigurationSource()) |
|
|
|
.and() |
|
|
|
// .csrf().disable(); |
|
|
|
// 开启csrf验证,需要前端同步传入token |
|
|
|
.csrf().csrfTokenRepository(CookieCsrfTokenRepository.withHttpOnlyFalse()) |
|
|
|
.ignoringAntMatchers(authProperties.getIgnoreCsrfUrlsArray()); |
|
|
|
|
|
|
|
|
|
|
|
// http.anonymous().authenticationFilter(availableUserAuthenticationFilter); |
|
|
|
} |
|
|
|
|
|
|
|
private AuthenticationEntryPoint authenticationEntryPoint() { |
|
|
@@ -94,4 +94,5 @@ public class WebSecurityConfig extends WebSecurityConfigurerAdapter { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
} |