Search in sources :

Example 11 with SecurityHandler

use of org.eclipse.jetty.security.SecurityHandler in project blade by biezhi.

the class SessionAuthentication method readObject.

private void readObject(ObjectInputStream stream) throws IOException, ClassNotFoundException {
    stream.defaultReadObject();
    SecurityHandler security = SecurityHandler.getCurrentSecurityHandler();
    if (security == null)
        throw new IllegalStateException("!SecurityHandler");
    LoginService login_service = security.getLoginService();
    if (login_service == null)
        throw new IllegalStateException("!LoginService");
    _userIdentity = login_service.login(_name, _credentials, null);
    LOG.debug("Deserialized and relogged in {}", this);
}
Also used : SecurityHandler(org.eclipse.jetty.security.SecurityHandler) LoginService(org.eclipse.jetty.security.LoginService)

Example 12 with SecurityHandler

use of org.eclipse.jetty.security.SecurityHandler in project jena by apache.

the class TestFusekiTestAuth method ctlBeforeClass.

@BeforeClass
public static void ctlBeforeClass() {
    SecurityHandler sh = FusekiTestAuth.makeSimpleSecurityHandler("/*", USER, PASSWORD);
    FusekiTestAuth.setupServer(false, sh);
}
Also used : SecurityHandler(org.eclipse.jetty.security.SecurityHandler) BeforeClass(org.junit.BeforeClass)

Example 13 with SecurityHandler

use of org.eclipse.jetty.security.SecurityHandler in project airlift by airlift.

the class HttpServer method createServletContext.

private static ServletContextHandler createServletContext(Servlet theServlet, Map<String, String> parameters, Set<Filter> filters, TraceTokenManager tokenManager, LoginService loginService, String... connectorNames) {
    ServletContextHandler context = new ServletContextHandler(ServletContextHandler.NO_SESSIONS);
    context.addFilter(new FilterHolder(new TimingFilter()), "/*", null);
    if (tokenManager != null) {
        context.addFilter(new FilterHolder(new TraceTokenFilter(tokenManager)), "/*", null);
    }
    // -- security handler
    if (loginService != null) {
        SecurityHandler securityHandler = createSecurityHandler(loginService);
        context.setSecurityHandler(securityHandler);
    }
    // -- user provided filters
    for (Filter filter : filters) {
        context.addFilter(new FilterHolder(filter), "/*", null);
    }
    // -- gzip handler
    context.setGzipHandler(new GzipHandler());
    // -- the servlet
    ServletHolder servletHolder = new ServletHolder(theServlet);
    servletHolder.setInitParameters(ImmutableMap.copyOf(parameters));
    context.addServlet(servletHolder, "/*");
    // Starting with Jetty 9 there is no way to specify connectors directly, but
    // there is this wonky @ConnectorName virtual hosts automatically added
    String[] virtualHosts = new String[connectorNames.length];
    for (int i = 0; i < connectorNames.length; i++) {
        virtualHosts[i] = "@" + connectorNames[i];
    }
    context.setVirtualHosts(virtualHosts);
    return context;
}
Also used : ConstraintSecurityHandler(org.eclipse.jetty.security.ConstraintSecurityHandler) SecurityHandler(org.eclipse.jetty.security.SecurityHandler) FilterHolder(org.eclipse.jetty.servlet.FilterHolder) Filter(javax.servlet.Filter) GzipHandler(org.eclipse.jetty.server.handler.gzip.GzipHandler) ServletHolder(org.eclipse.jetty.servlet.ServletHolder) ServletContextHandler(org.eclipse.jetty.servlet.ServletContextHandler) Constraint(org.eclipse.jetty.util.security.Constraint)

Example 14 with SecurityHandler

use of org.eclipse.jetty.security.SecurityHandler in project jspwiki by apache.

the class TestContainer method addWebApp.

/**
 * Configures a test web application
 *
 * @param context the name of the web m_context; must start with "/"
 * @param path the file path for the WAR file, or expanded WAR directory
 * @throws IOException
 */
public void addWebApp(String context, String path) throws IOException {
    // Set the default users and roles for the realm (note that realm name *must* match web.xml <realm-name>
    HashLoginService loginService = new HashLoginService("JSPWikiRealm");
    loginService.putUser(Users.ADMIN, new Password(Users.ADMIN_PASS), new String[] { "Authenticated", "Admin" });
    loginService.putUser(Users.JANNE, new Password(Users.JANNE_PASS), new String[] { "Authenticated" });
    WebAppContext webAppContext = new WebAppContext(path, context);
    // Add a security handler.
    SecurityHandler csh = new ConstraintSecurityHandler();
    csh.setLoginService(loginService);
    webAppContext.setSecurityHandler(csh);
    log.error("Adding webapp " + context + " for path " + path);
    handlerCollection.addHandler(webAppContext);
}
Also used : WebAppContext(org.eclipse.jetty.webapp.WebAppContext) ConstraintSecurityHandler(org.eclipse.jetty.security.ConstraintSecurityHandler) SecurityHandler(org.eclipse.jetty.security.SecurityHandler) HashLoginService(org.eclipse.jetty.security.HashLoginService) ConstraintSecurityHandler(org.eclipse.jetty.security.ConstraintSecurityHandler) Password(org.eclipse.jetty.util.security.Password)

Example 15 with SecurityHandler

use of org.eclipse.jetty.security.SecurityHandler 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

SecurityHandler (org.eclipse.jetty.security.SecurityHandler)19 ConstraintSecurityHandler (org.eclipse.jetty.security.ConstraintSecurityHandler)7 ContextHandler (org.eclipse.jetty.server.handler.ContextHandler)4 IOException (java.io.IOException)3 FusekiServer (org.apache.jena.fuseki.main.FusekiServer)3 UserStore (org.eclipse.jetty.security.UserStore)3 Handler (org.eclipse.jetty.server.Handler)3 GzipHandler (org.eclipse.jetty.server.handler.gzip.GzipHandler)3 SessionHandler (org.eclipse.jetty.server.session.SessionHandler)3 FilterHolder (org.eclipse.jetty.servlet.FilterHolder)3 ServletHolder (org.eclipse.jetty.servlet.ServletHolder)3 Constraint (org.eclipse.jetty.util.security.Constraint)3 BeforeClass (org.junit.BeforeClass)3 Filter (javax.servlet.Filter)2 LoginService (org.eclipse.jetty.security.LoginService)2 ContextHandlerCollection (org.eclipse.jetty.server.handler.ContextHandlerCollection)2 ErrorHandler (org.eclipse.jetty.server.handler.ErrorHandler)2 ServletContextHandler (org.eclipse.jetty.servlet.ServletContextHandler)2 HttpResourceBinding (io.airlift.http.server.HttpServerBinder.HttpResourceBinding)1 ForbiddenException (io.crnk.core.exception.ForbiddenException)1