use of net.oauth.OAuthAccessor in project zm-mailbox by Zimbra.
the class OAuthAuthorizationServlet method doGet.
@Override
public void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException {
LOG.debug("Authorization Handler doGet requested!");
try {
OAuthMessage oAuthMessage = OAuthServlet.getMessage(request, null);
OAuthAccessor accessor = OAuthServiceProvider.getAccessor(oAuthMessage);
if (Boolean.TRUE.equals(accessor.getProperty("authorized"))) {
// already authorized send the user back
returnToConsumer(request, response, accessor);
} else {
sendToAuthorizePage(request, response, accessor);
}
} catch (Exception e) {
OAuthServiceProvider.handleException(e, request, response, true);
}
}
use of net.oauth.OAuthAccessor in project zm-mailbox by Zimbra.
the class OAuthTokenCache method get.
public static OAuthAccessor get(String consumer_token, String token_type) throws ServiceException {
String key_prefix = null;
if (token_type == OAuthTokenCache.ACCESS_TOKEN_TYPE) {
key_prefix = OAuthTokenCacheKey.ACCESS_TOKEN_PREFIX;
} else if (token_type == OAuthTokenCache.REQUEST_TOKEN_TYPE) {
key_prefix = OAuthTokenCacheKey.REQUEST_TOKEN_PREFIX;
}
OAuthTokenCacheKey key = new OAuthTokenCacheKey(consumer_token, key_prefix);
LOG.debug("get type: " + token_type + " token from memcache with key: " + key.getKeyPrefix() + key.getKeyValue() + ".");
OAuthAccessor cache = sTheInstance.get(key);
if (cache != null) {
if (token_type == OAuthTokenCache.ACCESS_TOKEN_TYPE) {
cache.accessToken = consumer_token;
cache.requestToken = null;
} else {
cache.requestToken = consumer_token;
cache.accessToken = null;
}
}
return cache;
}
use of net.oauth.OAuthAccessor in project cxf by apache.
the class TokenRequestController method handleRequest.
@RequestMapping("/tokenRequest")
protected ModelAndView handleRequest(@ModelAttribute("oAuthParams") OAuthParams oAuthParams, HttpServletRequest request) throws Exception {
String oauthToken = oAuthParams.getOauthToken();
String tokenRequestEndpoint = oAuthParams.getTokenRequestEndpoint();
String clientID = oAuthParams.getClientID();
if (tokenRequestEndpoint == null || "".equals(tokenRequestEndpoint)) {
oAuthParams.setErrorMessage("Missing token request URI");
}
if (clientID == null || "".equals(clientID)) {
oAuthParams.setErrorMessage("Missing consumer key");
}
if (oauthToken == null || "".equals(oauthToken)) {
oAuthParams.setErrorMessage("Missing oauth token");
}
String verifier = oAuthParams.getOauthVerifier();
if (verifier == null || "".equals(verifier)) {
oAuthParams.setErrorMessage("Missing oauth verifier");
}
if (oAuthParams.getErrorMessage() == null) {
OAuthClient client = new OAuthClient(new URLConnectionClient());
OAuthServiceProvider provider = new OAuthServiceProvider(oAuthParams.getTemporaryCredentialsEndpoint(), oAuthParams.getResourceOwnerAuthorizationEndpoint(), tokenRequestEndpoint);
OAuthConsumer consumer = new OAuthConsumer(null, clientID, oAuthParams.getClientSecret(), provider);
OAuthAccessor accessor = new OAuthAccessor(consumer);
accessor.requestToken = oauthToken;
accessor.tokenSecret = Common.findCookieValue(request, "tokenSec");
Map<String, String> parameters = new HashMap<>();
parameters.put(OAuth.OAUTH_SIGNATURE_METHOD, oAuthParams.getSignatureMethod());
parameters.put(OAuth.OAUTH_NONCE, UUID.randomUUID().toString());
parameters.put(OAuth.OAUTH_TIMESTAMP, String.valueOf(System.currentTimeMillis() / 1000));
parameters.put(OAuth.OAUTH_TOKEN, oauthToken);
parameters.put(OAuth.OAUTH_VERIFIER, oAuthParams.getOauthVerifier());
try {
client.getAccessToken(accessor, OAuthMessage.GET, parameters.entrySet());
oAuthParams.setOauthToken(accessor.accessToken);
} catch (Exception e) {
oAuthParams.setErrorMessage(e.toString());
oAuthParams.setOauthToken(oauthToken);
return new ModelAndView("tokenRequest");
}
oAuthParams.setOauthTokenSecret(accessor.tokenSecret);
}
oAuthParams.setClientID(Common.findCookieValue(request, "clientID"));
oAuthParams.setClientSecret(Common.findCookieValue(request, "clientSecret"));
return new ModelAndView("accessToken");
}
use of net.oauth.OAuthAccessor in project cxf by apache.
the class OAuthClientUtils method getAccessToken.
public static Token getAccessToken(WebClient accessTokenService, Consumer consumer, Token requestToken, String verifier, Map<String, Object> oauthConsumerProps) throws OAuthServiceException {
Map<String, String> parameters = new HashMap<>();
parameters.put(OAuth.OAUTH_CONSUMER_KEY, consumer.getKey());
parameters.put(OAuth.OAUTH_TOKEN, requestToken.getToken());
parameters.put(OAuth.OAUTH_VERIFIER, verifier);
if (oauthConsumerProps == null || !oauthConsumerProps.containsKey(OAuth.OAUTH_SIGNATURE_METHOD)) {
parameters.put(OAuth.OAUTH_SIGNATURE_METHOD, OAuth.HMAC_SHA1);
}
OAuthAccessor accessor = createAccessor(consumer, oauthConsumerProps);
accessor.requestToken = requestToken.getToken();
accessor.tokenSecret = requestToken.getSecret();
return getToken(accessTokenService, accessor, parameters);
}
use of net.oauth.OAuthAccessor in project cxf by apache.
the class OAuthClientUtils method createAuthorizationHeader.
public static String createAuthorizationHeader(Consumer consumer, Token accessToken, String method, String requestURI, Map<String, Object> oauthConsumerProps) {
Map<String, String> parameters = new HashMap<>();
parameters.put(OAuth.OAUTH_CONSUMER_KEY, consumer.getKey());
if (accessToken != null) {
parameters.put(OAuth.OAUTH_TOKEN, accessToken.getToken());
}
if (oauthConsumerProps == null || !oauthConsumerProps.containsKey(OAuth.OAUTH_SIGNATURE_METHOD)) {
parameters.put(OAuth.OAUTH_SIGNATURE_METHOD, OAuth.HMAC_SHA1);
}
parameters.put(OAuth.OAUTH_NONCE, UUID.randomUUID().toString());
parameters.put(OAuth.OAUTH_TIMESTAMP, String.valueOf(System.currentTimeMillis() / 1000));
OAuthAccessor accessor = createAccessor(consumer, oauthConsumerProps);
if (accessToken != null) {
accessor.accessToken = accessToken.getToken();
accessor.tokenSecret = accessToken.getSecret();
}
return doGetAuthorizationHeader(accessor, method, requestURI, parameters);
}
Aggregations