mirror of
http://git.pig4cloud.com/pig/pigx.git
synced 2026-11-12 21:49:01 +08:00
✨ Introducing new features. 支持前后端 sso 的退出,回调
This commit is contained in:
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/**",
|
||||
|
||||
+6
-2
@@ -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());
|
||||
|
||||
+5
-1
@@ -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);
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user