public void setError(OAuth2Error error) { this.params.put(OAuth2Message.ERROR, error.getErrorCode()); }
/** * Create an exception and record information about the exception to be returned to the gadget. * * @param error * {@link OAuth2Error} for this error * @param errorText * String to help elaborate on the cause of this error * @param cause * {@link Throwable} optional root cause of the error * @param errorUri * optional errorUri from the OAuth2 spec * @param errorDescription * optionally provide more details about the error */ public OAuth2RequestException(final OAuth2Error error, final String errorText, final Throwable cause, final String errorUri, final String errorDescription) { super('[' + error.name() + ',' + String.format(error.toString(), errorText) + ']', cause); this.error = error; this.errorText = error.getErrorDescription(errorText); this.errorUri = errorUri; this.errorDescription = errorDescription; }
errorResponse = String.format(OAuth2CallbackServlet.RESP_ERROR_BODY, error.getErrorCode(), error.getErrorDescription(description), uri); } else { errorResponse = String.format(OAuth2CallbackServlet.RESP_ERROR_BODY, error.getErrorCode(), "", "");
@Test public void testGetError1() throws Exception { final OAuth2HandlerError fixture = new OAuth2HandlerError(OAuth2Error.AUTHENTICATION_PROBLEM, "", new Exception()); final OAuth2Error result = fixture.getError(); Assert.assertNotNull(result); Assert.assertEquals("authentication_problem", result.getErrorCode()); Assert.assertEquals("AUTHENTICATION_PROBLEM", result.name()); Assert.assertEquals(2, result.ordinal()); Assert.assertEquals("AUTHENTICATION_PROBLEM", result.toString()); }
private HttpResponseBuilder getErrorResponseBuilder(final Throwable t, final OAuth2Error error, final String contextMessage, final String errorUri, final String errorDescription) { final boolean isLogging = BasicOAuth2Request.LOG.isLoggable(); if (isLogging) { BasicOAuth2Request.LOG.entering(BasicOAuth2Request.LOG_CLASS, "getErrorResponseBuilder", new Object[] { t, error, contextMessage, errorUri, errorDescription }); } final HttpResponseBuilder ret = new HttpResponseBuilder().setHttpStatusCode( HttpResponse.SC_FORBIDDEN).setStrictNoCache(); if (t != null && this.sendTraceToClient) { final StringWriter sw = new StringWriter(); t.printStackTrace(new PrintWriter(sw)); final String message = sw.toString(); this.responseParams.addDebug(message); } if (this.sendTraceToClient) { this.responseParams.addToResponse(ret, error.getErrorCode(), error.getErrorDescription(contextMessage) + " , " + errorDescription, errorUri, error.getErrorExplanation()); } else { this.responseParams.addToResponse(ret, error.getErrorCode(), "", "", error.getErrorExplanation()); } if (isLogging) { BasicOAuth2Request.LOG.exiting(BasicOAuth2Request.LOG_CLASS, "getErrorResponseBuilder", ret); } return ret; }
@Override public String toString() { return '[' + this.error.toString() + ',' + this.errorText + ']'; } }
@Test public void testGetError_1() throws Exception { final OAuth2RequestException fixture = new OAuth2RequestException( OAuth2Error.AUTHENTICATION_PROBLEM, "", new Throwable()); final OAuth2Error result = fixture.getError(); Assert.assertNotNull(result); Assert.assertEquals("authentication_problem", result.getErrorCode()); Assert.assertEquals("AUTHENTICATION_PROBLEM", result.name()); Assert.assertEquals(2, result.ordinal()); Assert.assertEquals("AUTHENTICATION_PROBLEM", result.toString()); }
@Test public void testGetError1() throws Exception { final OAuth2HandlerError fixture = new OAuth2HandlerError(OAuth2Error.AUTHENTICATION_PROBLEM, "", new Exception()); final OAuth2Error result = fixture.getError(); Assert.assertNotNull(result); Assert.assertEquals("authentication_problem", result.getErrorCode()); Assert.assertEquals("AUTHENTICATION_PROBLEM", result.name()); Assert.assertEquals(2, result.ordinal()); Assert.assertEquals("AUTHENTICATION_PROBLEM", result.toString()); }
@Test public void testGetErrorCode_1() throws Exception { final OAuth2Error fixture = OAuth2Error.AUTHENTICATION_PROBLEM; final String result = fixture.getErrorCode(); Assert.assertEquals("authentication_problem", result); }
@Test public void testGetError_1() throws Exception { final OAuth2RequestException fixture = new OAuth2RequestException( OAuth2Error.AUTHENTICATION_PROBLEM, "", new Throwable()); final OAuth2Error result = fixture.getError(); Assert.assertNotNull(result); Assert.assertEquals("authentication_problem", result.getErrorCode()); Assert.assertEquals("AUTHENTICATION_PROBLEM", result.name()); Assert.assertEquals(2, result.ordinal()); Assert.assertEquals("AUTHENTICATION_PROBLEM", result.toString()); }
@Test public void testGetErrorCode_1() throws Exception { final OAuth2Error fixture = OAuth2Error.AUTHENTICATION_PROBLEM; final String result = fixture.getErrorCode(); Assert.assertEquals("authentication_problem", result); }