Search in sources :

Example 6 with TestContainer

use of org.glassfish.jersey.test.spi.TestContainer in project crnk-framework by crnk-project.

the class SecurityModuleIntTest method getTestContainerFactory.

protected TestContainerFactory getTestContainerFactory() throws TestContainerException {
    final TestContainerFactory testContainerFactory = super.getTestContainerFactory();
    return new TestContainerFactory() {

        @Override
        public TestContainer create(URI baseUri, DeploymentContext deploymentContext) {
            TestContainer container = testContainerFactory.create(baseUri, deploymentContext);
            try {
                Field field = container.getClass().getDeclaredField("server");
                field.setAccessible(true);
                Server server = (Server) field.get(container);
                Handler handler = server.getHandler();
                SecurityHandler securityHandler = identityManager.getSecurityHandler();
                if (securityHandler.getHandler() == null) {
                    securityHandler.setHandler(handler);
                }
                server.setHandler(securityHandler);
            } catch (Exception e) {
                throw new IllegalStateException(e);
            }
            return container;
        }
    };
}
Also used : DeploymentContext(org.glassfish.jersey.test.DeploymentContext) Field(java.lang.reflect.Field) SecurityHandler(org.eclipse.jetty.security.SecurityHandler) TestContainer(org.glassfish.jersey.test.spi.TestContainer) Server(org.eclipse.jetty.server.Server) Handler(org.eclipse.jetty.server.Handler) SecurityHandler(org.eclipse.jetty.security.SecurityHandler) URI(java.net.URI) UnauthorizedException(io.crnk.core.exception.UnauthorizedException) IOException(java.io.IOException) TestContainerException(org.glassfish.jersey.test.spi.TestContainerException) ForbiddenException(io.crnk.core.exception.ForbiddenException) TestContainerFactory(org.glassfish.jersey.test.spi.TestContainerFactory)

Aggregations

TestContainer (org.glassfish.jersey.test.spi.TestContainer)6 IOException (java.io.IOException)2 URI (java.net.URI)2 DeploymentContext (org.glassfish.jersey.test.DeploymentContext)2 TestContainerException (org.glassfish.jersey.test.spi.TestContainerException)2 TestContainerFactory (org.glassfish.jersey.test.spi.TestContainerFactory)2 ForbiddenException (io.crnk.core.exception.ForbiddenException)1 UnauthorizedException (io.crnk.core.exception.UnauthorizedException)1 Field (java.lang.reflect.Field)1 ArrayList (java.util.ArrayList)1 HelixRestNamespace (org.apache.helix.rest.common.HelixRestNamespace)1 AuditLogger (org.apache.helix.rest.server.auditlog.AuditLogger)1 SecurityHandler (org.eclipse.jetty.security.SecurityHandler)1 Handler (org.eclipse.jetty.server.Handler)1 Server (org.eclipse.jetty.server.Server)1 Before (org.junit.Before)1