Example usage for org.springframework.security.oauth2.client OAuth2RestTemplate OAuth2RestTemplate

List of usage examples for org.springframework.security.oauth2.client OAuth2RestTemplate OAuth2RestTemplate

Introduction

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

Prototype

public OAuth2RestTemplate(OAuth2ProtectedResourceDetails resource) 

Source Link

Usage

From source file:com.create.application.configuration.TestConfiguration.java

@Bean
@Lazy//  w w  w  . j av  a  2  s .  c o  m
public OAuth2RestTemplate authenticatedUserRestTemplate(TestRestTemplate testRestTemplate,
        @Qualifier("authenticatedUserResourceDetails") OAuth2ProtectedResourceDetails resourceDetails) {
    final OAuth2RestTemplate restTemplate = new OAuth2RestTemplate(resourceDetails);
    restTemplate.setRequestFactory(new BufferingClientHttpRequestFactory(restTemplate.getRequestFactory()));
    return restTemplate;
}

From source file:org.cloudfoundry.identity.uaa.integration.OpenIdTokenAuthorizationWithApprovalIntegrationTests.java

@Before
public void createRestTemplate() throws Exception {

    ClientCredentialsResourceDetails clientCredentials = getClientCredentialsResource(
            new String[] { "oauth.login" }, "login", "loginsecret");
    loginClient = new OAuth2RestTemplate(clientCredentials);
    loginClient.setRequestFactory(new StatelessRequestFactory());
    loginClient.setErrorHandler(new OAuth2ErrorHandler(clientCredentials) {
        // Pass errors through in response entity for status code analysis
        @Override//  ww  w  .  java  2s .c o  m
        public boolean hasError(ClientHttpResponse response) throws IOException {
            return false;
        }

        @Override
        public void handleError(ClientHttpResponse response) throws IOException {
        }
    });

    Assume.assumeTrue(!testAccounts.isProfileActive("vcap"));

    client = (RestTemplate) serverRunning.getRestTemplate();
    client.setErrorHandler(new OAuth2ErrorHandler(context.getResource()) {
        // Pass errors through in response entity for status code analysis
        @Override
        public boolean hasError(ClientHttpResponse response) throws IOException {
            return false;
        }

        @Override
        public void handleError(ClientHttpResponse response) throws IOException {
        }
    });
    user = createUser(new RandomValueStringGenerator().generate(), "openiduser", "openidlast",
            "test@openid,com", true).getBody();
}

From source file:cz.cvut.zuul.support.spring.provider.RemoteResourceTokenServicesBuilder.java

public RemoteResourceTokenServices build() {
    if (resourceBuilder.clientId != null && restTemplate != null) {
        throw new IllegalStateException("secured() cannot be used along with custom restTemplate");
    }//www .j  a  v a2 s  . c  o  m

    if (restTemplate == null) {
        restTemplate = resourceBuilder.clientId != null
                ? new OAuth2RestTemplate(resourceBuilder.buildResourceDetails())
                : new RestTemplate();
    }
    if (!cachingBuilder.disable) {
        restTemplate.getInterceptors().add(cachingBuilder.buildInterceptor());
    }

    RemoteResourceTokenServices services = new RemoteResourceTokenServices();
    services.setTokenInfoEndpointUrl(tokenInfoEndpointUri);
    services.setTokenParameterName(tokenParameterName);
    services.setRestTemplate(restTemplate);
    services.setDecorateErrorHandler(decorateErrorHandler);
    services.afterPropertiesSet();

    return services;
}

From source file:com.ge.predix.test.utils.ACSRestTemplateFactory.java

public OAuth2RestTemplate getACSTemplateWithPolicyScope() {
    if (this.authorizedACSTemplate == null) {
        this.authorizedACSTemplate = new OAuth2RestTemplate(getUserWithPolicyScope());
        this.authorizedACSTemplate.setRequestFactory(new HttpComponentsClientHttpRequestFactory());
    }//from  w  ww.j  a v  a 2  s .c om
    return this.authorizedACSTemplate;
}

