├── README.md
├── server
├── src
│ ├── main
│ │ ├── resources
│ │ │ └── application.yml
│ │ └── java
│ │ │ └── com
│ │ │ └── pjb
│ │ │ └── server
│ │ │ ├── ServerApplication.java
│ │ │ ├── service
│ │ │ └── SSOUserDetailsService.java
│ │ │ └── config
│ │ │ ├── SpringSecurityConfig.java
│ │ │ └── AuthorizationServerConfig.java
│ └── test
│ │ └── java
│ │ └── com
│ │ └── pjb
│ │ └── server
│ │ └── ServerApplicationTests.java
├── .gitignore
└── pom.xml
├── client2
├── src
│ ├── main
│ │ ├── resources
│ │ │ └── application.yml
│ │ └── java
│ │ │ └── com
│ │ │ └── pjb
│ │ │ └── client2
│ │ │ ├── Client2Application.java
│ │ │ ├── controller
│ │ │ └── ClientController.java
│ │ │ └── config
│ │ │ └── ClientWebsecurityConfigurer.java
│ └── test
│ │ └── java
│ │ └── com
│ │ └── pjb
│ │ └── client2
│ │ └── Client2ApplicationTests.java
├── .gitignore
└── pom.xml
├── client1
├── src
│ ├── main
│ │ ├── java
│ │ │ └── com
│ │ │ │ └── pjb
│ │ │ │ └── client1
│ │ │ │ ├── Client1Application.java
│ │ │ │ ├── controller
│ │ │ │ └── ClientController.java
│ │ │ │ └── config
│ │ │ │ └── ClientWebsecurityConfigurer.java
│ │ └── resources
│ │ │ └── application.yml
│ └── test
│ │ └── java
│ │ └── com
│ │ └── pjb
│ │ └── client1
│ │ └── Client1ApplicationTests.java
├── .gitignore
└── pom.xml
└── .gitignore
/README.md:
--------------------------------------------------------------------------------
1 | SpringBoot-SSO
2 |
--------------------------------------------------------------------------------
/server/src/main/resources/application.yml:
--------------------------------------------------------------------------------
1 | server:
2 | servlet:
3 | context-path: /pjb
4 |
--------------------------------------------------------------------------------
/client2/src/main/resources/application.yml:
--------------------------------------------------------------------------------
1 | server:
2 | port: 8087
3 | security:
4 | oauth2:
5 | client:
6 | client-id: ben2
7 | client-secret: 123456
8 | user-authorization-uri: http://localhost:8080/pjb/oauth/authorize
9 | access-token-uri: http://localhost:8080/pjb/oauth/token
10 | resource:
11 | jwt:
12 | key-uri: http://localhost:8080/pjb/oauth/token_key
13 |
--------------------------------------------------------------------------------
/server/src/main/java/com/pjb/server/ServerApplication.java:
--------------------------------------------------------------------------------
1 | package com.pjb.server;
2 |
3 | import org.springframework.boot.SpringApplication;
4 | import org.springframework.boot.autoconfigure.SpringBootApplication;
5 |
6 | @SpringBootApplication
7 | public class ServerApplication {
8 |
9 | public static void main(String[] args) {
10 | SpringApplication.run(ServerApplication.class, args);
11 | }
12 |
13 | }
14 |
--------------------------------------------------------------------------------
/client1/src/main/java/com/pjb/client1/Client1Application.java:
--------------------------------------------------------------------------------
1 | package com.pjb.client1;
2 |
3 | import org.springframework.boot.SpringApplication;
4 | import org.springframework.boot.autoconfigure.SpringBootApplication;
5 |
6 | @SpringBootApplication
7 | public class Client1Application {
8 |
9 | public static void main(String[] args) {
10 | SpringApplication.run(Client1Application.class, args);
11 | }
12 |
13 | }
14 |
--------------------------------------------------------------------------------
/client2/src/main/java/com/pjb/client2/Client2Application.java:
--------------------------------------------------------------------------------
1 | package com.pjb.client2;
2 |
3 | import org.springframework.boot.SpringApplication;
4 | import org.springframework.boot.autoconfigure.SpringBootApplication;
5 |
6 | @SpringBootApplication
7 | public class Client2Application {
8 |
9 | public static void main(String[] args) {
10 | SpringApplication.run(Client2Application.class, args);
11 | }
12 |
13 | }
14 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | HELP.md
2 | /target/
3 | !.mvn/wrapper/maven-wrapper.jar
4 |
5 | ### STS ###
6 | .apt_generated
7 | .classpath
8 | .factorypath
9 | .project
10 | .settings
11 | .springBeans
12 | .sts4-cache
13 |
14 | ### IntelliJ IDEA ###
15 | .idea
16 | *.iws
17 | *.iml
18 | *.ipr
19 |
20 | ### NetBeans ###
21 | /nbproject/private/
22 | /nbbuild/
23 | /dist/
24 | /nbdist/
25 | /.nb-gradle/
26 | /build/
27 |
28 | ### VS Code ###
29 | .vscode/
30 |
--------------------------------------------------------------------------------
/client1/.gitignore:
--------------------------------------------------------------------------------
1 | HELP.md
2 | /target/
3 | !.mvn/wrapper/maven-wrapper.jar
4 |
5 | ### STS ###
6 | .apt_generated
7 | .classpath
8 | .factorypath
9 | .project
10 | .settings
11 | .springBeans
12 | .sts4-cache
13 |
14 | ### IntelliJ IDEA ###
15 | .idea
16 | *.iws
17 | *.iml
18 | *.ipr
19 |
20 | ### NetBeans ###
21 | /nbproject/private/
22 | /nbbuild/
23 | /dist/
24 | /nbdist/
25 | /.nb-gradle/
26 | /build/
27 |
28 | ### VS Code ###
29 | .vscode/
30 |
--------------------------------------------------------------------------------
/client1/src/main/resources/application.yml:
--------------------------------------------------------------------------------
1 | server:
2 | port: 8086
3 |
4 | security:
5 | oauth2:
6 | client:
7 | client-id: ben1
8 | client-secret: 123456
9 | user-authorization-uri: http://localhost:8080/pjb/oauth/authorize
10 | access-token-uri: http://localhost:8080/pjb/oauth/token
11 | registered-redirect-uri:
12 | resource:
13 | jwt:
14 | key-uri: http://localhost:8080/pjb/oauth/token_key
15 |
--------------------------------------------------------------------------------
/client2/.gitignore:
--------------------------------------------------------------------------------
1 | HELP.md
2 | /target/
3 | !.mvn/wrapper/maven-wrapper.jar
4 |
5 | ### STS ###
6 | .apt_generated
7 | .classpath
8 | .factorypath
9 | .project
10 | .settings
11 | .springBeans
12 | .sts4-cache
13 |
14 | ### IntelliJ IDEA ###
15 | .idea
16 | *.iws
17 | *.iml
18 | *.ipr
19 |
20 | ### NetBeans ###
21 | /nbproject/private/
22 | /nbbuild/
23 | /dist/
24 | /nbdist/
25 | /.nb-gradle/
26 | /build/
27 |
28 | ### VS Code ###
29 | .vscode/
30 |
--------------------------------------------------------------------------------
/server/.gitignore:
--------------------------------------------------------------------------------
1 | HELP.md
2 | /target/
3 | !.mvn/wrapper/maven-wrapper.jar
4 |
5 | ### STS ###
6 | .apt_generated
7 | .classpath
8 | .factorypath
9 | .project
10 | .settings
11 | .springBeans
12 | .sts4-cache
13 |
14 | ### IntelliJ IDEA ###
15 | .idea
16 | *.iws
17 | *.iml
18 | *.ipr
19 |
20 | ### NetBeans ###
21 | /nbproject/private/
22 | /nbbuild/
23 | /dist/
24 | /nbdist/
25 | /.nb-gradle/
26 | /build/
27 |
28 | ### VS Code ###
29 | .vscode/
30 |
--------------------------------------------------------------------------------
/server/src/test/java/com/pjb/server/ServerApplicationTests.java:
--------------------------------------------------------------------------------
1 | package com.pjb.server;
2 |
3 | import org.junit.Test;
4 | import org.junit.runner.RunWith;
5 | import org.springframework.boot.test.context.SpringBootTest;
6 | import org.springframework.test.context.junit4.SpringRunner;
7 |
8 | @RunWith(SpringRunner.class)
9 | @SpringBootTest
10 | public class ServerApplicationTests {
11 |
12 | @Test
13 | public void contextLoads() {
14 | }
15 |
16 | }
17 |
--------------------------------------------------------------------------------
/client1/src/test/java/com/pjb/client1/Client1ApplicationTests.java:
--------------------------------------------------------------------------------
1 | package com.pjb.client1;
2 |
3 | import org.junit.Test;
4 | import org.junit.runner.RunWith;
5 | import org.springframework.boot.test.context.SpringBootTest;
6 | import org.springframework.test.context.junit4.SpringRunner;
7 |
8 | @RunWith(SpringRunner.class)
9 | @SpringBootTest
10 | public class Client1ApplicationTests {
11 |
12 | @Test
13 | public void contextLoads() {
14 | }
15 |
16 | }
17 |
--------------------------------------------------------------------------------
/client2/src/test/java/com/pjb/client2/Client2ApplicationTests.java:
--------------------------------------------------------------------------------
1 | package com.pjb.client2;
2 |
3 | import org.junit.Test;
4 | import org.junit.runner.RunWith;
5 | import org.springframework.boot.test.context.SpringBootTest;
6 | import org.springframework.test.context.junit4.SpringRunner;
7 |
8 | @RunWith(SpringRunner.class)
9 | @SpringBootTest
10 | public class Client2ApplicationTests {
11 |
12 | @Test
13 | public void contextLoads() {
14 | }
15 |
16 | }
17 |
--------------------------------------------------------------------------------
/client1/src/main/java/com/pjb/client1/controller/ClientController.java:
--------------------------------------------------------------------------------
1 | package com.pjb.client1.controller;
2 |
3 | import org.springframework.security.access.prepost.PreAuthorize;
4 | import org.springframework.web.bind.annotation.GetMapping;
5 | import org.springframework.web.bind.annotation.RestController;
6 |
7 | /**
8 | * @author jinbin
9 | * @date 2019-05-20 20:35
10 | */
11 | @RestController
12 | public class ClientController {
13 |
14 | @GetMapping("/normal")
15 | @PreAuthorize("hasAuthority('ROLE_USER')")
16 | public String normal( ) {
17 | return "用户页面";
18 | }
19 |
20 | @GetMapping("/medium")
21 | @PreAuthorize("hasAuthority('ROLE_USER')")
22 | public String medium() {
23 | return "这也是用户页面";
24 | }
25 |
26 | @GetMapping("/admin")
27 | @PreAuthorize("hasAuthority('ROLE_ADMIN')")
28 | public String admin() {
29 | return "管理员页面";
30 | }
31 | }
32 |
--------------------------------------------------------------------------------
/client2/src/main/java/com/pjb/client2/controller/ClientController.java:
--------------------------------------------------------------------------------
1 | package com.pjb.client2.controller;
2 |
3 | import org.springframework.security.access.prepost.PreAuthorize;
4 | import org.springframework.web.bind.annotation.GetMapping;
5 | import org.springframework.web.bind.annotation.RestController;
6 |
7 | /**
8 | * @author jinbin
9 | * @date 2019-05-20 20:38
10 | */
11 |
12 | @RestController
13 | public class ClientController {
14 |
15 | @GetMapping("/normal")
16 | @PreAuthorize("hasAuthority('ROLE_USER')")
17 | public String normal( ) {
18 | return "用户页面";
19 | }
20 |
21 | @GetMapping("/medium")
22 | @PreAuthorize("hasAuthority('ROLE_USER')")
23 | public String medium() {
24 | return "这也是用户页面";
25 | }
26 |
27 | @GetMapping("/admin")
28 | @PreAuthorize("hasAuthority('ROLE_ADMIN')")
29 | public String admin() {
30 | return "管理员页面";
31 | }
32 | }
33 |
--------------------------------------------------------------------------------
/client1/src/main/java/com/pjb/client1/config/ClientWebsecurityConfigurer.java:
--------------------------------------------------------------------------------
1 | package com.pjb.client1.config;
2 |
3 | import org.springframework.boot.autoconfigure.security.oauth2.client.EnableOAuth2Sso;
4 | import org.springframework.context.annotation.Configuration;
5 | import org.springframework.security.config.annotation.method.configuration.EnableGlobalMethodSecurity;
6 | import org.springframework.security.config.annotation.web.builders.HttpSecurity;
7 | import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
8 | import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;
9 |
10 | /**
11 | * @author jinbin
12 | * @date 2019-05-20 20:34
13 | */
14 |
15 | @Configuration
16 | @EnableWebSecurity
17 | @EnableGlobalMethodSecurity(prePostEnabled = true)
18 | @EnableOAuth2Sso
19 | public class ClientWebsecurityConfigurer extends WebSecurityConfigurerAdapter {
20 |
21 | @Override
22 | public void configure(HttpSecurity http) throws Exception {
23 | http.antMatcher("/**").authorizeRequests()
24 | .anyRequest().authenticated();
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/client2/src/main/java/com/pjb/client2/config/ClientWebsecurityConfigurer.java:
--------------------------------------------------------------------------------
1 | package com.pjb.client2.config;
2 |
3 | import org.springframework.boot.autoconfigure.security.oauth2.client.EnableOAuth2Sso;
4 | import org.springframework.context.annotation.Configuration;
5 | import org.springframework.security.config.annotation.method.configuration.EnableGlobalMethodSecurity;
6 | import org.springframework.security.config.annotation.web.builders.HttpSecurity;
7 | import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
8 | import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;
9 |
10 | /**
11 | * @author jinbin
12 | * @date 2019-05-20 20:38
13 | */
14 |
15 | @Configuration
16 | @EnableWebSecurity
17 | @EnableGlobalMethodSecurity(prePostEnabled = true)
18 | @EnableOAuth2Sso
19 | public class ClientWebsecurityConfigurer extends WebSecurityConfigurerAdapter {
20 |
21 | @Override
22 | public void configure(HttpSecurity http) throws Exception {
23 | http.antMatcher("/**").authorizeRequests()
24 | .anyRequest().authenticated();
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/server/src/main/java/com/pjb/server/service/SSOUserDetailsService.java:
--------------------------------------------------------------------------------
1 | package com.pjb.server.service;
2 |
3 | import org.springframework.beans.factory.annotation.Autowired;
4 | import org.springframework.security.core.authority.AuthorityUtils;
5 | import org.springframework.security.core.userdetails.User;
6 | import org.springframework.security.core.userdetails.UserDetails;
7 | import org.springframework.security.core.userdetails.UserDetailsService;
8 | import org.springframework.security.core.userdetails.UsernameNotFoundException;
9 | import org.springframework.security.crypto.password.PasswordEncoder;
10 | import org.springframework.stereotype.Component;
11 |
12 | /**
13 | * @author jinbin
14 | * @date 2019-05-20 20:28
15 | */
16 |
17 | @Component
18 | public class SSOUserDetailsService implements UserDetailsService {
19 | @Autowired
20 | private PasswordEncoder passwordEncoder;
21 |
22 | @Override
23 | public UserDetails loadUserByUsername(String s) throws UsernameNotFoundException {
24 | String user="user";
25 | if( !user.equals(s) ) {
26 | throw new UsernameNotFoundException("用户不存在");
27 | }
28 | return new User( s, passwordEncoder.encode("123456"), AuthorityUtils.commaSeparatedStringToAuthorityList("ROLE_USER"));
29 | }
30 | }
31 |
--------------------------------------------------------------------------------
/server/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 | 4.0.0
5 |
6 | org.springframework.boot
7 | spring-boot-starter-parent
8 | 2.1.5.RELEASE
9 |
10 |
11 | com.pjb
12 | server
13 | 0.0.1-SNAPSHOT
14 | server
15 | Demo project for Spring Boot
16 |
17 |
18 | 1.8
19 | Greenwich.SR1
20 |
21 |
22 |
23 |
24 | org.springframework.cloud
25 | spring-cloud-starter-oauth2
26 |
27 |
28 | org.springframework.boot
29 | spring-boot-starter-web
30 |
31 |
32 | org.springframework.boot
33 | spring-boot-starter-test
34 | test
35 |
36 |
37 |
38 |
39 |
40 |
41 | org.springframework.cloud
42 | spring-cloud-dependencies
43 | ${spring-cloud.version}
44 | pom
45 | import
46 |
47 |
48 |
49 |
50 |
51 |
52 |
53 | org.springframework.boot
54 | spring-boot-maven-plugin
55 |
56 |
57 |
58 |
59 |
60 |
--------------------------------------------------------------------------------
/client1/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 | 4.0.0
5 |
6 | org.springframework.boot
7 | spring-boot-starter-parent
8 | 2.1.5.RELEASE
9 |
10 |
11 | com.pjb
12 | client1
13 | 0.0.1-SNAPSHOT
14 | client1
15 | Demo project for Spring Boot
16 |
17 |
18 | 1.8
19 | Greenwich.SR1
20 |
21 |
22 |
23 |
24 | org.springframework.cloud
25 | spring-cloud-starter-oauth2
26 |
27 |
28 | org.springframework.boot
29 | spring-boot-starter-web
30 |
31 |
32 | org.springframework.boot
33 | spring-boot-starter-test
34 | test
35 |
36 |
37 |
38 |
39 |
40 |
41 | org.springframework.cloud
42 | spring-cloud-dependencies
43 | ${spring-cloud.version}
44 | pom
45 | import
46 |
47 |
48 |
49 |
50 |
51 |
52 |
53 | org.springframework.boot
54 | spring-boot-maven-plugin
55 |
56 |
57 |
58 |
59 |
60 |
--------------------------------------------------------------------------------
/client2/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 | 4.0.0
5 |
6 | org.springframework.boot
7 | spring-boot-starter-parent
8 | 2.1.5.RELEASE
9 |
10 |
11 | com.pjb
12 | client2
13 | 0.0.1-SNAPSHOT
14 | client2
15 | Demo project for Spring Boot
16 |
17 |
18 | 1.8
19 | Greenwich.SR1
20 |
21 |
22 |
23 |
24 | org.springframework.cloud
25 | spring-cloud-starter-oauth2
26 |
27 |
28 | org.springframework.boot
29 | spring-boot-starter-web
30 |
31 |
32 | org.springframework.boot
33 | spring-boot-starter-test
34 | test
35 |
36 |
37 |
38 |
39 |
40 |
41 | org.springframework.cloud
42 | spring-cloud-dependencies
43 | ${spring-cloud.version}
44 | pom
45 | import
46 |
47 |
48 |
49 |
50 |
51 |
52 |
53 | org.springframework.boot
54 | spring-boot-maven-plugin
55 |
56 |
57 |
58 |
59 |
60 |
--------------------------------------------------------------------------------
/server/src/main/java/com/pjb/server/config/SpringSecurityConfig.java:
--------------------------------------------------------------------------------
1 | package com.pjb.server.config;
2 |
3 | import org.springframework.beans.factory.annotation.Autowired;
4 | import org.springframework.beans.factory.annotation.Qualifier;
5 | import org.springframework.context.annotation.Bean;
6 | import org.springframework.context.annotation.Configuration;
7 | import org.springframework.security.authentication.dao.DaoAuthenticationProvider;
8 | import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder;
9 | import org.springframework.security.config.annotation.web.builders.HttpSecurity;
10 | import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;
11 | import org.springframework.security.core.userdetails.UserDetailsService;
12 | import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
13 | import org.springframework.security.crypto.password.PasswordEncoder;
14 |
15 | /**
16 | * @author jinbin
17 | * @date 2019-05-20 20:26
18 | */
19 |
20 | @Configuration
21 | public class SpringSecurityConfig extends WebSecurityConfigurerAdapter {
22 |
23 | @Autowired
24 | @Qualifier("SSOUserDetailsService")
25 | private UserDetailsService userDetailsService;
26 |
27 | @Bean
28 | public PasswordEncoder passwordEncoder() {
29 | return new BCryptPasswordEncoder();
30 | }
31 |
32 | @Bean
33 | public DaoAuthenticationProvider authenticationProvider() {
34 | DaoAuthenticationProvider authenticationProvider = new DaoAuthenticationProvider();
35 | authenticationProvider.setUserDetailsService(userDetailsService);
36 | authenticationProvider.setPasswordEncoder(passwordEncoder());
37 | authenticationProvider.setHideUserNotFoundExceptions(false);
38 | return authenticationProvider;
39 | }
40 |
41 | @Override
42 | protected void configure(HttpSecurity http) throws Exception {
43 |
44 | http.requestMatchers().antMatchers("/oauth/**", "/login/**", "/logout/**")
45 | .and()
46 | .authorizeRequests()
47 | .antMatchers("/oauth/**").authenticated()
48 | .and()
49 | .formLogin().permitAll();
50 | }
51 |
52 | @Override
53 | protected void configure(AuthenticationManagerBuilder auth) {
54 | auth.authenticationProvider(authenticationProvider());
55 | }
56 |
57 | }
58 |
--------------------------------------------------------------------------------
/server/src/main/java/com/pjb/server/config/AuthorizationServerConfig.java:
--------------------------------------------------------------------------------
1 | package com.pjb.server.config;
2 |
3 | import org.springframework.context.annotation.Bean;
4 | import org.springframework.context.annotation.Configuration;
5 | import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
6 | import org.springframework.security.oauth2.config.annotation.configurers.ClientDetailsServiceConfigurer;
7 | import org.springframework.security.oauth2.config.annotation.web.configuration.AuthorizationServerConfigurerAdapter;
8 | import org.springframework.security.oauth2.config.annotation.web.configuration.EnableAuthorizationServer;
9 | import org.springframework.security.oauth2.config.annotation.web.configurers.AuthorizationServerEndpointsConfigurer;
10 | import org.springframework.security.oauth2.config.annotation.web.configurers.AuthorizationServerSecurityConfigurer;
11 | import org.springframework.security.oauth2.provider.token.DefaultTokenServices;
12 | import org.springframework.security.oauth2.provider.token.TokenStore;
13 | import org.springframework.security.oauth2.provider.token.store.JwtAccessTokenConverter;
14 | import org.springframework.security.oauth2.provider.token.store.JwtTokenStore;
15 |
16 | import java.util.concurrent.TimeUnit;
17 |
18 | /**
19 | * @author jinbin
20 | * @date 2019-05-20 20:23
21 | */
22 |
23 | @Configuration
24 | @EnableAuthorizationServer
25 | public class AuthorizationServerConfig extends AuthorizationServerConfigurerAdapter {
26 | @Override
27 | public void configure(ClientDetailsServiceConfigurer clients) throws Exception {
28 |
29 | // 定义了两个客户端应用的通行证
30 | clients.inMemory()
31 | .withClient("ben1")
32 | .secret(new BCryptPasswordEncoder().encode("123456"))
33 | .authorizedGrantTypes("authorization_code", "refresh_token")
34 | .scopes("all")
35 | .autoApprove(true)
36 | //加上验证回调地址
37 | .redirectUris("http://localhost:8086/login")
38 | .and()
39 | .withClient("ben2")
40 | .secret(new BCryptPasswordEncoder().encode("123456"))
41 | .authorizedGrantTypes("authorization_code", "refresh_token")
42 | .scopes("all")
43 | .autoApprove(true)
44 | .redirectUris("http://localhost:8087/login");
45 | }
46 |
47 | @Override
48 | public void configure(AuthorizationServerEndpointsConfigurer endpoints) {
49 |
50 | //endpoints.tokenStore(jwtTokenStore()).accessTokenConverter(jwtAccessTokenConverter());
51 | DefaultTokenServices tokenServices = (DefaultTokenServices) endpoints.getDefaultAuthorizationServerTokenServices();
52 | //tokenServices.setTokenStore(endpoints.getTokenStore());
53 | tokenServices.setTokenStore(jwtTokenStore());
54 | tokenServices.setSupportRefreshToken(true);
55 | tokenServices.setClientDetailsService(endpoints.getClientDetailsService());
56 | //tokenServices.setTokenEnhancer(endpoints.getTokenEnhancer());
57 | tokenServices.setTokenEnhancer(jwtAccessTokenConverter());
58 | // 一天有效期
59 | tokenServices.setAccessTokenValiditySeconds((int) TimeUnit.DAYS.toSeconds(1));
60 | endpoints.tokenServices(tokenServices);
61 | }
62 |
63 | @Override
64 | public void configure(AuthorizationServerSecurityConfigurer security) {
65 | security.tokenKeyAccess("isAuthenticated()");
66 | }
67 |
68 | @Bean
69 | public TokenStore jwtTokenStore() {
70 | return new JwtTokenStore(jwtAccessTokenConverter());
71 | }
72 |
73 | @Bean
74 | public JwtAccessTokenConverter jwtAccessTokenConverter(){
75 | JwtAccessTokenConverter converter = new JwtAccessTokenConverter();
76 | converter.setSigningKey("testKey");
77 | return converter;
78 | }
79 | }
80 |
--------------------------------------------------------------------------------