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

The following examples show how to use org.springframework.security.oauth2.provider.token.UserAuthenticationConverter. 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: CustomJwtAccessTokenConverter.java    From spring-security with Apache License 2.0 5 votes vote down vote up
@Override
public OAuth2Authentication extractAuthentication(Map<String, ?> map) {
    DefaultAccessTokenConverter accessTokenConverter = new DefaultAccessTokenConverter();
    UserAuthenticationConverter userAuthenticationConverter = new CustomUserAuthenticationConverter();
    accessTokenConverter.setUserTokenConverter(userAuthenticationConverter);
    return accessTokenConverter.extractAuthentication(map);

}
 
Example #2
Source File: CustomJwtAccessTokenConverter.java    From spring-security with Apache License 2.0 5 votes vote down vote up
@Override
public OAuth2Authentication extractAuthentication(Map<String, ?> map) {
    DefaultAccessTokenConverter accessTokenConverter = new DefaultAccessTokenConverter();
    UserAuthenticationConverter userAuthenticationConverter = new CustomUserAuthenticationConverter();
    accessTokenConverter.setUserTokenConverter(userAuthenticationConverter);
    return accessTokenConverter.extractAuthentication(map);

}
 
Example #3
Source File: CustomAccessTokenConverter.java    From microservices-oauth with Apache License 2.0 5 votes vote down vote up
public Map<String, ?> convertAccessToken(OAuth2AccessToken token, OAuth2Authentication authentication) {
	Map<String, Object> response = new HashMap<String, Object>();
	OAuth2Request clientToken = authentication.getOAuth2Request();

	if (!authentication.isClientOnly())
		response.putAll(userTokenConverter.convertUserAuthentication(authentication.getUserAuthentication()));
	else if (clientToken.getAuthorities() != null && !clientToken.getAuthorities().isEmpty())
		response.put(UserAuthenticationConverter.AUTHORITIES,
				AuthorityUtils.authorityListToSet(clientToken.getAuthorities()));

	if (token.getScope() != null)
		response.put(SCOPE, token.getScope());

	if (token.getAdditionalInformation().containsKey(JTI))
		response.put(JTI, token.getAdditionalInformation().get(JTI));

	if (token.getExpiration() != null)
		response.put(EXP, token.getExpiration().getTime() / 1000);

	if (includeGrantType && authentication.getOAuth2Request().getGrantType() != null)
		response.put(GRANT_TYPE, authentication.getOAuth2Request().getGrantType());

	response.putAll(token.getAdditionalInformation());

	response.put(CLIENT_ID, clientToken.getClientId());
	if (clientToken.getResourceIds() != null && !clientToken.getResourceIds().isEmpty())
		response.put(AUD, clientToken.getResourceIds());

	return response;
}
 
Example #4
Source File: CustomAccessTokenConverter.java    From spring-boot-2-oauth2-resource-jwt with MIT License 5 votes vote down vote up
public Map<String, ?> convertAccessToken(OAuth2AccessToken token, OAuth2Authentication authentication) {
	Map<String, Object> response = new HashMap<String, Object>();
	OAuth2Request clientToken = authentication.getOAuth2Request();

	if (!authentication.isClientOnly())
		response.putAll(userTokenConverter.convertUserAuthentication(authentication.getUserAuthentication()));
	else if (clientToken.getAuthorities() != null && !clientToken.getAuthorities().isEmpty())
		response.put(UserAuthenticationConverter.AUTHORITIES,
				AuthorityUtils.authorityListToSet(clientToken.getAuthorities()));

	if (token.getScope() != null)
		response.put(SCOPE, token.getScope());

	if (token.getAdditionalInformation().containsKey(JTI))
		response.put(JTI, token.getAdditionalInformation().get(JTI));

	if (token.getExpiration() != null)
		response.put(EXP, token.getExpiration().getTime() / 1000);

	if (includeGrantType && authentication.getOAuth2Request().getGrantType() != null)
		response.put(GRANT_TYPE, authentication.getOAuth2Request().getGrantType());

	response.putAll(token.getAdditionalInformation());

	response.put(CLIENT_ID, clientToken.getClientId());
	if (clientToken.getResourceIds() != null && !clientToken.getResourceIds().isEmpty())
		response.put(AUD, clientToken.getResourceIds());

	return response;
}
 
Example #5
Source File: CustomAccessTokenConverter.java    From microservices-oauth with Apache License 2.0 4 votes vote down vote up
public void setUserTokenConverter(UserAuthenticationConverter userTokenConverter) {
	this.userTokenConverter = userTokenConverter;
}
 
Example #6
Source File: CustomAccessTokenConverter.java    From spring-boot-2-oauth2-resource-jwt with MIT License 4 votes vote down vote up
public void setUserTokenConverter(UserAuthenticationConverter userTokenConverter) {
	this.userTokenConverter = userTokenConverter;
}
 
Example #7
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 #8
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 #9
Source File: FacebookAccessTokenConverter.java    From geowave with Apache License 2.0 2 votes vote down vote up
/**
 * Converter for the part of the data in the token representing a user.
 *
 * @param userTokenConverter the userTokenConverter to set
 */
@Override
public final void setUserTokenConverter(final UserAuthenticationConverter userTokenConverter) {}