From source file:ru.anr.base.facade.web.api.RestClient.java

/**
 * Constructor with OAuth2 resource// w ww  .j av  a  2s .  c  om
 * 
 * @param resource
 *            OAuth2 protected resource
 */
public RestClient(OAuth2ProtectedResourceDetails resource) {

    super();
    rest = initRest(new OAuth2RestTemplate(resource));
}

From source file:org.cloudfoundry.identity.uaa.login.feature.OpenIdTokenGrantsIT.java

@Before
public void setUp() throws Exception {
    ((RestTemplate) restOperations).setRequestFactory(new StatelessRequestFactory());
    ClientCredentialsResourceDetails clientCredentials = getClientCredentialsResource(
            new String[] { "scim.write" }, testAccounts.getAdminClientId(),
            testAccounts.getAdminClientSecret());
    client = new OAuth2RestTemplate(clientCredentials);
    client.setRequestFactory(new StatelessRequestFactory());
    client.setErrorHandler(new OAuth2ErrorHandler(clientCredentials) {
        // Pass errors through in response entity for status code analysis
        @Override/*from  ww w  .  j  a  va 2s  .  c o m*/
        public boolean hasError(ClientHttpResponse response) throws IOException {
            return false;
        }

        @Override
        public void handleError(ClientHttpResponse response) throws IOException {
        }
    });
    user = createUser(new RandomValueStringGenerator().generate(), "openiduser", "openidlast",
            "test@openid,com", true).getBody();
}

From source file:com.ge.predix.test.utils.ACSRestTemplateFactory.java

public OAuth2RestTemplate getOAuth2RestTemplateForZone1AdminClient() {
    if (this.zone1AdminACSTemplate == null) {
        ClientCredentialsResourceDetails resource = new ClientCredentialsResourceDetails();
        resource.setAccessTokenUri(this.accessTokenEndpointUrl);
        resource.setClientId(this.zone1AdminClientId);
        resource.setClientSecret(this.zone1AdminClientSecret);
        this.zone1AdminACSTemplate = new OAuth2RestTemplate(resource);
    }/*from  w  w  w  .ja  v  a 2  s.  co  m*/

    return this.zone1AdminACSTemplate;
}

From source file:com.create.controller.AuthenticationIT.java

private OAuth2RestTemplate getRestTemplateWithInvalidClientPassword() {
    final OAuth2ProtectedResourceDetails resourceDetails = getLocalOAuth2RemoteResourceWithInvalidClientPassword();
    return new OAuth2RestTemplate(resourceDetails);
}

From source file:com.ge.predix.test.utils.ACSRestTemplateFactory.java

public OAuth2RestTemplate getOAuth2RestTemplateForZone2AdminClient() {
    if (this.zone2AdminACSTemplate == null) {
        ClientCredentialsResourceDetails resource = new ClientCredentialsResourceDetails();
        resource.setAccessTokenUri(this.zone2TokenUrl);
        resource.setClientId(this.zone2AdminClientId);
        resource.setClientSecret(this.zone2AdminClientSecret);
        this.zone2AdminACSTemplate = new OAuth2RestTemplate(resource);
    }/*from  w  w  w.j  av a  2s .  c  o m*/

    return this.zone2AdminACSTemplate;
}

From source file:com.ge.predix.test.utils.ACSRestTemplateFactory.java

public OAuth2RestTemplate getOAuth2ResttemplateForZAC() {
    if (this.zacTemplate == null) {
        ClientCredentialsResourceDetails resource = new ClientCredentialsResourceDetails();
        resource.setAccessTokenUri(this.accessTokenEndpointUrl);
        resource.setClientId(this.zacClientId);
        resource.setClientSecret(this.zacClientSecret);
        this.zacTemplate = new OAuth2RestTemplate(resource);
    }/*  w  w  w  .j  a  va2s.c om*/

    return this.zacTemplate;
}