Example usage for org.springframework.security.oauth2.client.resource BaseOAuth2ProtectedResourceDetails setClientId

List of usage examples for org.springframework.security.oauth2.client.resource BaseOAuth2ProtectedResourceDetails setClientId

Introduction

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

Prototype

public void setClientId(String clientId) 

Source Link

Usage

From source file:ltistarter.oauth.OAuthUtils.java

public static ResponseEntity sendOAuth2Request(String url, String clientId, String clientSecret,
        String accessTokenURI, Map<String, String> params) {
    assert url != null;
    assert clientId != null;
    assert clientSecret != null;
    AuthorizationCodeAccessTokenProvider provider = new AuthorizationCodeAccessTokenProvider();
    BaseOAuth2ProtectedResourceDetails resource = new BaseOAuth2ProtectedResourceDetails();
    resource.setClientAuthenticationScheme(AuthenticationScheme.form);
    resource.setClientId(clientId);
    resource.setClientSecret(clientSecret);
    resource.setAccessTokenUri(accessTokenURI);
    resource.setGrantType("access");
    OAuth2AccessToken accessToken = provider.obtainAccessToken(resource, new DefaultAccessTokenRequest());
    OAuth2RestTemplate restTemplate = new OAuth2RestTemplate(resource,
            new DefaultOAuth2ClientContext(accessToken));
    ResponseEntity<String> response = restTemplate.postForEntity(url, params, String.class,
            (Map<String, ?>) null);
    return response;
}

From source file:com.feedeo.rest.client.AbstractOAuth2RestClient.java

public void setClientId(String clientId) {
    OAuth2RestTemplate restOperations = (OAuth2RestTemplate) getRestOperations();
    BaseOAuth2ProtectedResourceDetails resource = (BaseOAuth2ProtectedResourceDetails) restOperations
            .getResource();/*from   w w  w.jav a2  s .  c o  m*/
    resource.setClientId(clientId);
}

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

/**
 * Sets the client_id and client_secret on the resource details object
 * @param tokenRequest the token request containing the client_id and client_secret
 * @param details the details object that. will be configured
 *///from  w  w w  .j av  a2  s .co m
protected void setClientCredentials(TokenRequest tokenRequest, BaseOAuth2ProtectedResourceDetails details) {
    details.setClientId(tokenRequest.getClientId());
    details.setClientSecret(tokenRequest.getClientSecret());
}

From source file:org.springframework.boot.autoconfigure.security.oauth2.resource.UserInfoTokenServices.java

@SuppressWarnings({ "unchecked" })
private Map<String, Object> getMap(String path, String accessToken) {
    this.logger.info("Getting user info from: " + path);
    try {// w  ww . j  a v a2  s  .  c om
        OAuth2RestOperations restTemplate = this.restTemplate;
        if (restTemplate == null) {
            BaseOAuth2ProtectedResourceDetails resource = new BaseOAuth2ProtectedResourceDetails();
            resource.setClientId(this.clientId);
            restTemplate = new OAuth2RestTemplate(resource);
        }
        DefaultOAuth2AccessToken token = new DefaultOAuth2AccessToken(accessToken);
        token.setTokenType(this.tokenType);
        restTemplate.getOAuth2ClientContext().setAccessToken(token);
        return restTemplate.getForEntity(path, Map.class).getBody();
    } catch (Exception ex) {
        this.logger.info("Could not fetch user details: " + ex.getClass() + ", " + ex.getMessage());
        return Collections.<String, Object>singletonMap("error", "Could not fetch user details");
    }
}

From source file:org.springframework.cloud.security.oauth2.resource.UserInfoTokenServices.java

private Map<String, Object> getMap(String path, String accessToken) {
    logger.info("Getting user info from: " + path);
    OAuth2RestOperations restTemplate = this.restTemplate;
    if (restTemplate == null) {
        BaseOAuth2ProtectedResourceDetails resource = new BaseOAuth2ProtectedResourceDetails();
        resource.setClientId(clientId);
        restTemplate = new OAuth2RestTemplate(resource);
    }//from w w w .j ava  2s  .  c om
    restTemplate.getOAuth2ClientContext().setAccessToken(new DefaultOAuth2AccessToken(accessToken));
    @SuppressWarnings("rawtypes")
    Map map = restTemplate.getForEntity(path, Map.class).getBody();
    @SuppressWarnings("unchecked")
    Map<String, Object> result = map;
    return result;
}

From source file:org.springframework.cloud.security.oauth2.UserInfoTokenServices.java

private Map<String, Object> getMap(String path, String accessToken) {
    logger.info("Getting user info from: " + path);
    BaseOAuth2ProtectedResourceDetails resource = new BaseOAuth2ProtectedResourceDetails();
    resource.setClientId(clientId);
    OAuth2RestTemplate restTemplate = new OAuth2RestTemplate(resource);
    restTemplate.getOAuth2ClientContext().setAccessToken(new DefaultOAuth2AccessToken(accessToken));
    @SuppressWarnings("rawtypes")
    Map map = restTemplate.getForEntity(path, Map.class).getBody();
    @SuppressWarnings("unchecked")
    Map<String, Object> result = map;
    return result;
}

From source file:ua.com.skywell.oauth.custom.UserInfoTokenServices.java

@SuppressWarnings({ "unchecked" })
private Map<String, Object> getMap(String path, String accessToken) {
    this.logger.info("Getting user info from: " + path);
    try {/*from   w  w w  .java2 s.c o  m*/
        OAuth2RestOperations restTemplate = this.restTemplate;
        if (restTemplate == null) {
            BaseOAuth2ProtectedResourceDetails resource = new BaseOAuth2ProtectedResourceDetails();
            resource.setClientId(this.clientId);
            restTemplate = new OAuth2RestTemplate(resource);
        }
        OAuth2AccessToken existingToken = restTemplate.getOAuth2ClientContext().getAccessToken();
        if (existingToken == null || !accessToken.equals(existingToken.getValue())) {
            DefaultOAuth2AccessToken token = new DefaultOAuth2AccessToken(accessToken);
            token.setTokenType(this.tokenType);
            restTemplate.getOAuth2ClientContext().setAccessToken(token);
        }
        return restTemplate.getForEntity(path, Map.class).getBody();
    } catch (Exception ex) {
        this.logger.info("Could not fetch user details: " + ex.getClass() + ", " + ex.getMessage());
        return Collections.<String, Object>singletonMap("error", "Could not fetch user details");
    }
}