|
@@ -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
|
|
|
+ }
|
|
|
+
|
|
|
}
|