@@ -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;
|
||||
|
||||
/**
|
||||
* 授权模式
|
||||
@@ -153,7 +150,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
|
||||
|
||||
@@ -101,7 +101,7 @@ public class RedisClientDetailsService extends JdbcClientDetailsService {
|
||||
return;
|
||||
}
|
||||
|
||||
list.parallelStream().forEach(client -> redisTemplate.opsForValue().set(clientRedisKey(client.getClientId()), client));
|
||||
list.forEach(client -> redisTemplate.opsForValue().set(clientRedisKey(client.getClientId()), client));
|
||||
}
|
||||
|
||||
private String clientRedisKey(String clientId) {
|
||||
|
||||
@@ -39,7 +39,7 @@ public class RedisTokensServiceImpl implements ITokensService {
|
||||
public PageResult<TokenVo> listTokens(Map<String, Object> params, String clientId) {
|
||||
Integer page = MapUtils.getInteger(params, "page");
|
||||
Integer limit = MapUtils.getInteger(params, "limit");
|
||||
int[] startEnds = PageUtil.transToStartEnd(page, limit);
|
||||
int[] startEnds = PageUtil.transToStartEnd(page-1, limit);
|
||||
//根据请求参数生成redis的key
|
||||
String redisKey = getRedisKey(params, clientId);
|
||||
long size = redisRepository.length(redisKey);
|
||||
|
||||
@@ -29,12 +29,12 @@ zlt:
|
||||
# 忽略验证码的应用编号
|
||||
ignoreClientCode: app
|
||||
auth:
|
||||
# 开启统一登出
|
||||
unifiedLogout: true
|
||||
# 同账号登录互踢
|
||||
isSingleLogin: true
|
||||
#多租户配置
|
||||
tenant:
|
||||
enable: true
|
||||
ignoreTables:
|
||||
- oauth_client_details
|
||||
#是否登录同应用同账号互踢
|
||||
uaa:
|
||||
isSingleLogin: false
|
||||
- oauth_client_details
|
||||
Reference in New Issue
Block a user