org.springframework.security.oauth2.provider.token.DefaultUserAuthenticationConverter Java Examples

The following examples show how to use org.springframework.security.oauth2.provider.token.DefaultUserAuthenticationConverter. 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 vote down vote up
/**
 * 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: BaseResourceServerConfigurerAdapter.java    From smaker with GNU Lesser General Public License v3.0 5 votes vote down vote up
/**
 * 不获取用户详细 只有用户名
 *
 * @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 #3
Source File: BaseResourceServerConfigurerAdapter.java    From smaker with GNU Lesser General Public License v3.0 5 votes vote down vote up
/**
 * 上下文中获取用户全部信息,两次调用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 #4
Source File: FebsAuthorizationServerConfigure.java    From FEBS-Cloud with Apache License 2.0 5 votes vote down vote up
@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 #5
Source File: OAuth2ResourceServer.java    From OAuth-2.0-Cookbook with MIT License 4 votes vote down vote up
@Bean
public UserAuthenticationConverter userTokenConverter() {
    DefaultUserAuthenticationConverter converter = new DefaultUserAuthenticationConverter();
    converter.setUserDetailsService(userDetailsService);
    return converter;
}
 
Example #6
Source File: OAuth2ResourceServer.java    From OAuth-2.0-Cookbook with MIT License 4 votes vote down vote up
@Bean
public UserAuthenticationConverter userTokenConverter() {
    DefaultUserAuthenticationConverter converter = new DefaultUserAuthenticationConverter();
    converter.setUserDetailsService(userDetailsService);
    return converter;
}