Example usage for org.springframework.security.oauth2.client.token.grant.code AuthorizationCodeResourceDetails setPreEstablishedRedirectUri

List of usage examples for org.springframework.security.oauth2.client.token.grant.code AuthorizationCodeResourceDetails setPreEstablishedRedirectUri

Introduction

In this page you can find the example usage for org.springframework.security.oauth2.client.token.grant.code AuthorizationCodeResourceDetails setPreEstablishedRedirectUri.

Prototype

public void setPreEstablishedRedirectUri(String preEstablishedRedirectUri) 

Source Link

Document

The redirect URI that has been pre-established with the server.

Usage

From source file:org.cloudfoundry.identity.client.UaaContextFactory.java

/**
 * Not yet implemented//from   w  w w . jav  a2  s . c  om
 * @param tokenRequest - a configured TokenRequest
 * @return an authenticated {@link UaaContext}
 */
protected UaaContext authenticateAuthCode(final TokenRequest tokenRequest) {
    AuthorizationCodeResourceDetails details = new AuthorizationCodeResourceDetails();
    details.setPreEstablishedRedirectUri(tokenRequest.getRedirectUri().toString());
    details.setUserAuthorizationUri(tokenRequest.getAuthorizationEndpoint().toString());
    configureResourceDetails(tokenRequest, details);
    setClientCredentials(tokenRequest, details);
    setRequestScopes(tokenRequest, details);

    //begin - work around for not having UI for now
    DefaultOAuth2ClientContext oAuth2ClientContext = new DefaultOAuth2ClientContext();
    oAuth2ClientContext.getAccessTokenRequest().setStateKey(tokenRequest.getState());
    oAuth2ClientContext.setPreservedState(tokenRequest.getState(), details.getPreEstablishedRedirectUri());
    oAuth2ClientContext.getAccessTokenRequest().setCurrentUri(details.getPreEstablishedRedirectUri());
    //end - work around for not having UI for now

    OAuth2RestTemplate template = new OAuth2RestTemplate(details, oAuth2ClientContext);
    skipSslValidation(tokenRequest, template, null);
    template.getAccessToken();
    throw new UnsupportedOperationException(AUTHORIZATION_CODE + " is not yet implemented");
}

From source file:org.cloudfoundry.identity.client.UaaContextFactory.java

/**
 * Performs and authorization_code grant, but uses a token to assert the user's identity.
 * @param tokenRequest - a configured TokenRequest
 * @return an authenticated {@link UaaContext}
 *///  w w w  . j  a  v a  2  s.  co m
protected UaaContext authenticateAuthCodeWithToken(final TokenRequest tokenRequest) {
    List<OAuth2AccessTokenSupport> providers = Collections
            .singletonList(new AuthorizationCodeAccessTokenProvider() {
                @Override
                protected ResponseExtractor<OAuth2AccessToken> getResponseExtractor() {
                    getRestTemplate(); // force initialization
                    MappingJackson2HttpMessageConverter converter = new MappingJackson2HttpMessageConverter();
                    return new HttpMessageConverterExtractor<OAuth2AccessToken>(CompositeAccessToken.class,
                            Arrays.asList(converter));
                }
            });
    enhanceRequestParameters(tokenRequest, providers.get(0));
    AuthorizationCodeResourceDetails details = new AuthorizationCodeResourceDetails();
    details.setPreEstablishedRedirectUri(tokenRequest.getRedirectUri().toString());
    configureResourceDetails(tokenRequest, details);
    setClientCredentials(tokenRequest, details);
    setRequestScopes(tokenRequest, details);
    details.setUserAuthorizationUri(tokenRequest.getAuthorizationEndpoint().toString());
    DefaultOAuth2ClientContext oAuth2ClientContext = new DefaultOAuth2ClientContext();
    oAuth2ClientContext.getAccessTokenRequest().setStateKey(tokenRequest.getState());
    oAuth2ClientContext.setPreservedState(tokenRequest.getState(), details.getPreEstablishedRedirectUri());
    oAuth2ClientContext.getAccessTokenRequest().setCurrentUri(details.getPreEstablishedRedirectUri());
    Map<String, List<String>> headers = (Map<String, List<String>>) oAuth2ClientContext.getAccessTokenRequest()
            .getHeaders();
    headers.put("Authorization", Arrays.asList("bearer " + tokenRequest.getAuthCodeAPIToken()));
    OAuth2RestTemplate template = new OAuth2RestTemplate(details, oAuth2ClientContext);
    skipSslValidation(tokenRequest, template, providers);
    OAuth2AccessToken token = template.getAccessToken();
    return new UaaContextImpl(tokenRequest, template, (CompositeAccessToken) token);
}

From source file:org.cloudfoundry.identity.uaa.test.UaaTestAccounts.java

public AuthorizationCodeResourceDetails getDefaultAuthorizationCodeResource() {
    ResourceOwnerPasswordResourceDetails resource = getDefaultResourceOwnerPasswordResource();
    AuthorizationCodeResourceDetails result = new AuthorizationCodeResourceDetails();
    result.setAccessTokenUri(resource.getAccessTokenUri());
    result.setUserAuthorizationUri(resource.getAccessTokenUri().replace("/token", "/authorize"));
    result.setClientId(resource.getClientId());
    result.setClientSecret(resource.getClientSecret());
    String redirectUri = environment.getProperty("oauth.clients.app.redirect-uri",
            "http://localhost:8080/app/");
    result.setPreEstablishedRedirectUri(redirectUri);
    return result;
}