@Override public boolean saveAccessToken(OAuth2Urls urls, OAuth2AppInfo info, OAuth2KeyUser key) { OAuthParams makeRequest = HttpAuthUtils.buildAuthenticated(info, urls, key); AccessKeyForUser access = HttpAuthUtils.obtainAccessCookie(makeRequest, info.getService()); if (access == null) return false; else { return accessKeyManager.saveE(access); } }
public boolean processRedirect( HttpServletRequest request, HttpServletResponse response, String token, String error, String errorMessage, String oauth1Token, String oauthVerifier, com.ccc.oauth.apimanagement.model.Service s, String userName) { if (log.isDebugEnabled()) { log.debug( "Code {} token {} error {} error descriptor {} error message {} oauthtoken {} oauthverifer {} ", new Object[] {token, token, error, errorMessage, oauth1Token, oauthVerifier}); } if (error != null && errorMessage != null) { log.warn( "Error found when retrieving code: " + " Error type: " + error + " and message: " + errorMessage); } OAuth2KeyUser key = null; List<AuthSupports> supported = supportedAuthForService(s); for (AuthSupports supports : supported) { if (supports.getAuthType().getName().equals(HttpAuthUtils.OAUTH2)) { key = new OAuth2KeyUser(); key.setUserName(userName); key.setService(s); key.setTimeMade(new Timestamp(System.currentTimeMillis())); key.setCode(token); if (log.isDebugEnabled()) { log.debug("Added new key for: " + userName + " and service: " + s.getName()); } Assert.isTrue(addKeyForUser(key)); AccessKeyForUser accessKey = HttpAuthUtils.requestAccessWithLookup(this, userName, s.getId()); if (log.isDebugEnabled()) { log.debug( "Requested to find access key: " + accessKey == null ? " not found: " : accessKey.getAccessCode()); } if (accessKey == null) { log.warn("Failed to retrieve access key"); return false; } Assert.isTrue(addKeyForUser(accessKey), "Couldn't add key for user: "******"Attempting oauth authorization"); } String toSave = null; // 1.0a compliance if (oauthVerifier != null && oauth1Token != null) toSave = oauthVerifier; else if (oauthVerifier != null) toSave = oauthVerifier; else if (oauth1Token != null) toSave = oauth1Token; if (toSave != null) { requestToken.setRequestToken(toSave); } else { if (log.isDebugEnabled()) { log.debug( "Attempted to save oauth 1 token for service: {} but couldn't find token passed in for user {}", s.getName(), userName); } } if (log.isDebugEnabled()) { log.debug("Found request token: " + toSave); } updateRequestToken(requestToken); } OAuth1Info oauth1Info = oauthInfoForService(s); try { String accessToken = HttpAuthUtils.getAccessTokenFromPin(oauth1Info, this, requestToken); if (accessToken == null) log.warn("Error retrieving access token for {}", s.getName()); log.info("Access token: " + accessToken); } catch (OAuthMessageSignerException e) { log.error("Error oauth1 token: ", e); return false; } catch (OAuthNotAuthorizedException e) { log.error("Error oauth1 token: ", e); return false; } catch (OAuthExpectationFailedException e) { log.error("Error oauth1 token: ", e); return false; } catch (OAuthCommunicationException e) { log.error("Error oauth1 token: ", e); return false; } } } return true; }