use of org.jboss.resteasy.core.interception.jaxrs.ResponseContainerRequestContext in project platform by dashjoin.
the class ACLContainerRequestFilterTest method testFilter.
/**
* make sure GET throws 401 unauthorized
*/
@Test
public void testFilter() throws Exception {
Assertions.assertThrows(NotAuthorizedException.class, () -> {
ACLContainerRequestFilter f = new ACLContainerRequestFilter();
f.filter(new ResponseContainerRequestContext(MockHttpRequest.create("GET", "/")));
});
}
use of org.jboss.resteasy.core.interception.jaxrs.ResponseContainerRequestContext in project resteasy by resteasy.
the class ServerResponseWriter method executeFilters.
private static void executeFilters(BuiltResponse jaxrsResponse, HttpRequest request, HttpResponse response, ResteasyProviderFactory providerFactory, ResourceMethodInvoker method, Consumer<Throwable> onComplete, RunnableWithIOException continuation) throws IOException {
ContainerResponseFilter[] responseFilters = null;
if (method != null) {
responseFilters = method.getResponseFilters();
} else {
responseFilters = providerFactory.getContainerResponseFilterRegistry().postMatch(null, null);
}
if (responseFilters != null) {
ResponseContainerRequestContext requestContext = new ResponseContainerRequestContext(request);
ContainerResponseContextImpl responseContext = new ContainerResponseContextImpl(request, response, jaxrsResponse, requestContext, responseFilters, onComplete, continuation);
RESTEasyTracingLogger logger = RESTEasyTracingLogger.getInstance(request);
final long timestamp = logger.timestamp("RESPONSE_FILTER_SUMMARY");
// filter calls the continuation
responseContext.filter();
logger.logDuration("RESPONSE_FILTER_SUMMARY", timestamp, responseFilters.length);
} else {
try {
continuation.run(onComplete);
} catch (Throwable t) {
onComplete.accept(t);
SynchronousDispatcher.rethrow(t);
}
}
}
use of org.jboss.resteasy.core.interception.jaxrs.ResponseContainerRequestContext in project platform by dashjoin.
the class ACLContainerRequestFilterTest method testQuery.
/**
* authenticated requests pass the filter
*/
@Test
public void testQuery() throws Exception {
ACLContainerRequestFilter f = new ACLContainerRequestFilter();
f.filter(new ResponseContainerRequestContext(null) {
@Override
public SecurityContext getSecurityContext() {
return new SecurityContext() {
@Override
public Principal getUserPrincipal() {
return new UnixPrincipal("root");
}
@Override
public boolean isUserInRole(String role) {
return true;
}
@Override
public boolean isSecure() {
return false;
}
@Override
public String getAuthenticationScheme() {
return null;
}
};
}
@Override
public UriInfo getUriInfo() {
try {
return new ResteasyUriInfo(new URI("/database/query/list"));
} catch (URISyntaxException e) {
throw new RuntimeException();
}
}
});
}
Aggregations