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