增强授权中心UAA可配置功能
This commit is contained in:
+12
@@ -35,4 +35,16 @@ public class AuthProperties {
|
|||||||
* 2. 登出信息通知所有单点登录系统
|
* 2. 登出信息通知所有单点登录系统
|
||||||
*/
|
*/
|
||||||
private Boolean unifiedLogout = false;
|
private Boolean unifiedLogout = false;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 是否同应用同账号登录互踢
|
||||||
|
*/
|
||||||
|
private Boolean isSingleLogin = false;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 是否同应用同账号登录时共用token
|
||||||
|
* true: 多个用户使用同一账号登录时共用一个token
|
||||||
|
* false: 就算使用同一账号登录时都会新建一个token
|
||||||
|
*/
|
||||||
|
private Boolean isShareToken = false;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,8 +7,8 @@ import com.central.oauth.service.IValidateCodeService;
|
|||||||
import com.central.oauth.service.impl.CustomTokenServices;
|
import com.central.oauth.service.impl.CustomTokenServices;
|
||||||
import com.central.oauth.service.impl.UserDetailServiceFactory;
|
import com.central.oauth.service.impl.UserDetailServiceFactory;
|
||||||
import com.central.oauth.service.impl.UserDetailsByNameServiceFactoryWrapper;
|
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.Autowired;
|
||||||
import org.springframework.beans.factory.annotation.Value;
|
|
||||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
|
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
|
||||||
import org.springframework.context.annotation.Bean;
|
import org.springframework.context.annotation.Bean;
|
||||||
import org.springframework.context.annotation.Configuration;
|
import org.springframework.context.annotation.Configuration;
|
||||||
@@ -71,11 +71,8 @@ public class TokenGranterConfig {
|
|||||||
|
|
||||||
private TokenGranter tokenGranter;
|
private TokenGranter tokenGranter;
|
||||||
|
|
||||||
/**
|
@Resource
|
||||||
* 是否登录同应用同账号互踢
|
private SecurityProperties securityProperties;
|
||||||
*/
|
|
||||||
@Value("${zlt.uaa.isSingleLogin:false}")
|
|
||||||
private boolean isSingleLogin;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 授权模式
|
* 授权模式
|
||||||
@@ -161,7 +158,7 @@ public class TokenGranterConfig {
|
|||||||
@Bean
|
@Bean
|
||||||
@ConditionalOnMissingBean
|
@ConditionalOnMissingBean
|
||||||
protected DefaultTokenServices createDefaultTokenServices() {
|
protected DefaultTokenServices createDefaultTokenServices() {
|
||||||
DefaultTokenServices tokenServices = new CustomTokenServices(isSingleLogin);
|
DefaultTokenServices tokenServices = new CustomTokenServices(securityProperties.getAuth());
|
||||||
tokenServices.setTokenStore(tokenStore);
|
tokenServices.setTokenStore(tokenStore);
|
||||||
tokenServices.setSupportRefreshToken(true);
|
tokenServices.setSupportRefreshToken(true);
|
||||||
tokenServices.setReuseRefreshToken(reuseRefreshToken);
|
tokenServices.setReuseRefreshToken(reuseRefreshToken);
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
package com.central.oauth.service.impl;
|
package com.central.oauth.service.impl;
|
||||||
|
|
||||||
import com.central.common.constant.SecurityConstants;
|
import com.central.common.constant.SecurityConstants;
|
||||||
|
import com.central.oauth2.common.properties.AuthProperties;
|
||||||
import org.springframework.security.authentication.AbstractAuthenticationToken;
|
import org.springframework.security.authentication.AbstractAuthenticationToken;
|
||||||
import org.springframework.security.authentication.AuthenticationManager;
|
import org.springframework.security.authentication.AuthenticationManager;
|
||||||
import org.springframework.security.core.Authentication;
|
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) {
|
public CustomTokenServices(AuthProperties auth) {
|
||||||
this.isSingleLogin = isSingleLogin;
|
this.authProperties = auth;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -53,7 +54,7 @@ public class CustomTokenServices extends DefaultTokenServices {
|
|||||||
OAuth2AccessToken existingAccessToken = tokenStore.getAccessToken(authentication);
|
OAuth2AccessToken existingAccessToken = tokenStore.getAccessToken(authentication);
|
||||||
OAuth2RefreshToken refreshToken = null;
|
OAuth2RefreshToken refreshToken = null;
|
||||||
if (existingAccessToken != null) {
|
if (existingAccessToken != null) {
|
||||||
if (isSingleLogin) {
|
if (authProperties.getIsSingleLogin()) {
|
||||||
if (existingAccessToken.getRefreshToken() != null) {
|
if (existingAccessToken.getRefreshToken() != null) {
|
||||||
tokenStore.removeRefreshToken(existingAccessToken.getRefreshToken());
|
tokenStore.removeRefreshToken(existingAccessToken.getRefreshToken());
|
||||||
}
|
}
|
||||||
@@ -67,8 +68,7 @@ public class CustomTokenServices extends DefaultTokenServices {
|
|||||||
tokenStore.removeRefreshToken(refreshToken);
|
tokenStore.removeRefreshToken(refreshToken);
|
||||||
}
|
}
|
||||||
tokenStore.removeAccessToken(existingAccessToken);
|
tokenStore.removeAccessToken(existingAccessToken);
|
||||||
}
|
} else if (authProperties.getIsShareToken()) {
|
||||||
else {
|
|
||||||
// oidc每次授权都刷新id_token
|
// oidc每次授权都刷新id_token
|
||||||
existingAccessToken = refreshIdToken(existingAccessToken, authentication);
|
existingAccessToken = refreshIdToken(existingAccessToken, authentication);
|
||||||
// Re-store the access token in case the authentication has changed
|
// Re-store the access token in case the authentication has changed
|
||||||
|
|||||||
@@ -29,12 +29,12 @@ zlt:
|
|||||||
# 忽略验证码的应用编号
|
# 忽略验证码的应用编号
|
||||||
ignoreClientCode: app
|
ignoreClientCode: app
|
||||||
auth:
|
auth:
|
||||||
|
# 开启统一登出
|
||||||
unifiedLogout: true
|
unifiedLogout: true
|
||||||
|
# 同账号登录互踢
|
||||||
|
isSingleLogin: true
|
||||||
#多租户配置
|
#多租户配置
|
||||||
tenant:
|
tenant:
|
||||||
enable: true
|
enable: true
|
||||||
ignoreTables:
|
ignoreTables:
|
||||||
- oauth_client_details
|
- oauth_client_details
|
||||||
#是否登录同应用同账号互踢
|
|
||||||
uaa:
|
|
||||||
isSingleLogin: false
|
|
||||||
Reference in New Issue
Block a user