From 687ddd477b15dd6211c4da98fd9d34620f0fbe3d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=A9=AC=E5=A2=9E=E7=BE=A4?= Date: Fri, 15 May 2020 17:12:15 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BD=BF=E7=94=A8JWT=E5=AD=98=E5=82=A8token?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/main/resources/application.properties | 2 +- .../configuration/OAuth2Configuration.java | 30 +++++++++---------- 2 files changed, 16 insertions(+), 16 deletions(-) diff --git a/code/jeeplatform-cms/src/main/resources/application.properties b/code/jeeplatform-cms/src/main/resources/application.properties index 4bd8315..d4a6260 100644 --- a/code/jeeplatform-cms/src/main/resources/application.properties +++ b/code/jeeplatform-cms/src/main/resources/application.properties @@ -7,7 +7,7 @@ security.oauth2.resource.user-info-uri=http://localhost:8888/user security.oauth2.client.use-current-uri=false security.oauth2.client.pre-established-redirect-uri=http://localhost:8084/cms/login security.oauth2.resource.token-info-uri= http://localhost:8888/oauth/check_token -#security.oauth2.resource.jwt.key-uri=http://localhost:8888/oauth/token_key +security.oauth2.resource.jwt.key-uri=http://localhost:8888/oauth/token_key security.oauth2.authorization.check-token-access= http://localhost:8888/oauth/check_token server.port=8084 diff --git a/code/jeeplatform-sso-oauth2/src/main/java/org/muses/jeeplatform/oauth/configuration/OAuth2Configuration.java b/code/jeeplatform-sso-oauth2/src/main/java/org/muses/jeeplatform/oauth/configuration/OAuth2Configuration.java index fe17ab5..860e208 100644 --- a/code/jeeplatform-sso-oauth2/src/main/java/org/muses/jeeplatform/oauth/configuration/OAuth2Configuration.java +++ b/code/jeeplatform-sso-oauth2/src/main/java/org/muses/jeeplatform/oauth/configuration/OAuth2Configuration.java @@ -100,17 +100,17 @@ public class OAuth2Configuration extends AuthorizationServerConfigurerAdapter { @Override public void configure(AuthorizationServerEndpointsConfigurer endpoints) throws Exception { - //endpoints.tokenStore(jwtTokenStore()).authenticationManager(authenticationManager) - //.accessTokenConverter(accessTokenConverter()) + endpoints.tokenStore(jwtTokenStore()).authenticationManager(authenticationManager) + .accessTokenConverter(accessTokenConverter()) //必须注入userDetailsService否则根据refresh_token无法加载用户信息 //.userDetailsService(userDetailsService) //支持获取token方式 - //.allowedTokenEndpointRequestMethods(HttpMethod.GET, HttpMethod.POST,HttpMethod.PUT,HttpMethod.DELETE,HttpMethod.OPTIONS) + .allowedTokenEndpointRequestMethods(HttpMethod.GET, HttpMethod.POST,HttpMethod.PUT,HttpMethod.DELETE,HttpMethod.OPTIONS); //刷新token //.reuseRefreshTokens(false) - //.tokenServices(tokenServices()); + //endpoints .tokenServices(tokenServices()); // 使用内存保存生成的token - endpoints.authenticationManager(authenticationManager).tokenStore(memoryTokenStore()); + //endpoints.authenticationManager(authenticationManager).tokenStore(memoryTokenStore()); } /** @@ -155,23 +155,23 @@ public class OAuth2Configuration extends AuthorizationServerConfigurerAdapter { return converter; } -// @Bean -// public TokenStore jwtTokenStore() { -// //基于jwt实现令牌(Access Token)保存 -// return new JwtTokenStore(accessTokenConverter()); -// } - @Bean - public TokenStore memoryTokenStore() { - // 最基本的InMemoryTokenStore生成token - return new InMemoryTokenStore(); + public TokenStore jwtTokenStore() { + //基于jwt实现令牌(Access Token)保存 + return new JwtTokenStore(accessTokenConverter()); } +// @Bean +// public TokenStore memoryTokenStore() { +// // 最基本的InMemoryTokenStore生成token +// return new InMemoryTokenStore(); +// } + @Bean public DefaultTokenServices tokenServices() { final DefaultTokenServices defaultTokenServices = new DefaultTokenServices(); defaultTokenServices.setTokenEnhancer(accessTokenConverter()); - defaultTokenServices.setTokenStore(memoryTokenStore()); + defaultTokenServices.setTokenStore(jwtTokenStore()); defaultTokenServices.setSupportRefreshToken(false); defaultTokenServices.setAccessTokenValiditySeconds((int) TimeUnit.DAYS.toSeconds(30)); return defaultTokenServices; -- GitLab