diff --git a/youlai-auth/src/main/java/com/youlai/auth/config/AuthorizationServerConfig.java b/youlai-auth/src/main/java/com/youlai/auth/config/AuthorizationServerConfig.java index 008c9b9aa..30894773b 100644 --- a/youlai-auth/src/main/java/com/youlai/auth/config/AuthorizationServerConfig.java +++ b/youlai-auth/src/main/java/com/youlai/auth/config/AuthorizationServerConfig.java @@ -11,6 +11,9 @@ import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.core.io.ClassPathResource; import org.springframework.security.authentication.AuthenticationManager; +import org.springframework.security.authentication.AuthenticationProvider; +import org.springframework.security.authentication.dao.DaoAuthenticationProvider; +import org.springframework.security.core.userdetails.UserDetailsService; import org.springframework.security.oauth2.common.DefaultOAuth2AccessToken; import org.springframework.security.oauth2.config.annotation.configurers.ClientDetailsServiceConfigurer; import org.springframework.security.oauth2.config.annotation.web.configuration.AuthorizationServerConfigurerAdapter; @@ -121,4 +124,12 @@ public class AuthorizationServerConfig extends AuthorizationServerConfigurerAdap return accessToken; }; } + + @Bean + public AuthenticationProvider daoAuthenticationProvider(){ + DaoAuthenticationProvider impl = new DaoAuthenticationProvider(); + impl.setUserDetailsService(userDetailsService); + impl.setHideUserNotFoundExceptions(false) ; + return impl ; + } } diff --git a/youlai-auth/src/main/java/com/youlai/auth/exception/CustomOAuth2ExceptionSerializer.java b/youlai-auth/src/main/java/com/youlai/auth/exception/CustomOAuth2ExceptionSerializer.java index 32462b8b7..8cc2d9fa0 100644 --- a/youlai-auth/src/main/java/com/youlai/auth/exception/CustomOAuth2ExceptionSerializer.java +++ b/youlai-auth/src/main/java/com/youlai/auth/exception/CustomOAuth2ExceptionSerializer.java @@ -3,6 +3,7 @@ package com.youlai.auth.exception; import com.fasterxml.jackson.core.JsonGenerator; import com.fasterxml.jackson.databind.SerializerProvider; import com.fasterxml.jackson.databind.ser.std.StdSerializer; + import java.io.IOException; public class CustomOAuth2ExceptionSerializer extends StdSerializer { @@ -14,14 +15,8 @@ public class CustomOAuth2ExceptionSerializer extends StdSerializer userResult = adminUserFeignClient.loadUserByUsername(username); - if (userResult == null || !ResultCode.SUCCESS.getCode().equals(userResult.getCode())) { + if (userResult == null || !ResultCode.SUCCESS.getCode().equals(userResult.getCode()) + || userResult.getData() == null + ) { throw new UsernameNotFoundException("用户不存在"); } UserDTO userDTO = userResult.getData(); @@ -48,7 +50,8 @@ public class UserDetailsServiceImpl implements UserDetailsService { break; case AuthConstants.WEAPP_CLIENT_ID: // 小程序会员 Result memberResult = umsMemberFeignClient.loadMemberByOpenid(username); - if (memberResult == null || !ResultCode.SUCCESS.getCode().equals(memberResult.getCode())) { + if (memberResult == null || !ResultCode.SUCCESS.getCode().equals(memberResult.getCode()) + ||memberResult.getData()==null) { throw new UsernameNotFoundException("会员不存在"); } MemberDTO memberDTO = memberResult.getData();