private OAuthParamLocation getStoreLocation(Location location, OAuthResponseParams responseParams) throws OAuthRequestException { switch(location) { case HEADER: return OAuthParamLocation.AUTH_HEADER; case URL: return OAuthParamLocation.URI_QUERY; case BODY: return OAuthParamLocation.POST_BODY; } throw new OAuthRequestException(OAuthError.UNKNOWN_PARAMETER_LOCATION); }
private String getDetails(Throwable e) { String error = null; if (null != e) { if(e instanceof OAuthRequestException) { OAuthRequestException reqException = ((OAuthRequestException) e); error = reqException.getError() + ", " + reqException.getErrorText(); } else { error = e.getMessage(); } } return "OAuth error [" + error + "] for application " + securityToken.getAppUrl() + ". Request trace:" + getRequestTrace(); }
@Test public void testGetOAuthAccessor_useToken_noOAuthInSpec() throws Exception { OAuthArguments arguments = new OAuthArguments(); arguments.setUseToken(UseToken.IF_AVAILABLE); try { store.getOAuthAccessor(socialToken, arguments, clientState, responseParams, fetcherConfig); fail(); } catch (OAuthRequestException e) { assertEquals("BAD_OAUTH_CONFIGURATION", e.getError()); } }
@Test public void testException() { HttpRequest req = new HttpRequest(Uri.parse("http://www")); HttpResponse ok = new HttpResponseBuilder().setHttpStatusCode(200).create(); params.addRequestTrace(req, ok); OAuthRequestException e = new OAuthRequestException("error", "errorText"); checkStringContains(e.toString(), "[error,errorText]"); params.addRequestTrace(null, null); Throwable cause = new RuntimeException(); e = new OAuthRequestException(OAuthError.UNAUTHENTICATED, "errorText", cause); checkStringContains(e.toString(), "[UNAUTHENTICATED,Unauthenticated OAuth fetch]"); assertEquals(cause, e.getCause()); }
@Test public void testGetOAuthAccessor_useToken_noOAuthInSpec() throws Exception { OAuthArguments arguments = new OAuthArguments(); arguments.setUseToken(UseToken.IF_AVAILABLE); try { store.getOAuthAccessor(socialToken, arguments, clientState, responseParams, fetcherConfig); fail(); } catch (OAuthRequestException e) { assertEquals("BAD_OAUTH_CONFIGURATION", e.getError()); } }
@Test public void testException() { HttpRequest req = new HttpRequest(Uri.parse("http://www")); HttpResponse ok = new HttpResponseBuilder().setHttpStatusCode(200).create(); params.addRequestTrace(req, ok); OAuthRequestException e = new OAuthRequestException("error", "errorText"); checkStringContains(e.toString(), "[error,errorText]"); params.addRequestTrace(null, null); Throwable cause = new RuntimeException(); e = new OAuthRequestException(OAuthError.UNAUTHENTICATED, "errorText", cause); checkStringContains(e.toString(), "[UNAUTHENTICATED,Unauthenticated OAuth fetch]"); assertEquals(cause, e.getCause()); }
private OAuthParamLocation getStoreLocation(Location location, OAuthResponseParams responseParams) throws OAuthRequestException { switch(location) { case HEADER: return OAuthParamLocation.AUTH_HEADER; case URL: return OAuthParamLocation.URI_QUERY; case BODY: return OAuthParamLocation.POST_BODY; } throw new OAuthRequestException(OAuthError.UNKNOWN_PARAMETER_LOCATION); }
@Test public void testGetOAuthAccessor_useToken_noOAuthInSpec() throws Exception { OAuthArguments arguments = new OAuthArguments(); arguments.setUseToken(UseToken.IF_AVAILABLE); try { store.getOAuthAccessor(socialToken, arguments, clientState, responseParams, fetcherConfig); fail(); } catch (OAuthRequestException e) { assertEquals("BAD_OAUTH_CONFIGURATION", e.getError()); } }
private String getDetails(Throwable e) { String error = null; if (null != e) { if(e instanceof OAuthRequestException) { OAuthRequestException reqException = ((OAuthRequestException) e); error = reqException.getError() + ", " + reqException.getErrorText(); } else { error = e.getMessage(); } } return "OAuth error [" + error + "] for application " + securityToken.getAppUrl() + ". Request trace:" + getRequestTrace(); }
@Test public void testException() { HttpRequest req = new HttpRequest(Uri.parse("http://www")); HttpResponse ok = new HttpResponseBuilder().setHttpStatusCode(200).create(); params.addRequestTrace(req, ok); OAuthRequestException e = new OAuthRequestException("error", "errorText"); checkStringContains(e.toString(), "[error,errorText]"); params.addRequestTrace(null, null); Throwable cause = new RuntimeException(); e = new OAuthRequestException(OAuthError.UNAUTHENTICATED, "errorText", cause); checkStringContains(e.toString(), "[UNAUTHENTICATED,Unauthenticated OAuth fetch]"); assertEquals(cause, e.getCause()); }
private OAuthParamLocation getStoreLocation(Location location, OAuthResponseParams responseParams) throws OAuthRequestException { switch(location) { case HEADER: return OAuthParamLocation.AUTH_HEADER; case URL: return OAuthParamLocation.URI_QUERY; case BODY: return OAuthParamLocation.POST_BODY; } throw new OAuthRequestException(OAuthError.UNKNOWN_PARAMETER_LOCATION); }
} catch (OAuthRequestException e) { if (OAuthError.UNAUTHENTICATED.name().equals(e.getError())) { responseParams.logDetailedInfo("Unauthenticated OAuth fetch", e); } else if (OAuthError.BAD_OAUTH_TOKEN_URL.name().equals(e.getError())) { responseParams.logDetailedInfo("Invalid OAuth fetch request", e); } else {
private String getDetails(Throwable e) { String error = null; if (null != e) { if(e instanceof OAuthRequestException) { OAuthRequestException reqException = ((OAuthRequestException) e); error = reqException.getError() + ", " + reqException.getErrorText(); } else { error = e.getMessage(); } } return "OAuth error [" + error + "] for application " + securityToken.getAppUrl() + ". Request trace:" + getRequestTrace(); }
private HttpMethod getStoreMethod(Method method, OAuthResponseParams responseParams) throws OAuthRequestException { switch(method) { case GET: return HttpMethod.GET; case POST: return HttpMethod.POST; } throw new OAuthRequestException(OAuthError.UNSUPPORTED_HTTP_METHOD, method.toString()); }
} catch (OAuthRequestException e) { if (OAuthError.UNAUTHENTICATED.name().equals(e.getError())) { responseParams.logDetailedInfo(classname,"fetchNoThrow",MessageKeys.UNAUTHENTICATED_OAUTH, e); } else if (OAuthError.BAD_OAUTH_TOKEN_URL.name().equals(e.getError())) { responseParams.logDetailedInfo(classname,"fetchNoThrow",MessageKeys.INVALID_OAUTH, e); } else {
/** * Update a response with additional data to be returned to the application. */ public void addToResponse(HttpResponseBuilder response, OAuthRequestException e) { if (!newClientState.isEmpty()) { try { response.setMetadata(CLIENT_STATE, newClientState.getEncryptedState()); } catch (BlobCrypterException cryptException) { // Configuration error somewhere, this should never happen. throw new RuntimeException(cryptException); } } if (aznUrl != null) { response.setMetadata(APPROVAL_URL, aznUrl); } if (e != null || sendTraceToClient) { StringBuilder verboseError = new StringBuilder(); if (e != null) { response.setMetadata(ERROR_CODE, e.getError()); verboseError.append(e.getErrorText()); } if (sendTraceToClient) { verboseError.append('\n'); verboseError.append(getRequestTrace()); } response.setMetadata(ERROR_TEXT, verboseError.toString()); } }
private HttpMethod getStoreMethod(Method method, OAuthResponseParams responseParams) throws OAuthRequestException { switch(method) { case GET: return HttpMethod.GET; case POST: return HttpMethod.POST; } throw new OAuthRequestException(OAuthError.UNSUPPORTED_HTTP_METHOD, method.toString()); }
} catch (OAuthRequestException e) { if (OAuthError.UNAUTHENTICATED.name().equals(e.getError())) { responseParams.logDetailedInfo("Unauthenticated OAuth fetch", e); } else if (OAuthError.BAD_OAUTH_TOKEN_URL.name().equals(e.getError())) { responseParams.logDetailedInfo("Invalid OAuth fetch request", e); } else {
/** * Update a response with additional data to be returned to the application. */ public void addToResponse(HttpResponseBuilder response, OAuthRequestException e) { if (!newClientState.isEmpty()) { try { response.setMetadata(CLIENT_STATE, newClientState.getEncryptedState()); } catch (BlobCrypterException cryptException) { // Configuration error somewhere, this should never happen. throw new RuntimeException(cryptException); } } if (aznUrl != null) { response.setMetadata(APPROVAL_URL, aznUrl); } if (e != null || sendTraceToClient) { StringBuilder verboseError = new StringBuilder(); if (e != null) { response.setMetadata(ERROR_CODE, e.getError()); verboseError.append(e.getErrorText()); } if (sendTraceToClient) { verboseError.append('\n'); verboseError.append(getRequestTrace()); } response.setMetadata(ERROR_TEXT, verboseError.toString()); } }
private HttpMethod getStoreMethod(Method method, OAuthResponseParams responseParams) throws OAuthRequestException { switch(method) { case GET: return HttpMethod.GET; case POST: return HttpMethod.POST; } throw new OAuthRequestException(OAuthError.UNSUPPORTED_HTTP_METHOD, method.toString()); }