use of org.wso2.carbon.identity.application.authentication.framework.inbound.FrameworkClientException in project carbon-identity-framework by wso2.
the class SessionExtenderRequestFactory method handleException.
@Override
public HttpIdentityResponse.HttpIdentityResponseBuilder handleException(FrameworkClientException exception, HttpServletRequest request, HttpServletResponse response) {
HttpIdentityResponse.HttpIdentityResponseBuilder errorResponseBuilder = new HttpIdentityResponse.HttpIdentityResponseBuilder();
SessionExtenderErrorResponse.SessionExtenderErrorResponseBuilder sessionErrorResponseBuilder = new SessionExtenderErrorResponse.SessionExtenderErrorResponseBuilder();
sessionErrorResponseBuilder.setErrorCode(exception.getErrorCode());
String traceId = FrameworkUtils.getCorrelation();
String errorLogDescription;
if (exception instanceof SessionExtenderClientException) {
sessionErrorResponseBuilder.setErrorMessage(((SessionExtenderClientException) exception).getErrorMessage());
sessionErrorResponseBuilder.setErrorDescription(((SessionExtenderClientException) exception).getDescription());
sessionErrorResponseBuilder.setTraceId(traceId);
errorLogDescription = ((SessionExtenderClientException) exception).getDescription();
} else {
sessionErrorResponseBuilder.setErrorMessage(exception.getMessage());
errorLogDescription = exception.getMessage();
}
if (log.isDebugEnabled()) {
String clientErrorLog = String.format(ERROR_LOG_TEMPLATE, traceId, SessionExtenderRequestFactory.class.getName(), errorLogDescription);
log.debug(clientErrorLog);
}
SessionExtenderErrorResponse sessionExtenderErrorResponse = sessionErrorResponseBuilder.build();
errorResponseBuilder.setStatusCode(SC_BAD_REQUEST);
errorResponseBuilder.setContentType(APPLICATION_JSON);
errorResponseBuilder.setBody(sessionExtenderErrorResponse.getResponse());
return errorResponseBuilder;
}
use of org.wso2.carbon.identity.application.authentication.framework.inbound.FrameworkClientException in project carbon-identity-framework by wso2.
the class HttpIdentityRequestFactoryTest method testHandleFrameworkClientException.
@Test
public void testHandleFrameworkClientException() throws Exception {
FrameworkClientException clientException = new FrameworkClientException(ERROR_MESSAGE);
HttpIdentityResponseBuilder responseBuilder = httpIdentityRequestFactory.handleException(clientException, request, response);
assertEquals(responseBuilder.body, ERROR_MESSAGE);
assertEquals(responseBuilder.statusCode, 400);
}
use of org.wso2.carbon.identity.application.authentication.framework.inbound.FrameworkClientException in project identity-inbound-auth-oauth by wso2-extensions.
the class HttpUnRegistrationResponseFactoryTest method testHandleException.
@Test
public void testHandleException() throws Exception {
mockHttpIdentityResponseBuilder = mock(HttpIdentityResponse.HttpIdentityResponseBuilder.class);
whenNew(HttpIdentityResponse.HttpIdentityResponseBuilder.class).withNoArguments().thenReturn(mockHttpIdentityResponseBuilder);
final Integer[] statusCode = new Integer[1];
doAnswer(new Answer<Object>() {
@Override
public Object answer(InvocationOnMock invocation) throws Throwable {
statusCode[0] = (Integer) invocation.getArguments()[0];
return null;
}
}).when(mockHttpIdentityResponseBuilder).setStatusCode(anyInt());
final String[] header = new String[3];
doAnswer(new Answer<Object>() {
@Override
public Object answer(InvocationOnMock invocation) throws Throwable {
header[0] = (String) invocation.getArguments()[1];
return null;
}
}).when(mockHttpIdentityResponseBuilder).addHeader(eq(OAuthConstants.HTTP_RESP_HEADER_CACHE_CONTROL), anyString());
doAnswer(new Answer<Object>() {
@Override
public Object answer(InvocationOnMock invocation) throws Throwable {
header[1] = (String) invocation.getArguments()[1];
return null;
}
}).when(mockHttpIdentityResponseBuilder).addHeader(eq(OAuthConstants.HTTP_RESP_HEADER_PRAGMA), anyString());
FrameworkClientException exception = mock(FrameworkClientException.class);
when(exception.getMessage()).thenReturn("dummyDescription");
httpUnregistrationResponseFactory.handleException(exception);
assertEquals(header[0], OAuthConstants.HTTP_RESP_HEADER_VAL_CACHE_CONTROL_NO_STORE, "Wrong header value " + "for " + OAuthConstants.HTTP_RESP_HEADER_CACHE_CONTROL);
assertEquals(header[1], OAuthConstants.HTTP_RESP_HEADER_VAL_PRAGMA_NO_CACHE, "Wrong header value for " + OAuthConstants.HTTP_RESP_HEADER_PRAGMA);
assertEquals((int) statusCode[0], HttpServletResponse.SC_METHOD_NOT_ALLOWED, "Status code doesn't match with " + HttpServletResponse.SC_BAD_REQUEST);
}
use of org.wso2.carbon.identity.application.authentication.framework.inbound.FrameworkClientException in project identity-inbound-auth-oauth by wso2-extensions.
the class RegistrationRequestFactoryTest method testHandleException.
@Test
public void testHandleException() throws Exception {
whenNew(HttpIdentityResponse.HttpIdentityResponseBuilder.class).withNoArguments().thenReturn(mockHttpIdentityResponseBuilder);
final Integer[] statusCode = new Integer[1];
doAnswer(new Answer<Object>() {
@Override
public Object answer(InvocationOnMock invocation) throws Throwable {
statusCode[0] = (Integer) invocation.getArguments()[0];
return null;
}
}).when(mockHttpIdentityResponseBuilder).setStatusCode(anyInt());
final String[] header = new String[3];
doAnswer(new Answer<Object>() {
@Override
public Object answer(InvocationOnMock invocation) throws Throwable {
header[0] = (String) invocation.getArguments()[1];
return null;
}
}).when(mockHttpIdentityResponseBuilder).addHeader(eq(OAuthConstants.HTTP_RESP_HEADER_CACHE_CONTROL), anyString());
doAnswer(new Answer<Object>() {
@Override
public Object answer(InvocationOnMock invocation) throws Throwable {
header[1] = (String) invocation.getArguments()[1];
return null;
}
}).when(mockHttpIdentityResponseBuilder).addHeader(eq(OAuthConstants.HTTP_RESP_HEADER_PRAGMA), anyString());
doAnswer(new Answer<Object>() {
@Override
public Object answer(InvocationOnMock invocation) throws Throwable {
header[2] = (String) invocation.getArguments()[1];
return null;
}
}).when(mockHttpIdentityResponseBuilder).addHeader(eq(HttpHeaders.CONTENT_TYPE), anyString());
FrameworkClientException exception = mock(FrameworkClientException.class);
when(exception.getMessage()).thenReturn(dummyDescription);
registrationRequestFactory.handleException(exception, mockHttpRequest, mockHttpResponse);
assertEquals(header[0], OAuthConstants.HTTP_RESP_HEADER_VAL_CACHE_CONTROL_NO_STORE, "Wrong header value " + "for " + OAuthConstants.HTTP_RESP_HEADER_CACHE_CONTROL);
assertEquals(header[1], OAuthConstants.HTTP_RESP_HEADER_VAL_PRAGMA_NO_CACHE, "Wrong header value for " + OAuthConstants.HTTP_RESP_HEADER_PRAGMA);
assertEquals(header[2], MediaType.APPLICATION_JSON, "Wrong header value for " + HttpHeaders.CONTENT_TYPE);
assertEquals((int) statusCode[0], HttpServletResponse.SC_BAD_REQUEST, "Status code doesn't match with " + HttpServletResponse.SC_BAD_REQUEST);
}
use of org.wso2.carbon.identity.application.authentication.framework.inbound.FrameworkClientException in project identity-inbound-auth-oauth by wso2-extensions.
the class DCRProcessorTest method getInstanceType.
@DataProvider(name = "instanceTypeprovider")
public Object[][] getInstanceType() throws FrameworkClientException {
RegistrationRequest registrationRequest = mock(RegistrationRequest.class);
UnregistrationRequest unregistrationRequest = mock(UnregistrationRequest.class);
return new Object[][] { { "RegistrationRequest", registrationRequest }, { "UnregistrationRequest", unregistrationRequest } };
}
Aggregations