zhouhao il y a 6 ans
Parent
commit
a7de98d2bd

+ 5 - 5
hsweb-system/hsweb-system-oauth2-server/hsweb-system-oauth2-server-local/pom.xml

@@ -19,11 +19,11 @@
             <artifactId>hsweb-commons-service-simple</artifactId>
             <artifactId>hsweb-commons-service-simple</artifactId>
             <version>${project.version}</version>
             <version>${project.version}</version>
         </dependency>
         </dependency>
-        <dependency>
-            <groupId>org.hswebframework.web</groupId>
-            <artifactId>hsweb-system-authorization-api</artifactId>
-            <version>${project.version}</version>
-        </dependency>
+        <!--<dependency>-->
+            <!--<groupId>org.hswebframework.web</groupId>-->
+            <!--<artifactId>hsweb-system-authorization-api</artifactId>-->
+            <!--<version>${project.version}</version>-->
+        <!--</dependency>-->
         <dependency>
         <dependency>
             <groupId>org.springframework.boot</groupId>
             <groupId>org.springframework.boot</groupId>
             <artifactId>spring-boot-starter</artifactId>
             <artifactId>spring-boot-starter</artifactId>

+ 14 - 11
hsweb-system/hsweb-system-oauth2-server/hsweb-system-oauth2-server-local/src/main/java/org/hswebframework/web/service/oauth2/server/simple/SimplePasswordService.java

@@ -18,29 +18,32 @@
 
 
 package org.hswebframework.web.service.oauth2.server.simple;
 package org.hswebframework.web.service.oauth2.server.simple;
 
 
+import org.hswebframework.web.authorization.Authentication;
+import org.hswebframework.web.authorization.AuthenticationManager;
 import org.hswebframework.web.authorization.oauth2.server.support.password.PasswordService;
 import org.hswebframework.web.authorization.oauth2.server.support.password.PasswordService;
-import org.hswebframework.web.entity.authorization.UserEntity;
-import org.hswebframework.web.service.authorization.UserService;
+import org.hswebframework.web.authorization.simple.PlainTextUsernamePasswordAuthenticationRequest;
+import org.hswebframework.web.validate.ValidationException;
 
 
 /**
 /**
  * @author zhouhao
  * @author zhouhao
  */
  */
 public class SimplePasswordService implements PasswordService {
 public class SimplePasswordService implements PasswordService {
-    private UserService userService;
+    private AuthenticationManager authenticationManager;
 
 
-    public SimplePasswordService(UserService userService) {
-        this.userService = userService;
+    public SimplePasswordService(AuthenticationManager authenticationManager) {
+        this.authenticationManager = authenticationManager;
     }
     }
 
 
     @Override
     @Override
     public String getUserIdByUsernameAndPassword(String username, String password) {
     public String getUserIdByUsernameAndPassword(String username, String password) {
-        UserEntity userEntity = userService.selectByUsername(username);
-        if (userEntity == null) {
+        try {
+            Authentication authenticate = authenticationManager.authenticate(new PlainTextUsernamePasswordAuthenticationRequest(username, password));
+            if (null != authenticate) {
+                return authenticate.getUser().getId();
+            }
+        } catch (ValidationException | UnsupportedOperationException | IllegalArgumentException e) {
             return null;
             return null;
         }
         }
-        if (!userService.encodePassword(password, userEntity.getSalt()).equals(userEntity.getPassword())) {
-            return null;
-        }
-        return userEntity.getId();
+        return null;
     }
     }
 }
 }

+ 2 - 2
hsweb-system/hsweb-system-oauth2-server/hsweb-system-oauth2-server-starter/src/main/java/org/hswebframework/web/oauth2/OAuth2GranterAutoConfiguration.java

@@ -18,6 +18,7 @@
 
 
 package org.hswebframework.web.oauth2;
 package org.hswebframework.web.oauth2;
 
 
+import org.hswebframework.web.authorization.AuthenticationManager;
 import org.hswebframework.web.authorization.oauth2.server.client.OAuth2ClientConfigRepository;
 import org.hswebframework.web.authorization.oauth2.server.client.OAuth2ClientConfigRepository;
 import org.hswebframework.web.authorization.oauth2.server.support.AbstractAuthorizationService;
 import org.hswebframework.web.authorization.oauth2.server.support.AbstractAuthorizationService;
 import org.hswebframework.web.authorization.oauth2.server.support.DefaultOAuth2Granter;
 import org.hswebframework.web.authorization.oauth2.server.support.DefaultOAuth2Granter;
@@ -39,7 +40,6 @@ import org.hswebframework.web.commons.entity.factory.EntityFactory;
 import org.hswebframework.web.dao.oauth2.server.AuthorizationCodeDao;
 import org.hswebframework.web.dao.oauth2.server.AuthorizationCodeDao;
 import org.hswebframework.web.dao.oauth2.server.OAuth2AccessDao;
 import org.hswebframework.web.dao.oauth2.server.OAuth2AccessDao;
 import org.hswebframework.web.dao.oauth2.server.OAuth2ClientDao;
 import org.hswebframework.web.dao.oauth2.server.OAuth2ClientDao;
-import org.hswebframework.web.service.authorization.UserService;
 import org.hswebframework.web.service.oauth2.server.simple.*;
 import org.hswebframework.web.service.oauth2.server.simple.*;
 import org.springframework.beans.BeansException;
 import org.springframework.beans.BeansException;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.beans.factory.annotation.Autowired;
@@ -82,7 +82,7 @@ public class OAuth2GranterAutoConfiguration {
 
 
     @ConditionalOnMissingBean(PasswordService.class)
     @ConditionalOnMissingBean(PasswordService.class)
     @Bean
     @Bean
-    public SimplePasswordService simplePasswordService(UserService userService) {
+    public SimplePasswordService simplePasswordService(AuthenticationManager userService) {
         return new SimplePasswordService(userService);
         return new SimplePasswordService(userService);
     }
     }