From b8835cddc4e449ab5d9eb10a4ee211a108ad87a2 Mon Sep 17 00:00:00 2001 From: lbw Date: Tue, 19 Apr 2022 18:34:34 +0800 Subject: [PATCH] =?UTF-8?q?:bug:=20Fixing=20a=20bug.=20close=20#I53HRW=20?= =?UTF-8?q?=E7=99=BB=E5=BD=95=E7=94=A8=E6=88=B7=E5=A4=9A=E8=A1=A8=E5=AD=98?= =?UTF-8?q?=E5=82=A8=E7=9A=84=E4=B8=8B=E5=8F=91=E7=9A=84token=E6=98=AF?= =?UTF-8?q?=E4=B8=8D=E8=83=BD=E5=88=B7=E6=96=B0=E7=9A=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../AuthorizationServerConfiguration.java | 13 ---------- .../service/PigxCustomTokenServices.java | 25 ------------------- 2 files changed, 38 deletions(-) diff --git a/pigx-auth/src/main/java/com/pig4cloud/pigx/auth/config/AuthorizationServerConfiguration.java b/pigx-auth/src/main/java/com/pig4cloud/pigx/auth/config/AuthorizationServerConfiguration.java index e675d14fd..daec7b1c6 100644 --- a/pigx-auth/src/main/java/com/pig4cloud/pigx/auth/config/AuthorizationServerConfiguration.java +++ b/pigx-auth/src/main/java/com/pig4cloud/pigx/auth/config/AuthorizationServerConfiguration.java @@ -30,8 +30,6 @@ import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.http.HttpMethod; import org.springframework.security.authentication.AuthenticationManager; -import org.springframework.security.authentication.ProviderManager; -import org.springframework.security.core.userdetails.UserDetailsByNameServiceWrapper; import org.springframework.security.core.userdetails.UserDetailsService; import org.springframework.security.oauth2.config.annotation.configurers.ClientDetailsServiceConfigurer; import org.springframework.security.oauth2.config.annotation.web.configuration.AuthorizationServerConfigurerAdapter; @@ -44,11 +42,9 @@ import org.springframework.security.oauth2.provider.TokenGranter; import org.springframework.security.oauth2.provider.code.AuthorizationCodeServices; import org.springframework.security.oauth2.provider.token.TokenEnhancer; import org.springframework.security.oauth2.provider.token.TokenStore; -import org.springframework.security.web.authentication.preauth.PreAuthenticatedAuthenticationProvider; import java.util.ArrayList; import java.util.Arrays; -import java.util.Collections; /** * @author lengleng @@ -124,16 +120,7 @@ public class AuthorizationServerConfiguration extends AuthorizationServerConfigu tokenServices.setReuseRefreshToken(false); tokenServices.setClientDetailsService(pigxClientDetailsServiceImpl); tokenServices.setTokenEnhancer(tokenEnhancer); - addUserDetailsService(tokenServices, pigxUserDetailsService); return tokenServices; } - private void addUserDetailsService(PigxCustomTokenServices tokenServices, UserDetailsService userDetailsService) { - if (userDetailsService != null) { - PreAuthenticatedAuthenticationProvider provider = new PreAuthenticatedAuthenticationProvider(); - provider.setPreAuthenticatedUserDetailsService(new UserDetailsByNameServiceWrapper<>(userDetailsService)); - tokenServices.setAuthenticationManager(new ProviderManager(Collections.singletonList(provider))); - } - } - } diff --git a/pigx-common/pigx-common-security/src/main/java/com/pig4cloud/pigx/common/security/service/PigxCustomTokenServices.java b/pigx-common/pigx-common-security/src/main/java/com/pig4cloud/pigx/common/security/service/PigxCustomTokenServices.java index 34134c4aa..56a243f85 100644 --- a/pigx-common/pigx-common-security/src/main/java/com/pig4cloud/pigx/common/security/service/PigxCustomTokenServices.java +++ b/pigx-common/pigx-common-security/src/main/java/com/pig4cloud/pigx/common/security/service/PigxCustomTokenServices.java @@ -4,8 +4,6 @@ import cn.hutool.core.map.MapUtil; import com.pig4cloud.pigx.common.core.constant.CommonConstants; import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.InitializingBean; -import org.springframework.security.authentication.AuthenticationManager; -import org.springframework.security.core.Authentication; import org.springframework.security.core.AuthenticationException; import org.springframework.security.oauth2.common.*; import org.springframework.security.oauth2.common.exceptions.InvalidGrantException; @@ -13,7 +11,6 @@ import org.springframework.security.oauth2.common.exceptions.InvalidScopeExcepti import org.springframework.security.oauth2.common.exceptions.InvalidTokenException; import org.springframework.security.oauth2.provider.*; import org.springframework.security.oauth2.provider.token.*; -import org.springframework.security.web.authentication.preauth.PreAuthenticatedAuthenticationToken; import org.springframework.transaction.annotation.Transactional; import org.springframework.util.Assert; @@ -45,8 +42,6 @@ public class PigxCustomTokenServices implements AuthorizationServerTokenServices private TokenEnhancer accessTokenEnhancer; - private AuthenticationManager authenticationManager; - /** * Initialize these token services. If no random generator is set, one will be * created. @@ -121,17 +116,6 @@ public class PigxCustomTokenServices implements AuthorizationServerTokenServices } OAuth2Authentication authentication = tokenStore.readAuthenticationForRefreshToken(refreshToken); - if (this.authenticationManager != null && !authentication.isClientOnly()) { - // The client has already been authenticated, but the user authentication - // might be old now, so give it a - // chance to re-authenticate. - Authentication user = new PreAuthenticatedAuthenticationToken(authentication.getUserAuthentication(), "", - authentication.getAuthorities()); - user = authenticationManager.authenticate(user); - Object details = authentication.getDetails(); - authentication = new OAuth2Authentication(authentication.getOAuth2Request(), user); - authentication.setDetails(details); - } String clientId = authentication.getOAuth2Request().getClientId(); if (clientId == null || !clientId.equals(tokenRequest.getClientId())) { throw new InvalidGrantException("Wrong client for this refresh token: " + refreshTokenValue); @@ -394,15 +378,6 @@ public class PigxCustomTokenServices implements AuthorizationServerTokenServices this.tokenStore = tokenStore; } - /** - * An authentication manager that will be used (if provided) to check the user - * authentication when a token is refreshed. - * @param authenticationManager the authenticationManager to set - */ - public void setAuthenticationManager(AuthenticationManager authenticationManager) { - this.authenticationManager = authenticationManager; - } - /** * The client details service to use for looking up clients (if necessary). Optional * if the access token expiry is set globally via