Java Code Examples for org.springframework.security.oauth2.provider.ClientDetails#getResourceIds()

The following examples show how to use org.springframework.security.oauth2.provider.ClientDetails#getResourceIds() . 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: OAuthHelper.java    From resource-server-testing with MIT License 6 votes vote down vote up
public OAuth2Authentication oAuth2Authentication(final String clientId, final String username) {
	// Look up authorities, resourceIds and scopes based on clientId
	ClientDetails client = clientDetailsService.loadClientByClientId(clientId);
	Collection<GrantedAuthority> authorities = client.getAuthorities();
	Set<String> resourceIds = client.getResourceIds();
	Set<String> scopes = client.getScope();

	// Default values for other parameters
	Map<String, String> requestParameters = Collections.emptyMap();
	boolean approved = true;
	String redirectUrl = null;
	Set<String> responseTypes = Collections.emptySet();
	Map<String, Serializable> extensionProperties = Collections.emptyMap();

	// Create request
	OAuth2Request oAuth2Request = new OAuth2Request(requestParameters, clientId, authorities, approved, scopes, resourceIds, redirectUrl, responseTypes, extensionProperties);

	// Create OAuth2AccessToken
	UserDetails user = userDetailsService.loadUserByUsername(username);
	UsernamePasswordAuthenticationToken authenticationToken = new UsernamePasswordAuthenticationToken(user, null, authorities);
	OAuth2Authentication auth = new OAuth2Authentication(oAuth2Request, authenticationToken);
	return auth;
}
 
Example 2
Source File: UserTokenRequest.java    From spring-cloud-gray with Apache License 2.0 5 votes vote down vote up
public OAuth2Request createOAuth2Request(ClientDetails client) {
    Map<String, String> requestParameters = getRequestParameters();
    HashMap<String, String> modifiable = new HashMap<String, String>(requestParameters);
    // Remove password if present to prevent leaks
    modifiable.remove("password");
    modifiable.remove("client_secret");
    // Add grant type so it can be retrieved from OAuth2Request
    modifiable.put("grant_type", getGrantType());
    return new OAuth2Request(modifiable, client.getClientId(), client.getAuthorities(), true, this.getScope(),
        client.getResourceIds(), null, null, extensionProperties);
}