Search in sources :

Example 1 with ResponseContainerRequestContext

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", "/")));
    });
}
Also used : ResponseContainerRequestContext(org.jboss.resteasy.core.interception.jaxrs.ResponseContainerRequestContext) QuarkusTest(io.quarkus.test.junit.QuarkusTest) Test(org.junit.jupiter.api.Test)

Example 2 with ResponseContainerRequestContext

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);
        }
    }
}
Also used : ContainerResponseFilter(jakarta.ws.rs.container.ContainerResponseFilter) ResponseContainerRequestContext(org.jboss.resteasy.core.interception.jaxrs.ResponseContainerRequestContext) ContainerResponseContextImpl(org.jboss.resteasy.core.interception.jaxrs.ContainerResponseContextImpl) RESTEasyTracingLogger(org.jboss.resteasy.tracing.RESTEasyTracingLogger)

Example 3 with ResponseContainerRequestContext

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();
            }
        }
    });
}
Also used : ResponseContainerRequestContext(org.jboss.resteasy.core.interception.jaxrs.ResponseContainerRequestContext) ResteasyUriInfo(org.jboss.resteasy.specimpl.ResteasyUriInfo) UnixPrincipal(com.sun.security.auth.UnixPrincipal) SecurityContext(javax.ws.rs.core.SecurityContext) URISyntaxException(java.net.URISyntaxException) URI(java.net.URI) Principal(java.security.Principal) UnixPrincipal(com.sun.security.auth.UnixPrincipal) ResteasyUriInfo(org.jboss.resteasy.specimpl.ResteasyUriInfo) UriInfo(javax.ws.rs.core.UriInfo) QuarkusTest(io.quarkus.test.junit.QuarkusTest) Test(org.junit.jupiter.api.Test)

Aggregations

ResponseContainerRequestContext (org.jboss.resteasy.core.interception.jaxrs.ResponseContainerRequestContext)3 QuarkusTest (io.quarkus.test.junit.QuarkusTest)2 Test (org.junit.jupiter.api.Test)2 UnixPrincipal (com.sun.security.auth.UnixPrincipal)1 ContainerResponseFilter (jakarta.ws.rs.container.ContainerResponseFilter)1 URI (java.net.URI)1 URISyntaxException (java.net.URISyntaxException)1 Principal (java.security.Principal)1 SecurityContext (javax.ws.rs.core.SecurityContext)1 UriInfo (javax.ws.rs.core.UriInfo)1 ContainerResponseContextImpl (org.jboss.resteasy.core.interception.jaxrs.ContainerResponseContextImpl)1 ResteasyUriInfo (org.jboss.resteasy.specimpl.ResteasyUriInfo)1 RESTEasyTracingLogger (org.jboss.resteasy.tracing.RESTEasyTracingLogger)1