Example usage for org.springframework.security.oauth.consumer ProtectedResourceDetails getAdditionalParameters

List of usage examples for org.springframework.security.oauth.consumer ProtectedResourceDetails getAdditionalParameters

Introduction

In this page you can find the example usage for org.springframework.security.oauth.consumer ProtectedResourceDetails getAdditionalParameters.

Prototype

Map<String, String> getAdditionalParameters();

Source Link

Document

The additional OAuth parameters for this protected resource.

Usage

From source file:org.springframework.security.oauth.consumer.client.CoreOAuthConsumerSupport.java

public OAuthConsumerToken getUnauthorizedRequestToken(ProtectedResourceDetails details, String callback)
        throws OAuthRequestFailedException {
    URL requestTokenURL;//from ww  w .ja  v  a2s . c  om
    try {
        requestTokenURL = new URL(details.getRequestTokenURL());
    } catch (MalformedURLException e) {
        throw new IllegalStateException("Malformed URL for obtaining a request token.", e);
    }

    String httpMethod = details.getRequestTokenHttpMethod();

    Map<String, String> additionalParameters = new TreeMap<String, String>();
    if (details.isUse10a()) {
        additionalParameters.put(OAuthConsumerParameter.oauth_callback.toString(), callback);
    }
    Map<String, String> specifiedParams = details.getAdditionalParameters();
    if (specifiedParams != null) {
        additionalParameters.putAll(specifiedParams);
    }
    return getTokenFromProvider(details, requestTokenURL, httpMethod, null, additionalParameters);
}

From source file:org.springframework.security.oauth.consumer.client.CoreOAuthConsumerSupport.java

public OAuthConsumerToken getAccessToken(ProtectedResourceDetails details, OAuthConsumerToken requestToken,
        String verifier) {/*ww w.j a v  a  2s .  c o  m*/
    URL accessTokenURL;
    try {
        accessTokenURL = new URL(details.getAccessTokenURL());
    } catch (MalformedURLException e) {
        throw new IllegalStateException("Malformed URL for obtaining an access token.", e);
    }

    String httpMethod = details.getAccessTokenHttpMethod();

    Map<String, String> additionalParameters = new TreeMap<String, String>();
    if (details.isUse10a()) {
        if (verifier == null) {
            throw new UnverifiedRequestTokenException("Unverified request token: " + requestToken);
        }
        additionalParameters.put(OAuthConsumerParameter.oauth_verifier.toString(), verifier);
    }
    Map<String, String> specifiedParams = details.getAdditionalParameters();
    if (specifiedParams != null) {
        additionalParameters.putAll(specifiedParams);
    }
    return getTokenFromProvider(details, accessTokenURL, httpMethod, requestToken, additionalParameters);
}

From source file:org.springframework.security.oauth.consumer.client.CoreOAuthConsumerSupport.java

public InputStream readProtectedResource(URL url, OAuthConsumerToken accessToken, String httpMethod)
        throws OAuthRequestFailedException {
    if (accessToken == null) {
        throw new OAuthRequestFailedException("A valid access token must be supplied.");
    }/*from w ww. ja va  2s  .  c  o m*/

    ProtectedResourceDetails resourceDetails = getProtectedResourceDetailsService()
            .loadProtectedResourceDetailsById(accessToken.getResourceId());
    if ((!resourceDetails.isAcceptsAuthorizationHeader()) && !"POST".equalsIgnoreCase(httpMethod)
            && !"PUT".equalsIgnoreCase(httpMethod)) {
        throw new IllegalArgumentException("Protected resource " + resourceDetails.getId()
                + " cannot be accessed with HTTP method " + httpMethod
                + " because the OAuth provider doesn't accept the OAuth Authorization header.");
    }

    return readResource(resourceDetails, url, httpMethod, accessToken,
            resourceDetails.getAdditionalParameters(), null);
}

From source file:org.springframework.security.oauth.consumer.CoreOAuthConsumerSupport.java

public OAuthConsumerToken getUnauthorizedRequestToken(String resourceId, String callback)
        throws OAuthRequestFailedException {
    ProtectedResourceDetails details = getProtectedResourceDetailsService()
            .loadProtectedResourceDetailsById(resourceId);

    URL requestTokenURL;//w ww  .  ja v a  2 s  .c  om
    try {
        requestTokenURL = new URL(details.getRequestTokenURL());
    } catch (MalformedURLException e) {
        throw new IllegalStateException("Malformed URL for obtaining a request token.", e);
    }

    String httpMethod = details.getRequestTokenHttpMethod();

    Map<String, String> additionalParameters = new TreeMap<String, String>();
    if (details.isUse10a()) {
        additionalParameters.put(OAuthConsumerParameter.oauth_callback.toString(), callback);
    }
    Map<String, String> specifiedParams = details.getAdditionalParameters();
    if (specifiedParams != null) {
        additionalParameters.putAll(specifiedParams);
    }
    return getTokenFromProvider(details, requestTokenURL, httpMethod, null, additionalParameters);
}

From source file:org.springframework.security.oauth.consumer.CoreOAuthConsumerSupport.java

public OAuthConsumerToken getAccessToken(OAuthConsumerToken requestToken, String verifier)
        throws OAuthRequestFailedException {
    ProtectedResourceDetails details = getProtectedResourceDetailsService()
            .loadProtectedResourceDetailsById(requestToken.getResourceId());

    URL accessTokenURL;//w w w  .  j  a  v a  2s  .c  om
    try {
        accessTokenURL = new URL(details.getAccessTokenURL());
    } catch (MalformedURLException e) {
        throw new IllegalStateException("Malformed URL for obtaining an access token.", e);
    }

    String httpMethod = details.getAccessTokenHttpMethod();

    Map<String, String> additionalParameters = new TreeMap<String, String>();
    if (details.isUse10a()) {
        if (verifier == null) {
            throw new UnverifiedRequestTokenException("Unverified request token: " + requestToken.getValue());
        }
        additionalParameters.put(OAuthConsumerParameter.oauth_verifier.toString(), verifier);
    }
    Map<String, String> specifiedParams = details.getAdditionalParameters();
    if (specifiedParams != null) {
        additionalParameters.putAll(specifiedParams);
    }
    return getTokenFromProvider(details, accessTokenURL, httpMethod, requestToken, additionalParameters);
}