Search in sources :

Example 1 with SecurityHandler

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

the class ServletContextHandler method setSecurityHandler.

/* ------------------------------------------------------------ */
/**
     * @param securityHandler The {@link SecurityHandler} to set on this context.
     */
public void setSecurityHandler(SecurityHandler securityHandler) {
    if (isStarted())
        throw new IllegalStateException("STARTED");
    Handler next = null;
    if (_securityHandler != null) {
        next = _securityHandler.getHandler();
        _securityHandler.setHandler(null);
        replaceHandler(_securityHandler, securityHandler);
    }
    _securityHandler = securityHandler;
    if (next != null && _securityHandler.getHandler() == null)
        _securityHandler.setHandler(next);
    relinkHandlers();
}
Also used : Handler(org.eclipse.jetty.server.Handler) ConstraintSecurityHandler(org.eclipse.jetty.security.ConstraintSecurityHandler) ErrorHandler(org.eclipse.jetty.server.handler.ErrorHandler) SecurityHandler(org.eclipse.jetty.security.SecurityHandler) GzipHandler(org.eclipse.jetty.server.handler.gzip.GzipHandler) ContextHandler(org.eclipse.jetty.server.handler.ContextHandler) SessionHandler(org.eclipse.jetty.server.session.SessionHandler)

Example 2 with SecurityHandler

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

the class ServletHandler method doStart.

/* ----------------------------------------------------------------- */
@Override
protected synchronized void doStart() throws Exception {
    ContextHandler.Context context = ContextHandler.getCurrentContext();
    _servletContext = context == null ? new ContextHandler.StaticContext() : context;
    _contextHandler = (ServletContextHandler) (context == null ? null : context.getContextHandler());
    if (_contextHandler != null) {
        SecurityHandler security_handler = _contextHandler.getChildHandlerByClass(SecurityHandler.class);
        if (security_handler != null)
            _identityService = security_handler.getIdentityService();
    }
    updateNameMappings();
    updateMappings();
    if (getServletMapping("/") == null && isEnsureDefaultServlet()) {
        if (LOG.isDebugEnabled())
            LOG.debug("Adding Default404Servlet to {}", this);
        addServletWithMapping(Default404Servlet.class, "/");
        updateMappings();
        getServletMapping("/").setDefault(true);
    }
    if (isFilterChainsCached()) {
        _chainCache[FilterMapping.REQUEST] = new ConcurrentHashMap<>();
        _chainCache[FilterMapping.FORWARD] = new ConcurrentHashMap<>();
        _chainCache[FilterMapping.INCLUDE] = new ConcurrentHashMap<>();
        _chainCache[FilterMapping.ERROR] = new ConcurrentHashMap<>();
        _chainCache[FilterMapping.ASYNC] = new ConcurrentHashMap<>();
        _chainLRU[FilterMapping.REQUEST] = new ConcurrentLinkedQueue<>();
        _chainLRU[FilterMapping.FORWARD] = new ConcurrentLinkedQueue<>();
        _chainLRU[FilterMapping.INCLUDE] = new ConcurrentLinkedQueue<>();
        _chainLRU[FilterMapping.ERROR] = new ConcurrentLinkedQueue<>();
        _chainLRU[FilterMapping.ASYNC] = new ConcurrentLinkedQueue<>();
    }
    if (_contextHandler == null)
        initialize();
    super.doStart();
}
Also used : ContextHandler(org.eclipse.jetty.server.handler.ContextHandler) SecurityHandler(org.eclipse.jetty.security.SecurityHandler)

Example 3 with SecurityHandler

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

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 4 with SecurityHandler

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

the class ServletContextHandlerTest method testFindContainer.

@Test
public void testFindContainer() throws Exception {
    ContextHandlerCollection contexts = new ContextHandlerCollection();
    _server.setHandler(contexts);
    ServletContextHandler root = new ServletContextHandler(contexts, "/", ServletContextHandler.SESSIONS);
    SessionHandler session = root.getSessionHandler();
    ServletHandler servlet = root.getServletHandler();
    SecurityHandler security = new ConstraintSecurityHandler();
    root.setSecurityHandler(security);
    _server.start();
    assertEquals(root, AbstractHandlerContainer.findContainerOf(_server, ContextHandler.class, session));
    assertEquals(root, AbstractHandlerContainer.findContainerOf(_server, ContextHandler.class, security));
    assertEquals(root, AbstractHandlerContainer.findContainerOf(_server, ContextHandler.class, servlet));
}
Also used : SessionHandler(org.eclipse.jetty.server.session.SessionHandler) ContextHandler(org.eclipse.jetty.server.handler.ContextHandler) ConstraintSecurityHandler(org.eclipse.jetty.security.ConstraintSecurityHandler) SecurityHandler(org.eclipse.jetty.security.SecurityHandler) ConstraintSecurityHandler(org.eclipse.jetty.security.ConstraintSecurityHandler) ContextHandlerCollection(org.eclipse.jetty.server.handler.ContextHandlerCollection) Test(org.junit.Test)

Example 5 with SecurityHandler

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

the class ServletEnvironmentTest method setsSecurityHandlers.

@Test
void setsSecurityHandlers() {
    final SecurityHandler securityHandler = new ConstraintSecurityHandler();
    environment.setSecurityHandler(securityHandler);
    assertThat(handler.getSecurityHandler()).isEqualTo(securityHandler);
    assertThat(handler.isSecurityEnabled()).isTrue();
}
Also used : ConstraintSecurityHandler(org.eclipse.jetty.security.ConstraintSecurityHandler) SecurityHandler(org.eclipse.jetty.security.SecurityHandler) ConstraintSecurityHandler(org.eclipse.jetty.security.ConstraintSecurityHandler) Test(org.junit.jupiter.api.Test)

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