Просмотр исходного кода

用户模块:获取用户信息接口 用户状态修改接口

tangxiangan 2 лет назад
Родитель
Сommit
089b079c3e

+ 0 - 4
pdf-office-sso/pom.xml

@@ -104,10 +104,6 @@
                 </exclusion>
             </exclusions>
         </dependency>
-        <dependency>
-            <groupId>org.springframework.security.oauth.boot</groupId>
-            <artifactId>spring-security-oauth2-autoconfigure</artifactId>
-        </dependency>
         <!-- end -->
 
         <dependency>

+ 1 - 1
pdf-office-sso/src/main/java/cn/kdan/cloud/pdf/office/sso/service/impl/AuthServiceImpl.java

@@ -311,7 +311,7 @@ public class AuthServiceImpl implements AuthService {
             throw new BackendRuntimeException(AuthConstant.EXCEPTION_MSG_EMAIL_NOT_REGISTER);
         }
         //注销中的用户无法登陆
-        if(userVO.getValidFlag().equals(PDFOfficeUserStatusEnum.LOGGED_OUT_ING.value())){
+        if(userVO.getValidFlag().equals(PDFOfficeUserStatusEnum.LOGGED_OUT_ING.value().toString())){
             throw new BackendRuntimeException(AuthConstant.EXCEPTION_MSG_EMAIL_LOGOUT_ING);
         }
     }

+ 0 - 1
pdf-office-system/pom.xml

@@ -85,7 +85,6 @@
             <version>0.0.1</version>
             <scope>compile</scope>
         </dependency>
-        <!-- spring security start -->
         <dependency>
             <groupId>org.springframework.boot</groupId>
             <artifactId>spring-boot-starter-security</artifactId>

+ 18 - 1
pdf-office-system/src/main/java/cn/kdan/cloud/pdf/office/system/config/ResourceServerConfig.java

@@ -1,11 +1,15 @@
 package cn.kdan.cloud.pdf.office.system.config;
 
+import org.springframework.context.annotation.Bean;
 import org.springframework.context.annotation.Configuration;
 import org.springframework.core.annotation.Order;
 import org.springframework.security.config.annotation.web.builders.HttpSecurity;
 import org.springframework.security.config.http.SessionCreationPolicy;
 import org.springframework.security.oauth2.config.annotation.web.configuration.EnableResourceServer;
 import org.springframework.security.oauth2.config.annotation.web.configuration.ResourceServerConfigurerAdapter;
+import org.springframework.security.oauth2.provider.token.RemoteTokenServices;
+import org.springframework.security.oauth2.provider.token.ResourceServerTokenServices;
+import org.springframework.web.client.RestTemplate;
 
 
 /**
@@ -13,7 +17,7 @@ import org.springframework.security.oauth2.config.annotation.web.configuration.R
  */
 @Configuration
 @EnableResourceServer //开启资源提供服务的配置  是默认情况下spring security oauth2的http配置会被WebSecurityConfigurerAdapter的配置覆盖
-@Order(3)
+
 public class ResourceServerConfig extends ResourceServerConfigurerAdapter {
 
     @Override
@@ -22,4 +26,17 @@ public class ResourceServerConfig extends ResourceServerConfigurerAdapter {
         http.authorizeRequests().anyRequest().authenticated();
     }
 
+    @Bean
+    public ResourceServerTokenServices tokenService() {
+        // 是用于向远程认证服务器验证token,同时获取token对应的用户的信息
+        RemoteTokenServices remoteTokenServices = new RemoteTokenServices();
+        // 自定义token转换器
+        remoteTokenServices.setCheckTokenEndpointUrl("http://localhost:9081/oauth/check_token");
+        remoteTokenServices.setClientId("pdf-office-sso");
+        remoteTokenServices.setClientSecret("kdan@2022");
+        remoteTokenServices.setRestTemplate(new RestTemplate());
+        return remoteTokenServices;
+        //使用远程服务请求授权服务器校验token,必须指定校验token 的url、client_id,client_secret
+    }
+
 }

+ 1 - 0
pdf-office-system/src/main/java/cn/kdan/cloud/pdf/office/system/config/WebSecurityConfig.java

@@ -11,6 +11,7 @@ import org.springframework.security.config.annotation.web.builders.WebSecurity;
 import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
 import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;
 
+
 /**
  * 是默认情况下spring security的http配置 优于ResourceServerConfigurerAdapter的配置
  */