use of com.enonic.xp.web.WebException in project xp by enonic.
the class ServiceHandlerTest method testForbiddenService.
@Test
public void testForbiddenService() throws Exception {
final DescriptorKey serviceDescriptorKey = DescriptorKey.from("demo:test");
final Set<PrincipalKey> allowedPrincipals = Collections.singleton(PrincipalKey.from("role:system.admin"));
final ServiceDescriptor serviceDescriptor = ServiceDescriptor.create().key(serviceDescriptorKey).setAllowedPrincipals(allowedPrincipals).build();
Mockito.when(this.serviceDescriptorService.getByKey(serviceDescriptorKey)).thenReturn(serviceDescriptor);
this.request.setEndpointPath("/_/service/demo/test");
boolean forbiddenErrorThrown = false;
try {
this.handler.handle(this.request, PortalResponse.create().build(), null);
} catch (WebException e) {
if (HttpStatus.UNAUTHORIZED == e.getStatus()) {
forbiddenErrorThrown = true;
}
}
assertTrue(forbiddenErrorThrown);
}
use of com.enonic.xp.web.WebException in project xp by enonic.
the class ExceptionMapperImpl method throwIfNeeded.
@Override
public void throwIfNeeded(final WebResponse res) throws WebException {
final HttpStatus status = res.getStatus();
final Object body = res.getBody();
if (isError(status) && (body == null)) {
throw new WebException(status, status.getReasonPhrase());
}
}
Aggregations