✨ Introducing new features. 支持前后端 sso 的退出,回调

This commit is contained in:
冷冷 committed 2020-04-06 11:34:20 +08:00
1 parent 1e81e0d25d
commit 3b9568bb46
5 files changed
+24 -7

No files matched your search

@@ -27,6 +27,7 @@ import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Primary;
import org.springframework.core.annotation.Order;
import org.springframework.http.HttpHeaders;
import org.springframework.security.authentication.AuthenticationManager;
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.config.annotation.web.builders.WebSecurity;
@@ -54,6 +55,14 @@ public class WebSecurityConfigurer extends WebSecurityConfigurerAdapter {
.loginProcessingUrl("/token/form")
.failureHandler(authenticationFailureHandler())
.and()
.logout()
.logoutSuccessHandler((request, response, authentication) -> {
String referer = request.getHeader(HttpHeaders.REFERER);
response.sendRedirect(referer);
})
.deleteCookies("JSESSIONID")
.invalidateHttpSession(true)
.and()
.authorizeRequests()
.antMatchers(
"/token/**",
@@ -17,6 +17,7 @@
package com.pig4cloud.pigx.auth.handler;
import cn.hutool.core.util.StrUtil;
import com.pig4cloud.pigx.admin.api.entity.SysLog;
import com.pig4cloud.pigx.admin.api.feign.RemoteLogService;
import com.pig4cloud.pigx.common.core.constant.CommonConstants;
@@ -64,9 +65,12 @@ public class PigxAuthenticationFailureEventHandler implements AuthenticationFail
sysLog.setTitle(username + "用户登录");
sysLog.setType(CommonConstants.STATUS_LOCK);
sysLog.setParams(username);
String header = request.getHeader(HttpHeaders.AUTHORIZATION);
sysLog.setServiceId(WebUtils.getClientId(header)[0]);
sysLog.setException(authenticationException.getLocalizedMessage());
String header = request.getHeader(HttpHeaders.AUTHORIZATION);
if (StrUtil.isNotBlank(header)) {
sysLog.setServiceId(WebUtils.getClientId(header));
}
logService.saveLog(sysLog, SecurityConstants.FROM_IN);
log.info("用户:{} 登录失败,异常:{}", username, authenticationException.getLocalizedMessage());
@@ -17,6 +17,7 @@
package com.pig4cloud.pigx.auth.handler;
import cn.hutool.core.util.StrUtil;
import com.pig4cloud.pigx.admin.api.entity.SysLog;
import com.pig4cloud.pigx.admin.api.feign.RemoteLogService;
import com.pig4cloud.pigx.common.core.constant.SecurityConstants;
@@ -60,7 +61,10 @@ public class PigxAuthenticationSuccessEventHandler implements AuthenticationSucc
sysLog.setTitle(username + "用户登录");
sysLog.setParams(username);
String header = request.getHeader(HttpHeaders.AUTHORIZATION);
sysLog.setServiceId(WebUtils.getClientId(header)[0]);
if (StrUtil.isNotBlank(header)) {
sysLog.setServiceId(WebUtils.getClientId(header));
}
logService.saveLog(sysLog, SecurityConstants.FROM_IN);
log.info("用户:{} 登录成功", username);
}