Search in sources :

Example 1 with AccessDeniedExceptionMapper

use of io.crnk.spring.internal.AccessDeniedExceptionMapper in project crnk-framework by crnk-project.

the class SpringSecurityExceptionMapperTest method testAccessDenied.

@Test
public void testAccessDenied() {
    AccessDeniedExceptionMapper mapper = new AccessDeniedExceptionMapper();
    AccessDeniedException exception = new AccessDeniedException("hi");
    ErrorResponse response = mapper.toErrorResponse(exception);
    Iterable<ErrorData> errors = response.getErrors();
    Iterator<ErrorData> iterator = errors.iterator();
    ErrorData data = iterator.next();
    Assert.assertFalse(iterator.hasNext());
    Assert.assertEquals("403", data.getStatus());
    Assert.assertEquals("hi", data.getCode());
    Assert.assertTrue(mapper.accepts(response));
    AccessDeniedException fromErrorResponse = mapper.fromErrorResponse(response);
    Assert.assertEquals("hi", fromErrorResponse.getMessage());
}
Also used : AccessDeniedException(org.springframework.security.access.AccessDeniedException) ErrorData(io.crnk.core.engine.document.ErrorData) AccessDeniedExceptionMapper(io.crnk.spring.internal.AccessDeniedExceptionMapper) ErrorResponse(io.crnk.core.engine.error.ErrorResponse) Test(org.junit.Test)

Aggregations

ErrorData (io.crnk.core.engine.document.ErrorData)1 ErrorResponse (io.crnk.core.engine.error.ErrorResponse)1 AccessDeniedExceptionMapper (io.crnk.spring.internal.AccessDeniedExceptionMapper)1 Test (org.junit.Test)1 AccessDeniedException (org.springframework.security.access.AccessDeniedException)1