增强授权中心UAA可配置功能

This commit is contained in:
zlt2000
2022-01-29 15:38:03 +08:00
parent 3f06a2a684
commit 02a2c0cd6b
4 changed files with 26 additions and 17 deletions
@@ -7,8 +7,8 @@ import com.central.oauth.service.IValidateCodeService;
import com.central.oauth.service.impl.CustomTokenServices;
import com.central.oauth.service.impl.UserDetailServiceFactory;
import com.central.oauth.service.impl.UserDetailsByNameServiceFactoryWrapper;
import com.central.oauth2.common.properties.SecurityProperties;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
@@ -71,11 +71,8 @@ public class TokenGranterConfig {
private TokenGranter tokenGranter;
/**
* 是否登录同应用同账号互踢
*/
@Value("${zlt.uaa.isSingleLogin:false}")
private boolean isSingleLogin;
@Resource
private SecurityProperties securityProperties;
/**
* 授权模式
@@ -161,7 +158,7 @@ public class TokenGranterConfig {
@Bean
@ConditionalOnMissingBean
protected DefaultTokenServices createDefaultTokenServices() {
DefaultTokenServices tokenServices = new CustomTokenServices(isSingleLogin);
DefaultTokenServices tokenServices = new CustomTokenServices(securityProperties.getAuth());
tokenServices.setTokenStore(tokenStore);
tokenServices.setSupportRefreshToken(true);
tokenServices.setReuseRefreshToken(reuseRefreshToken);
@@ -1,6 +1,7 @@
package com.central.oauth.service.impl;
import com.central.common.constant.SecurityConstants;
import com.central.oauth2.common.properties.AuthProperties;
import org.springframework.security.authentication.AbstractAuthenticationToken;
import org.springframework.security.authentication.AuthenticationManager;
import org.springframework.security.core.Authentication;
@@ -41,10 +42,10 @@ public class CustomTokenServices extends DefaultTokenServices {
/**
* 是否登录同应用同账号互踢
*/
private boolean isSingleLogin;
private final AuthProperties authProperties;
public CustomTokenServices(boolean isSingleLogin) {
this.isSingleLogin = isSingleLogin;
public CustomTokenServices(AuthProperties auth) {
this.authProperties = auth;
}
@Override
@@ -53,7 +54,7 @@ public class CustomTokenServices extends DefaultTokenServices {
OAuth2AccessToken existingAccessToken = tokenStore.getAccessToken(authentication);
OAuth2RefreshToken refreshToken = null;
if (existingAccessToken != null) {
if (isSingleLogin) {
if (authProperties.getIsSingleLogin()) {
if (existingAccessToken.getRefreshToken() != null) {
tokenStore.removeRefreshToken(existingAccessToken.getRefreshToken());
}
@@ -67,8 +68,7 @@ public class CustomTokenServices extends DefaultTokenServices {
tokenStore.removeRefreshToken(refreshToken);
}
tokenStore.removeAccessToken(existingAccessToken);
}
else {
} else if (authProperties.getIsShareToken()) {
// oidc每次授权都刷新id_token
existingAccessToken = refreshIdToken(existingAccessToken, authentication);
// Re-store the access token in case the authentication has changed