✨ 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);
|
||||
}
|
||||
|
||||
+2
-2
@@ -210,7 +210,7 @@ public class WebUtils extends org.springframework.web.util.WebUtils {
|
||||
* @return
|
||||
*/
|
||||
@SneakyThrows
|
||||
public String[] getClientId(String header) {
|
||||
public String getClientId(String header) {
|
||||
|
||||
if (header == null || !header.startsWith(BASIC_)) {
|
||||
throw new CheckedException("请求头中client信息为空");
|
||||
@@ -231,7 +231,7 @@ public class WebUtils extends org.springframework.web.util.WebUtils {
|
||||
if (delim == -1) {
|
||||
throw new CheckedException("Invalid basic authentication token");
|
||||
}
|
||||
return new String[]{token.substring(0, delim), token.substring(delim + 1)};
|
||||
return token.substring(0, delim);
|
||||
}
|
||||
|
||||
}
|
||||
+2
-2
@@ -76,8 +76,8 @@ public class ValidateCodeGatewayFilter extends AbstractGatewayFilterFactory {
|
||||
// 终端设置不校验, 直接向下执行
|
||||
try {
|
||||
String header = request.getHeaders().getFirst(HttpHeaders.AUTHORIZATION);
|
||||
String[] clientInfos = WebUtils.getClientId(header);
|
||||
if (filterIgnorePropertiesConfig.getClients().contains(clientInfos[0])) {
|
||||
String clientId = WebUtils.getClientId(header);
|
||||
if (filterIgnorePropertiesConfig.getClients().contains(clientId)) {
|
||||
return chain.filter(exchange);
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user