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

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

Introduction

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

Prototype

String getUserAuthorizationURL();

Source Link

Document

The URL to which to redirect the user for authorization of access to the protected resource.

Usage

From source file:org.springframework.security.oauth.consumer.filter.OAuthConsumerContextFilter.java

/**
 * Get the URL to which to redirect the user for authorization of protected resources.
 *
 * @param details     The resource for which to get the authorization url.
 * @param requestToken The request token.
 * @param callbackURL  The callback URL.
 * @return The URL./*from   www  .  jav  a2 s  . co  m*/
 */
protected String getUserAuthorizationRedirectURL(ProtectedResourceDetails details,
        OAuthConsumerToken requestToken, String callbackURL) {
    try {
        String baseURL = details.getUserAuthorizationURL();
        StringBuilder builder = new StringBuilder(baseURL);
        char appendChar = baseURL.indexOf('?') < 0 ? '?' : '&';
        builder.append(appendChar).append("oauth_token=");
        builder.append(URLEncoder.encode(requestToken.getValue(), "UTF-8"));
        if (!details.isUse10a()) {
            builder.append('&').append("oauth_callback=");
            builder.append(URLEncoder.encode(callbackURL, "UTF-8"));
        }
        return builder.toString();
    } catch (UnsupportedEncodingException e) {
        throw new IllegalStateException(e);
    }
}

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

/**
 * Get the URL to which to redirect the user for authorization of protected resources.
 *
 * @param requestToken The request token.
 * @param callbackURL  The callback URL.
 * @return The URL.//from   www.ja v a  2  s . c  o m
 */
protected String getUserAuthorizationRedirectURL(OAuthConsumerToken requestToken, String callbackURL) {
    ProtectedResourceDetails details = getProtectedResourceDetailsService()
            .loadProtectedResourceDetailsById(requestToken.getResourceId());
    try {
        String baseURL = details.getUserAuthorizationURL();
        StringBuilder builder = new StringBuilder(baseURL);
        char appendChar = baseURL.indexOf('?') < 0 ? '?' : '&';
        builder.append(appendChar).append("oauth_token=");
        builder.append(URLEncoder.encode(requestToken.getValue(), "UTF-8"));
        if (!details.isUse10a()) {
            builder.append('&').append("oauth_callback=");
            builder.append(URLEncoder.encode(callbackURL, "UTF-8"));
        }
        return builder.toString();
    } catch (UnsupportedEncodingException e) {
        throw new IllegalStateException(e);
    }
}