+ * Blog: http://zlt2000.gitee.io
+ * Github: https://github.com/zlt2000
+ */
+@Slf4j
+public class CustomReactiveAuthorizationServiceIntrospector implements ReactiveOpaqueTokenIntrospector {
+ @Override
+ public Mono
+ * Blog: https://zlt2000.gitee.io
+ * Github: https://github.com/zlt2000
+ */
+public class BaseSecurityConfig {
+ @Bean
+ public OAuth2AuthorizationService oAuth2AuthorizationService(SecurityProperties securityProperties, RedissonClient redisson) {
+ return new RedisOAuth2AuthorizationService(securityProperties, redisson);
+ }
+
+ /**
+ * 鉴权错误处理
+ */
+ @Bean
+ public AuthenticationEntryPoint authenticationEntryPoint(ObjectMapper objectMapper) {
+ return (request, response, authException) -> ResponseUtil.responseFailed(objectMapper, response, authException.getMessage());
+ }
+ @Bean
+ public ServerAuthenticationEntryPoint serverAuthenticationEntryPoint() {
+ return (exchange, e) -> WebfluxResponseUtil.responseFailed(exchange, HttpStatus.UNAUTHORIZED.value(), e.getMessage());
+ }
+
+ /**
+ * 越权错误处理
+ */
+ @Bean
+ public AccessDeniedHandler oAuth2AccessDeniedHandler(ObjectMapper objectMapper) {
+ return (request, response, authException) -> ResponseUtil.responseFailed(objectMapper, response, authException.getMessage());
+ }
+ @Bean
+ public ServerAccessDeniedHandler serverAccessDeniedHandler() {
+ return (exchange, e) -> WebfluxResponseUtil.responseFailed(exchange, HttpStatus.FORBIDDEN.value(), e.getMessage());
+ }
+
+ /**
+ * 配置jwk源,使用非对称加密,公开用于检索匹配指定选择器的JWK的方法
+ */
+ @Bean
+ public JWKSource
+ * Blog: http://zlt2000.gitee.io
+ * Github: https://github.com/zlt2000
+ */
+@Data
+public class ClientDto implements Serializable {
+ @Serial
+ private static final long serialVersionUID = 1L;
+ private String clientId;
+ /**
+ * 应用名称
+ */
+ private String clientName;
+ private String resourceIds = "";
+ private String clientSecret;
+ private String clientSecretStr;
+ private String scope = "all";
+ private String authorizedGrantTypes = "authorization_code,password,refresh_token,client_credentials";
+ private String webServerRedirectUri;
+ private String authorities = "";
+
+ private Integer accessTokenValiditySeconds = 18000;
+
+ private Integer refreshTokenValiditySeconds = 28800;
+ private String additionalInformation = "{}";
+ private String autoapprove = "true";
+ /**
+ * 是否支持id_token
+ */
+ private Boolean supportIdToken = true;
+ /**
+ * id_token有效时间(s)
+ */
+ private Integer idTokenValiditySeconds = 60;
+
+ private Long creatorId;
+}
diff --git a/zlt-commons/zlt-auth-client-spring-boot-starter/src/main/java/com/central/oauth2/common/properties/PermitProperties.java b/zlt-commons/zlt-auth-client-spring-boot-starter/src/main/java/com/central/oauth2/common/properties/PermitProperties.java
index 7c5e4591..c861a309 100644
--- a/zlt-commons/zlt-auth-client-spring-boot-starter/src/main/java/com/central/oauth2/common/properties/PermitProperties.java
+++ b/zlt-commons/zlt-auth-client-spring-boot-starter/src/main/java/com/central/oauth2/common/properties/PermitProperties.java
@@ -23,15 +23,11 @@ public class PermitProperties {
* 监控中心和swagger需要访问的url
*/
private static final String[] ENDPOINTS = {
- "/oauth/**",
- "/actuator/**",
- "/*/v2/api-docs",
- "/swagger/api-docs",
- "/swagger-ui.html",
- "/doc.html",
- "/swagger-resources/**",
- "/webjars/**",
- "/druid/**"
+ "/login.html", "/validata/code/**",
+ "/v3/api-docs/**", "/*/v3/api-docs/**",
+ "/doc.html", "/swagger-ui.html", "/swagger-ui/**",
+ "/actuator/**", "/webjars/**", "/druid/**",
+ "/css/**", "/js/**", "/images/**", "/favicon.ico", "/error",
};
/**
diff --git a/zlt-commons/zlt-auth-client-spring-boot-starter/src/main/java/com/central/oauth2/common/properties/ResourceServerProperties.java b/zlt-commons/zlt-auth-client-spring-boot-starter/src/main/java/com/central/oauth2/common/properties/ResourceServerProperties.java
new file mode 100644
index 00000000..dcab6931
--- /dev/null
+++ b/zlt-commons/zlt-auth-client-spring-boot-starter/src/main/java/com/central/oauth2/common/properties/ResourceServerProperties.java
@@ -0,0 +1,22 @@
+package com.central.oauth2.common.properties;
+
+import lombok.Getter;
+import lombok.Setter;
+
+/**
+ * 资源服务器配置
+ *
+ * @author: zlt
+ * @date: 2023/11/26
+ *
+ * Blog: https://zlt2000.gitee.io
+ * Github: https://github.com/zlt2000
+ */
+@Setter
+@Getter
+public class ResourceServerProperties {
+ /**
+ * token格式: reference 引用令牌(不透明), self-contained 自包含令牌(jwt))
+ */
+ private String tokenFormat = "reference";
+}
diff --git a/zlt-commons/zlt-auth-client-spring-boot-starter/src/main/java/com/central/oauth2/common/properties/SecurityProperties.java b/zlt-commons/zlt-auth-client-spring-boot-starter/src/main/java/com/central/oauth2/common/properties/SecurityProperties.java
index c23adea3..7947eaf9 100644
--- a/zlt-commons/zlt-auth-client-spring-boot-starter/src/main/java/com/central/oauth2/common/properties/SecurityProperties.java
+++ b/zlt-commons/zlt-auth-client-spring-boot-starter/src/main/java/com/central/oauth2/common/properties/SecurityProperties.java
@@ -23,4 +23,6 @@ public class SecurityProperties {
private PermitProperties ignore = new PermitProperties();
private ValidateCodeProperties code = new ValidateCodeProperties();
+
+ private ResourceServerProperties resourceServer = new ResourceServerProperties();
}
diff --git a/zlt-commons/zlt-auth-client-spring-boot-starter/src/main/java/com/central/oauth2/common/properties/TokenStoreProperties.java b/zlt-commons/zlt-auth-client-spring-boot-starter/src/main/java/com/central/oauth2/common/properties/TokenStoreProperties.java
deleted file mode 100644
index d49a6c4c..00000000
--- a/zlt-commons/zlt-auth-client-spring-boot-starter/src/main/java/com/central/oauth2/common/properties/TokenStoreProperties.java
+++ /dev/null
@@ -1,27 +0,0 @@
-package com.central.oauth2.common.properties;
-
-import lombok.Getter;
-import lombok.Setter;
-import org.springframework.boot.context.properties.ConfigurationProperties;
-import org.springframework.cloud.context.config.annotation.RefreshScope;
-
-/**
- * Token配置
- *
- * @author zlt
- * @version 1.0
- * @date 2021/5/19
- *
- * Blog: http://zlt2000.gitee.io
- * Github: https://github.com/zlt2000
- */
-@Setter
-@Getter
-@ConfigurationProperties(prefix = "zlt.oauth2.token.store")
-@RefreshScope
-public class TokenStoreProperties {
- /**
- * token存储类型(redis/db/authJwt/resJwt)
- */
- private String type = "redis";
-}
diff --git a/zlt-commons/zlt-auth-client-spring-boot-starter/src/main/java/com/central/oauth2/common/service/impl/DefaultPermissionServiceImpl.java b/zlt-commons/zlt-auth-client-spring-boot-starter/src/main/java/com/central/oauth2/common/service/impl/DefaultPermissionServiceImpl.java
new file mode 100644
index 00000000..36435ef1
--- /dev/null
+++ b/zlt-commons/zlt-auth-client-spring-boot-starter/src/main/java/com/central/oauth2/common/service/impl/DefaultPermissionServiceImpl.java
@@ -0,0 +1,126 @@
+package com.central.oauth2.common.service.impl;
+
+import cn.hutool.core.collection.CollectionUtil;
+import cn.hutool.core.util.StrUtil;
+import com.central.common.constant.CommonConstant;
+import com.central.common.constant.SecurityConstants;
+import com.central.common.context.TenantContextHolder;
+import com.central.common.model.LoginAppUser;
+import com.central.common.model.SysMenu;
+import com.central.oauth2.common.properties.SecurityProperties;
+import com.central.oauth2.common.util.AuthUtils;
+import lombok.extern.slf4j.Slf4j;
+import org.apache.commons.lang3.StringUtils;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.http.HttpMethod;
+import org.springframework.security.authentication.AnonymousAuthenticationToken;
+import org.springframework.security.core.Authentication;
+import org.springframework.security.core.authority.SimpleGrantedAuthority;
+import org.springframework.security.oauth2.server.resource.introspection.OAuth2IntrospectionAuthenticatedPrincipal;
+import org.springframework.util.AntPathMatcher;
+
+import java.security.Principal;
+import java.util.Collection;
+import java.util.List;
+import java.util.Map;
+import java.util.stream.Collectors;
+
+/**
+ * 请求权限判断service
+ *
+ * @author zlt
+ * @date 2018/10/28
+ *
+ * Blog: https://zlt2000.gitee.io
+ * Github: https://github.com/zlt2000
+ */
+@Slf4j
+public abstract class DefaultPermissionServiceImpl {
+
+ @Autowired
+ private SecurityProperties securityProperties;
+
+ private final AntPathMatcher antPathMatcher = new AntPathMatcher();
+
+ /**
+ * 查询当前用户拥有的资源权限
+ * @param roleCodes 角色code列表,多个以','隔开
+ * @return
+ */
+ public abstract List
+ * Blog: http://zlt2000.gitee.io
+ * Github: https://github.com/zlt2000
+ */
+@Slf4j
+@RequiredArgsConstructor
+public class RedisOAuth2AuthorizationService implements OAuth2AuthorizationService {
+ private final static SerializationCodec AUTH_CODEC = new SerializationCodec();
+ private final static Long TIMEOUT = 10L;
+
+ private static final String AUTHORIZATION = "token";
+
+ private final SecurityProperties securityProperties;
+
+ private final RedissonClient redisson;
+
+ @Override
+ public void save(OAuth2Authorization authorization) {
+ if (isState(authorization)) {
+ String token = authorization.getAttribute("state");
+ this.redisBucketSet(OAuth2ParameterNames.STATE, token, authorization, Duration.ofMinutes(TIMEOUT));
+ }
+
+ if (isCode(authorization)) {
+ OAuth2AuthorizationCode authorizationCode = authorization.getToken(OAuth2AuthorizationCode.class).getToken();
+ Duration duration = this.getExpireSeconds(authorizationCode);
+ this.redisBucketSet(OAuth2ParameterNames.CODE, authorizationCode.getTokenValue(), authorization, duration);
+ }
+
+ if (isRefreshToken(authorization)) {
+ OAuth2RefreshToken refreshToken = authorization.getRefreshToken().getToken();
+ Duration duration = this.getExpireSeconds(refreshToken);
+ this.redisBucketSet(OAuth2ParameterNames.REFRESH_TOKEN, refreshToken.getTokenValue(), authorization, duration);
+ }
+
+ if (isAccessToken(authorization)) {
+ Duration duration = this.saveAccessToken(authorization);
+ OAuth2AccessToken accessToken = authorization.getAccessToken().getToken();
+ // 应用id集合
+ this.redisListAdd(this.getClientIdListKey(authorization), accessToken.getTokenValue(), duration);
+ // 应用id + 登录名 集合
+ this.redisListAdd(this.getUnameListKey(authorization), accessToken.getTokenValue(), duration);
+ }
+ }
+
+ private Duration saveAccessToken(OAuth2Authorization authorization) {
+ OAuth2AccessToken accessToken = authorization.getAccessToken().getToken();
+ Duration duration = this.getExpireSeconds(accessToken);
+ this.redisBucketSet(OAuth2ParameterNames.ACCESS_TOKEN, accessToken.getTokenValue(), authorization, duration);
+ return duration;
+ }
+
+ @Override
+ public void remove(OAuth2Authorization authorization) {
+ Assert.notNull(authorization, "authorization cannot be null");
+
+ List
- * Blog: http://zlt2000.gitee.io
- * Github: https://github.com/zlt2000
- */
-@Getter
-public class CustomWebAuthenticationDetails implements Serializable {
- private static final long serialVersionUID = - 1;
-
- private final String accountType;
- private final String remoteAddress;
- private final String sessionId;
-
- public CustomWebAuthenticationDetails(String remoteAddress, String sessionId, String accountType) {
- this.remoteAddress = remoteAddress;
- this.sessionId = sessionId;
- this.accountType = accountType;
- }
-
- @Override
- public String toString() {
- StringBuilder sb = new StringBuilder();
- sb.append(super.toString()).append("; accountType: ").append(this.getAccountType());
- return sb.toString();
- }
-}
diff --git a/zlt-commons/zlt-auth-client-spring-boot-starter/src/main/java/com/central/oauth2/common/token/MobileAuthenticationToken.java b/zlt-commons/zlt-auth-client-spring-boot-starter/src/main/java/com/central/oauth2/common/token/MobileAuthenticationToken.java
deleted file mode 100644
index 03835f4d..00000000
--- a/zlt-commons/zlt-auth-client-spring-boot-starter/src/main/java/com/central/oauth2/common/token/MobileAuthenticationToken.java
+++ /dev/null
@@ -1,84 +0,0 @@
-/**
- *
- */
-package com.central.oauth2.common.token;
-
-import org.springframework.security.authentication.AbstractAuthenticationToken;
-import org.springframework.security.core.GrantedAuthority;
-import org.springframework.security.core.SpringSecurityCoreVersion;
-
-import java.util.Collection;
-
-/**
- * @author zlt
- */
-public class MobileAuthenticationToken extends AbstractAuthenticationToken {
-
- private static final long serialVersionUID = SpringSecurityCoreVersion.SERIAL_VERSION_UID;
-
- // ~ Instance fields
- // ================================================================================================
-
- private final Object principal;
- private Object credentials;
-
- // ~ Constructors
- // ===================================================================================================
-
- /**
- * This constructor can be safely used by any code that wishes to create a
- *
+ * Blog: https://zlt2000.gitee.io
+ * Github: https://github.com/zlt2000
+ */
+@Getter
+public class PasswordAuthenticationToken extends BaseAuthenticationToken {
+ public static final AuthorizationGrantType GRANT_TYPE = new AuthorizationGrantType("password");
+ private final Object principal;
+ private final String credentials;
+
+ public PasswordAuthenticationToken(String username, String password) {
+ super(GRANT_TYPE);
+ this.principal = username;
+ this.credentials = password;
+ super.setAuthenticated(true);
+ }
+
+ public PasswordAuthenticationToken(UserDetails user, String password, Collection extends GrantedAuthority> authorities) {
+ super(authorities);
+ this.principal = user;
+ this.credentials = password;
+ }
+}
diff --git a/zlt-commons/zlt-auth-client-spring-boot-starter/src/main/java/com/central/oauth2/common/token/TenantUsernamePasswordAuthenticationToken.java b/zlt-commons/zlt-auth-client-spring-boot-starter/src/main/java/com/central/oauth2/common/token/TenantUsernamePasswordAuthenticationToken.java
deleted file mode 100644
index d1907825..00000000
--- a/zlt-commons/zlt-auth-client-spring-boot-starter/src/main/java/com/central/oauth2/common/token/TenantUsernamePasswordAuthenticationToken.java
+++ /dev/null
@@ -1,37 +0,0 @@
-package com.central.oauth2.common.token;
-
-import lombok.Getter;
-import org.springframework.security.authentication.UsernamePasswordAuthenticationToken;
-import org.springframework.security.core.GrantedAuthority;
-
-import java.util.Collection;
-
-/**
- * 增加租户id,解决不同租户单点登录时角色没变化
- *
- * @author zlt
- * @date 2020/6/10
- *
- * Blog: http://zlt2000.gitee.io
- * Github: https://github.com/zlt2000
- */
-public class TenantUsernamePasswordAuthenticationToken extends UsernamePasswordAuthenticationToken {
- private static final long serialVersionUID = -5638287853803374687L;
-
- /**
- * 租户id
- */
- @Getter
- private final String clientId;
-
- public TenantUsernamePasswordAuthenticationToken(Object principal, Object credentials, String clientId) {
- super(principal, credentials);
- this.clientId = clientId;
- }
-
- public TenantUsernamePasswordAuthenticationToken(Object principal, Object credentials,
- Collection extends GrantedAuthority> authorities, String clientId) {
- super(principal, credentials, authorities);
- this.clientId = clientId;
- }
-}
diff --git a/zlt-commons/zlt-auth-client-spring-boot-starter/src/main/java/com/central/oauth2/common/util/AuthUtils.java b/zlt-commons/zlt-auth-client-spring-boot-starter/src/main/java/com/central/oauth2/common/util/AuthUtils.java
index 4ef3d8a1..fed532c8 100644
--- a/zlt-commons/zlt-auth-client-spring-boot-starter/src/main/java/com/central/oauth2/common/util/AuthUtils.java
+++ b/zlt-commons/zlt-auth-client-spring-boot-starter/src/main/java/com/central/oauth2/common/util/AuthUtils.java
@@ -3,14 +3,12 @@ package com.central.oauth2.common.util;
import cn.hutool.extra.spring.SpringUtil;
import com.central.common.constant.CommonConstant;
import com.central.common.constant.SecurityConstants;
-import com.central.common.context.LoginUserContextHolder;
-import com.central.common.model.SysUser;
+import com.central.common.model.LoginAppUser;
+import com.central.common.utils.LoginUserUtils;
import com.central.oauth2.common.exception.CustomOAuth2AuthenticationException;
import com.central.oauth2.common.token.BaseAuthenticationToken;
import lombok.extern.slf4j.Slf4j;
-import org.springframework.security.authentication.AnonymousAuthenticationToken;
import org.springframework.security.core.Authentication;
-import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.security.oauth2.core.OAuth2AccessToken;
import org.springframework.security.oauth2.core.endpoint.OAuth2ParameterNames;
@@ -18,8 +16,10 @@ import jakarta.servlet.http.HttpServletRequest;
import org.springframework.security.oauth2.server.authorization.OAuth2Authorization;
import org.springframework.security.oauth2.server.authorization.OAuth2AuthorizationService;
import org.springframework.security.oauth2.server.authorization.OAuth2TokenType;
+import org.springframework.security.oauth2.server.resource.introspection.OAuth2IntrospectionException;
import java.nio.charset.StandardCharsets;
+import java.security.Principal;
import java.util.*;
/**
@@ -79,36 +79,33 @@ public class AuthUtils {
/**
* 校验accessToken
*/
- public static SysUser checkAccessToken(HttpServletRequest request) {
+ public static LoginAppUser checkAccessToken(HttpServletRequest request) {
String accessToken = extractToken(request);
return checkAccessToken(accessToken);
}
- public static SysUser checkAccessToken(String accessTokenValue) {
- OAuth2AuthorizationService tokenService = SpringUtil.getBean(OAuth2AuthorizationService.class);
- OAuth2Authorization oAuth2Authorization = tokenService.findByToken(accessTokenValue, OAuth2TokenType.ACCESS_TOKEN);
- if (oAuth2Authorization == null || oAuth2Authorization.getAccessToken() == null) {
- throw new CustomOAuth2AuthenticationException("Invalid access token: " + accessTokenValue);
- } else if (oAuth2Authorization.getAccessToken().isExpired()) {
- tokenService.remove(oAuth2Authorization);
- throw new CustomOAuth2AuthenticationException("Access token expired: " + accessTokenValue);
+ public static LoginAppUser checkAccessToken(String accessTokenValue) {
+ OAuth2Authorization authorization = checkAccessTokenToAuth(accessTokenValue);
+ Authentication authentication = (Authentication)authorization.getAttributes().get(Principal.class.getName());
+ if (authentication == null) {
+ throw new OAuth2IntrospectionException("Invalid access token: " + accessTokenValue);
}
- /*OAuth2Authentication result = tokenStore.readAuthentication(accessToken);
- if (result == null) {
- throw new OAuth2AuthenticationException("Invalid access token: " + accessTokenValue);
- }*/
- // TODO 如何生成 Authentication 对象
- return setContext(null);
+ return LoginUserUtils.setContext(authentication);
}
- /**
- * 用户信息赋值 context 对象
- */
- public static SysUser setContext(Authentication authentication) {
- SecurityContextHolder.getContext().setAuthentication(authentication);
- SysUser user = getUser(authentication);
- LoginUserContextHolder.setUser(user);
- return user;
+ public static OAuth2Authorization checkAccessTokenToAuth(String accessTokenValue) {
+ if (accessTokenValue == null) {
+ throw new OAuth2IntrospectionException("Invalid access token: " + null);
+ }
+ OAuth2AuthorizationService authorizationService = SpringUtil.getBean(OAuth2AuthorizationService.class);
+ OAuth2Authorization authorization = authorizationService.findByToken(accessTokenValue, OAuth2TokenType.ACCESS_TOKEN);
+ if (authorization == null || authorization.getAccessToken() == null) {
+ throw new OAuth2IntrospectionException("Invalid access token: " + accessTokenValue);
+ } else if (authorization.getAccessToken().isExpired()) {
+ authorizationService.remove(authorization);
+ throw new OAuth2IntrospectionException("Access token expired: " + accessTokenValue);
+ }
+ return authorization;
}
/**
@@ -147,35 +144,6 @@ public class AuthUtils {
return clientArr;
}
- /**
- * 获取登陆的用户名
- */
- public static String getUsername(Authentication authentication) {
- Object principal = authentication.getPrincipal();
- String username = null;
- if (principal instanceof SysUser) {
- username = ((SysUser) principal).getUsername();
- } else if (principal instanceof String) {
- username = (String) principal;
- }
- return username;
- }
-
- /**
- * 获取登陆的用户对象
- */
- public static SysUser getUser(Authentication authentication) {
- SysUser user = null;
- if (authentication != null && !(authentication instanceof AnonymousAuthenticationToken)) {
- Object principal = authentication.getPrincipal();
- //客户端模式只返回一个clientId
- if (principal instanceof SysUser) {
- user = (SysUser)principal;
- }
- }
- return user;
- }
-
/**
* 获取登陆的帐户类型
*/
diff --git a/zlt-commons/zlt-common-core/pom.xml b/zlt-commons/zlt-common-core/pom.xml
index 746451ba..f8d91b5b 100644
--- a/zlt-commons/zlt-common-core/pom.xml
+++ b/zlt-commons/zlt-common-core/pom.xml
@@ -93,5 +93,13 @@
UsernamePasswordAuthenticationToken, as the {@link #isAuthenticated()}
- * will return false.
- *
- */
- public MobileAuthenticationToken(String mobile, String password) {
- super(null);
- this.principal = mobile;
- this.credentials = password;
- setAuthenticated(false);
- }
-
- /**
- * This constructor should only be used by AuthenticationManager or
- * AuthenticationProvider implementations that are satisfied with
- * producing a trusted (i.e. {@link #isAuthenticated()} = true)
- * authentication token.
- *
- * @param principal
- * @param authorities
- */
- public MobileAuthenticationToken(Object principal, Object credentials,
- Collection extends GrantedAuthority> authorities) {
- super(authorities);
- this.principal = principal;
- this.credentials = credentials;
- super.setAuthenticated(true);
- }
-
- // ~ Methods
- // ========================================================================================================
-
- @Override
- public Object getCredentials() {
- return this.credentials;
- }
-
- @Override
- public Object getPrincipal() {
- return this.principal;
- }
-
- @Override
- public void setAuthenticated(boolean isAuthenticated) {
- if (isAuthenticated) {
- throw new IllegalArgumentException(
- "Cannot set this token to trusted - use constructor which takes a GrantedAuthority list instead");
- }
- super.setAuthenticated(false);
- }
-
- @Override
- public void eraseCredentials() {
- super.eraseCredentials();
- }
-}
diff --git a/zlt-commons/zlt-auth-client-spring-boot-starter/src/main/java/com/central/oauth2/common/token/OpenIdAuthenticationToken.java b/zlt-commons/zlt-auth-client-spring-boot-starter/src/main/java/com/central/oauth2/common/token/OpenIdAuthenticationToken.java
deleted file mode 100644
index 04395939..00000000
--- a/zlt-commons/zlt-auth-client-spring-boot-starter/src/main/java/com/central/oauth2/common/token/OpenIdAuthenticationToken.java
+++ /dev/null
@@ -1,78 +0,0 @@
-package com.central.oauth2.common.token;
-
-import org.springframework.security.authentication.AbstractAuthenticationToken;
-import org.springframework.security.core.GrantedAuthority;
-import org.springframework.security.core.SpringSecurityCoreVersion;
-
-import java.util.Collection;
-
-/**
- * @author zlt
- */
-public class OpenIdAuthenticationToken extends AbstractAuthenticationToken {
-
- private static final long serialVersionUID = SpringSecurityCoreVersion.SERIAL_VERSION_UID;
-
- // ~ Instance fields
- // ================================================================================================
-
- private final Object principal;
-
- // ~ Constructors
- // ===================================================================================================
-
- /**
- * This constructor can be safely used by any code that wishes to create a
- * UsernamePasswordAuthenticationToken, as the {@link #isAuthenticated()}
- * will return false.
- *
- */
- public OpenIdAuthenticationToken(String openId) {
- super(null);
- this.principal = openId;
- setAuthenticated(false);
- }
-
- /**
- * This constructor should only be used by AuthenticationManager or
- * AuthenticationProvider implementations that are satisfied with
- * producing a trusted (i.e. {@link #isAuthenticated()} = true)
- * authentication token.
- *
- * @param principal
- * @param authorities
- */
- public OpenIdAuthenticationToken(Object principal,
- Collection extends GrantedAuthority> authorities) {
- super(authorities);
- this.principal = principal;
- super.setAuthenticated(true);
- }
-
- // ~ Methods
- // ========================================================================================================
-
- @Override
- public Object getCredentials() {
- return null;
- }
-
- @Override
- public Object getPrincipal() {
- return this.principal;
- }
-
- @Override
- public void setAuthenticated(boolean isAuthenticated) {
- if (isAuthenticated) {
- throw new IllegalArgumentException(
- "Cannot set this token to trusted - use constructor which takes a GrantedAuthority list instead");
- }
- super.setAuthenticated(false);
- }
-
- @Override
- public void eraseCredentials() {
- super.eraseCredentials();
- }
-}
diff --git a/zlt-commons/zlt-auth-client-spring-boot-starter/src/main/java/com/central/oauth2/common/token/PasswordAuthenticationToken.java b/zlt-commons/zlt-auth-client-spring-boot-starter/src/main/java/com/central/oauth2/common/token/PasswordAuthenticationToken.java
new file mode 100644
index 00000000..31a0efed
--- /dev/null
+++ b/zlt-commons/zlt-auth-client-spring-boot-starter/src/main/java/com/central/oauth2/common/token/PasswordAuthenticationToken.java
@@ -0,0 +1,35 @@
+package com.central.oauth2.common.token;
+
+import lombok.Getter;
+import org.springframework.security.core.GrantedAuthority;
+import org.springframework.security.core.userdetails.UserDetails;
+import org.springframework.security.oauth2.core.AuthorizationGrantType;
+
+import java.util.Collection;
+
+/**
+ * @author: zlt
+ * @date: 2023/11/18
+ *