Java Code Examples for org.springframework.security.oauth2.provider.token.DefaultAccessTokenConverter#setUserTokenConverter()
The following examples show how to use
org.springframework.security.oauth2.provider.token.DefaultAccessTokenConverter#setUserTokenConverter() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: AuthorizationServerConfig.java From cloud-service with MIT License | 7 votes |
/** * Jwt资源令牌转换器<br> * 参数access_token.store-jwt为true时用到 * * @return accessTokenConverter */ @Bean public JwtAccessTokenConverter accessTokenConverter() { JwtAccessTokenConverter jwtAccessTokenConverter = new JwtAccessTokenConverter() { @Override public OAuth2AccessToken enhance(OAuth2AccessToken accessToken, OAuth2Authentication authentication) { OAuth2AccessToken oAuth2AccessToken = super.enhance(accessToken, authentication); addLoginUserInfo(oAuth2AccessToken, authentication); // 2019.07.13 将当前用户信息追加到登陆后返回数据里 return oAuth2AccessToken; } }; DefaultAccessTokenConverter defaultAccessTokenConverter = (DefaultAccessTokenConverter) jwtAccessTokenConverter .getAccessTokenConverter(); DefaultUserAuthenticationConverter userAuthenticationConverter = new DefaultUserAuthenticationConverter(); userAuthenticationConverter.setUserDetailsService(userDetailsService); defaultAccessTokenConverter.setUserTokenConverter(userAuthenticationConverter); // 2019.06.29 这里务必设置一个,否则多台认证中心的话,一旦使用jwt方式,access_token将解析错误 jwtAccessTokenConverter.setSigningKey(signingKey); return jwtAccessTokenConverter; }
Example 2
Source File: OauthAuthorizationServerConfig.java From codeway_service with GNU General Public License v3.0 | 5 votes |
/** * 配置AccessToken加密方式 */ @Bean public JwtAccessTokenConverter jwtAccessTokenConverter(CustomUserAuthenticationConverter customUserAuthenticationConverter) { JwtAccessTokenConverter converter = new JwtAccessTokenConverter(); KeyPair keyPair = new KeyStoreKeyFactory( keyProperties.getKeyStore().getLocation(), keyProperties.getKeyStore().getSecret().toCharArray()).getKeyPair( keyProperties.getKeyStore().getAlias(), keyProperties.getKeyStore().getPassword().toCharArray()); converter.setKeyPair(keyPair); //配置自定义的CustomUserAuthenticationConverter DefaultAccessTokenConverter accessTokenConverter = (DefaultAccessTokenConverter) converter.getAccessTokenConverter(); accessTokenConverter.setUserTokenConverter(customUserAuthenticationConverter); return converter; }
Example 3
Source File: BaseResourceServerConfigurerAdapter.java From smaker with GNU Lesser General Public License v3.0 | 5 votes |
/** * 不获取用户详细 只有用户名 * * @param resources */ protected void notGetUser(ResourceServerSecurityConfigurer resources) { DefaultAccessTokenConverter accessTokenConverter = new DefaultAccessTokenConverter(); DefaultUserAuthenticationConverter userTokenConverter = new DefaultUserAuthenticationConverter(); accessTokenConverter.setUserTokenConverter(userTokenConverter); remoteTokenServices.setRestTemplate(lbRestTemplate()); remoteTokenServices.setAccessTokenConverter(accessTokenConverter); resources.authenticationEntryPoint(resourceAuthExceptionEntryPoint) .accessDeniedHandler(AccessDeniedHandler) .tokenServices(remoteTokenServices); }
Example 4
Source File: BaseResourceServerConfigurerAdapter.java From smaker with GNU Lesser General Public License v3.0 | 5 votes |
/** * 上下文中获取用户全部信息,两次调用userDetailsService,影响性能 * * @param resources */ private void canGetUser(ResourceServerSecurityConfigurer resources) { DefaultAccessTokenConverter accessTokenConverter = new DefaultAccessTokenConverter(); DefaultUserAuthenticationConverter userTokenConverter = new DefaultUserAuthenticationConverter(); userTokenConverter.setUserDetailsService(userDetailsService); accessTokenConverter.setUserTokenConverter(userTokenConverter); remoteTokenServices.setRestTemplate(lbRestTemplate()); remoteTokenServices.setAccessTokenConverter(accessTokenConverter); resources.authenticationEntryPoint(resourceAuthExceptionEntryPoint) .accessDeniedHandler(AccessDeniedHandler) .tokenServices(remoteTokenServices); }
Example 5
Source File: FebsAuthorizationServerConfigure.java From FEBS-Cloud with Apache License 2.0 | 5 votes |
@Bean public JwtAccessTokenConverter jwtAccessTokenConverter() { JwtAccessTokenConverter accessTokenConverter = new JwtAccessTokenConverter(); DefaultAccessTokenConverter defaultAccessTokenConverter = (DefaultAccessTokenConverter) accessTokenConverter.getAccessTokenConverter(); DefaultUserAuthenticationConverter userAuthenticationConverter = new DefaultUserAuthenticationConverter(); userAuthenticationConverter.setUserDetailsService(userDetailService); defaultAccessTokenConverter.setUserTokenConverter(userAuthenticationConverter); accessTokenConverter.setSigningKey(properties.getJwtAccessKey()); return accessTokenConverter; }
Example 6
Source File: ResJwtTokenStore.java From microservices-platform with Apache License 2.0 | 5 votes |
@Bean public JwtAccessTokenConverter jwtAccessTokenConverter() { JwtAccessTokenConverter converter = new JwtAccessTokenConverter(); converter.setVerifierKey(getPubKey()); DefaultAccessTokenConverter tokenConverter = (DefaultAccessTokenConverter)converter.getAccessTokenConverter(); tokenConverter.setUserTokenConverter(new CustomUserAuthenticationConverter()); return converter; }
Example 7
Source File: AuthJwtTokenStore.java From microservices-platform with Apache License 2.0 | 5 votes |
@Bean public JwtAccessTokenConverter jwtAccessTokenConverter() { final JwtAccessTokenConverter converter = new JwtAccessTokenConverter(); KeyPair keyPair = new KeyStoreKeyFactory (keyProperties.getKeyStore().getLocation(), keyProperties.getKeyStore().getSecret().toCharArray()) .getKeyPair(keyProperties.getKeyStore().getAlias()); converter.setKeyPair(keyPair); DefaultAccessTokenConverter tokenConverter = (DefaultAccessTokenConverter)converter.getAccessTokenConverter(); tokenConverter.setUserTokenConverter(new CustomUserAuthenticationConverter()); return converter; }
Example 8
Source File: CustomJwtAccessTokenConverter.java From spring-security with Apache License 2.0 | 5 votes |
@Override public OAuth2Authentication extractAuthentication(Map<String, ?> map) { DefaultAccessTokenConverter accessTokenConverter = new DefaultAccessTokenConverter(); UserAuthenticationConverter userAuthenticationConverter = new CustomUserAuthenticationConverter(); accessTokenConverter.setUserTokenConverter(userAuthenticationConverter); return accessTokenConverter.extractAuthentication(map); }
Example 9
Source File: CustomJwtAccessTokenConverter.java From spring-security with Apache License 2.0 | 5 votes |
@Override public OAuth2Authentication extractAuthentication(Map<String, ?> map) { DefaultAccessTokenConverter accessTokenConverter = new DefaultAccessTokenConverter(); UserAuthenticationConverter userAuthenticationConverter = new CustomUserAuthenticationConverter(); accessTokenConverter.setUserTokenConverter(userAuthenticationConverter); return accessTokenConverter.extractAuthentication(map); }
Example 10
Source File: OpenHelper.java From open-cloud with MIT License | 5 votes |
/** * 构建token转换器 * * @return */ public static DefaultAccessTokenConverter buildAccessTokenConverter() { OpenUserConverter userAuthenticationConverter = new OpenUserConverter(); DefaultAccessTokenConverter accessTokenConverter = new DefaultAccessTokenConverter(); accessTokenConverter.setUserTokenConverter(userAuthenticationConverter); return accessTokenConverter; }
Example 11
Source File: OauthAuthorizationServerConfig.java From codeway_service with GNU General Public License v3.0 | 5 votes |
/** * 配置AccessToken加密方式 */ @Bean public JwtAccessTokenConverter jwtAccessTokenConverter(CustomUserAuthenticationConverter customUserAuthenticationConverter) { JwtAccessTokenConverter converter = new JwtAccessTokenConverter(); KeyPair keyPair = new KeyStoreKeyFactory( keyProperties.getKeyStore().getLocation(), keyProperties.getKeyStore().getSecret().toCharArray()).getKeyPair( keyProperties.getKeyStore().getAlias(), keyProperties.getKeyStore().getPassword().toCharArray()); converter.setKeyPair(keyPair); //配置自定义的CustomUserAuthenticationConverter DefaultAccessTokenConverter accessTokenConverter = (DefaultAccessTokenConverter) converter.getAccessTokenConverter(); accessTokenConverter.setUserTokenConverter(customUserAuthenticationConverter); return converter; }
Example 12
Source File: ResourceServerConfiguration.java From spring-cloud-contract-samples with Apache License 2.0 | 5 votes |
/** * <p> * Configures jwt related access token converter to allow enhanced user details to be * converted. * </p> * @param jwtAccessTokenConverter the converter to configure */ @Autowired public void configure(JwtAccessTokenConverter jwtAccessTokenConverter) { notNull(jwtAccessTokenConverter, "jwtAccessTokenConverter"); DefaultAccessTokenConverter defaultAccessTokenConverter = (DefaultAccessTokenConverter) jwtAccessTokenConverter .getAccessTokenConverter(); defaultAccessTokenConverter .setUserTokenConverter(new UserAuthenticationConverter()); }
Example 13
Source File: SecurityConfig.java From codenjoy with GNU General Public License v3.0 | 5 votes |
@Bean public TokenStore tokenStore() { JwtAccessTokenConverter accessTokenConverter = new JwtAccessTokenConverter(); DefaultAccessTokenConverter tokenConverter = new DefaultAccessTokenConverter(); tokenConverter.setUserTokenConverter(oAuth2UserAuthenticationConverter); accessTokenConverter.setAccessTokenConverter(tokenConverter); return new JwkTokenStore(clientProperties.getProvider().get("dojo").getJwkSetUri(), accessTokenConverter); }
Example 14
Source File: OAuth2ResourceServer.java From OAuth-2.0-Cookbook with MIT License | 4 votes |
@Bean public AccessTokenConverter accessTokenConverter() { DefaultAccessTokenConverter converter = new DefaultAccessTokenConverter(); converter.setUserTokenConverter(userTokenConverter()); return converter; }
Example 15
Source File: OAuth2ResourceServer.java From OAuth-2.0-Cookbook with MIT License | 4 votes |
@Bean public AccessTokenConverter accessTokenConverter() { DefaultAccessTokenConverter converter = new DefaultAccessTokenConverter(); converter.setUserTokenConverter(userTokenConverter()); return converter; }