Example usage for org.springframework.security.oauth2.client OAuth2ClientContext setAccessToken

List of usage examples for org.springframework.security.oauth2.client OAuth2ClientContext setAccessToken

Introduction

In this page you can find the example usage for org.springframework.security.oauth2.client OAuth2ClientContext setAccessToken.

Prototype

void setAccessToken(OAuth2AccessToken accessToken);

Source Link

Usage

From source file:org.cloudfoundry.identity.uaa.login.util.LocalUaaRestTemplate.java

@Override
protected OAuth2AccessToken acquireAccessToken(OAuth2ClientContext oauth2Context)
        throws UserRedirectRequiredException {
    ClientDetails client = clientDetailsService.loadClientByClientId(getClientId());
    Set<String> scopes = new HashSet<>();
    for (GrantedAuthority authority : client.getAuthorities()) {
        scopes.add(authority.getAuthority());
    }//from ww  w.  j  a va  2  s .  co m
    Set<String> resourceIds = new HashSet<>();
    resourceIds.add(Origin.UAA);
    Set<String> responseTypes = new HashSet<>();
    responseTypes.add("token");
    Map<String, String> requestParameters = new HashMap<>();
    requestParameters.put(OAuth2Utils.CLIENT_ID, "login");
    requestParameters.put(OAuth2Utils.GRANT_TYPE, "client_credentials");
    OAuth2Request request = new OAuth2Request(requestParameters, "login",
            (Collection<? extends GrantedAuthority>) Collections.EMPTY_SET, true, scopes, resourceIds, null,
            responseTypes, Collections.EMPTY_MAP);
    OAuth2Authentication authentication = new OAuth2Authentication(request, null);
    OAuth2AccessToken result = tokenServices.createAccessToken(authentication);
    oauth2Context.setAccessToken(result);
    return result;
}