List of usage examples for com.liferay.portal.kernel.oauth OAuthException OAuthException
public OAuthException(Throwable cause)
From source file:com.rivetlogic.evernote.util.EvernoteUtil.java
License:Open Source License
public static void authenticateEvernote(RenderRequest renderRequest, PortletSession portletSession, ThemeDisplay themeDisplay) throws OAuthException { HttpServletRequest request = PortalUtil.getHttpServletRequest(renderRequest); String authorizationUrl = StringPool.BLANK; try {/* ww w .ja v a2 s . c o m*/ OAuthService service = getOAuthService(request, themeDisplay); if (PortalUtil.getOriginalServletRequest(request).getParameter(OAUTH_VERIFIER) == null) { // Send an OAuth message to the Provider asking for a new Request // Token because we don't have access to the current user's account. Token scribeRequestToken = service.getRequestToken(); portletSession.setAttribute(REQUEST_TOKEN, scribeRequestToken.getToken()); portletSession.setAttribute(REQUEST_TOKEN_SECRET, scribeRequestToken.getSecret()); authorizationUrl = EVERNOTE_SERVICE.getAuthorizationUrl(scribeRequestToken.getToken()); } else { // Send an OAuth message to the Provider asking to exchange the // existing Request Token for an Access Token Token scribeRequestToken = new Token(portletSession.getAttribute(REQUEST_TOKEN).toString(), portletSession.getAttribute(REQUEST_TOKEN_SECRET).toString()); Verifier scribeVerifier = new Verifier( PortalUtil.getOriginalServletRequest(request).getParameter(OAUTH_VERIFIER)); Token scribeAccessToken = service.getAccessToken(scribeRequestToken, scribeVerifier); EvernoteAuth evernoteAuth = EvernoteAuth.parseOAuthResponse(EVERNOTE_SERVICE, scribeAccessToken.getRawResponse()); portletSession.setAttribute(ACCESS_TOKEN, evernoteAuth.getToken()); } } catch (Exception e) { throw new OAuthException(e); } renderRequest.setAttribute(AUTHORIZATION_URL, authorizationUrl); }