Search in sources :

Example 46 with ConstraintMapping

use of org.eclipse.jetty.security.ConstraintMapping in project Manga by herrlock.

the class JettyServer method createShutdownHandler.

private Handler createShutdownHandler() {
    String pwConfig = new File("conf/jetty-users.dsc").getAbsolutePath();
    HashLoginService loginService = new HashLoginService("MangaDownloader-Realm", pwConfig);
    this.server.addBean(loginService, true);
    ConstraintSecurityHandler secHandler = new ConstraintSecurityHandler();
    secHandler.setAuthenticator(new BasicAuthenticator());
    ConstraintMapping cm = new ConstraintMapping();
    final Constraint userConstraint = new Constraint(Constraint.__BASIC_AUTH, "**");
    userConstraint.setAuthenticate(true);
    cm.setConstraint(userConstraint);
    cm.setPathSpec("/shutdown/*");
    secHandler.setConstraintMappings(Arrays.asList(cm));
    secHandler.setHandler(new ShutdownHandler(SUPER_SECRET_MAGIC_TOKEN_FOR_SHUTDOWN, false, true));
    secHandler.setLoginService(loginService);
    return secHandler;
}
Also used : HashLoginService(org.eclipse.jetty.security.HashLoginService) ConstraintMapping(org.eclipse.jetty.security.ConstraintMapping) BasicAuthenticator(org.eclipse.jetty.security.authentication.BasicAuthenticator) ShutdownHandler(org.eclipse.jetty.server.handler.ShutdownHandler) Constraint(org.eclipse.jetty.util.security.Constraint) ConstraintSecurityHandler(org.eclipse.jetty.security.ConstraintSecurityHandler) File(java.io.File)

Example 47 with ConstraintMapping

use of org.eclipse.jetty.security.ConstraintMapping in project alluxio by Alluxio.

the class WebServer method disableMethod.

/**
 * @param method to disable
 */
private void disableMethod(String method) {
    Constraint constraint = new Constraint();
    constraint.setAuthenticate(true);
    constraint.setName("Disable " + method);
    ConstraintMapping disableMapping = new ConstraintMapping();
    disableMapping.setConstraint(constraint);
    disableMapping.setMethod(method.toUpperCase());
    disableMapping.setPathSpec("/");
    mSecurityHandler.addConstraintMapping(disableMapping);
}
Also used : ConstraintMapping(org.eclipse.jetty.security.ConstraintMapping) Constraint(org.eclipse.jetty.util.security.Constraint)

Example 48 with ConstraintMapping

use of org.eclipse.jetty.security.ConstraintMapping in project calcite-avatica by apache.

the class HttpServer method configureCommonAuthentication.

protected ConstraintSecurityHandler configureCommonAuthentication(String constraintName, String[] allowedRoles, Authenticator authenticator, String realm, LoginService loginService) {
    Constraint constraint = new Constraint();
    constraint.setName(constraintName);
    constraint.setRoles(allowedRoles);
    // This is telling Jetty to not allow unauthenticated requests through (very important!)
    constraint.setAuthenticate(true);
    ConstraintMapping cm = new ConstraintMapping();
    cm.setConstraint(constraint);
    cm.setPathSpec("/*");
    ConstraintSecurityHandler securityHandler = new ConstraintSecurityHandler();
    securityHandler.setAuthenticator(authenticator);
    securityHandler.setLoginService(loginService);
    securityHandler.setConstraintMappings(new ConstraintMapping[] { cm });
    return securityHandler;
}
Also used : ConstraintMapping(org.eclipse.jetty.security.ConstraintMapping) Constraint(org.eclipse.jetty.util.security.Constraint) ConstraintSecurityHandler(org.eclipse.jetty.security.ConstraintSecurityHandler)

Example 49 with ConstraintMapping

use of org.eclipse.jetty.security.ConstraintMapping in project zookeeper by apache.

the class JettyAdminServer method constrainTraceMethod.

/**
 * Add constraint to a given context to disallow TRACE method
 * @param ctxHandler the context to modify
 */
private void constrainTraceMethod(ServletContextHandler ctxHandler) {
    Constraint c = new Constraint();
    c.setAuthenticate(true);
    ConstraintMapping cmt = new ConstraintMapping();
    cmt.setConstraint(c);
    cmt.setMethod("TRACE");
    cmt.setPathSpec("/*");
    ConstraintSecurityHandler securityHandler = new ConstraintSecurityHandler();
    securityHandler.setConstraintMappings(new ConstraintMapping[] { cmt });
    ctxHandler.setSecurityHandler(securityHandler);
}
Also used : ConstraintMapping(org.eclipse.jetty.security.ConstraintMapping) Constraint(org.eclipse.jetty.util.security.Constraint) ConstraintSecurityHandler(org.eclipse.jetty.security.ConstraintSecurityHandler)

Aggregations

ConstraintMapping (org.eclipse.jetty.security.ConstraintMapping)49 Constraint (org.eclipse.jetty.util.security.Constraint)46 ConstraintSecurityHandler (org.eclipse.jetty.security.ConstraintSecurityHandler)34 HashLoginService (org.eclipse.jetty.security.HashLoginService)20 BasicAuthenticator (org.eclipse.jetty.security.authentication.BasicAuthenticator)17 Server (org.eclipse.jetty.server.Server)12 WebAppContext (org.eclipse.jetty.webapp.WebAppContext)9 ArrayList (java.util.ArrayList)6 Password (org.eclipse.jetty.util.security.Password)6 Test (org.junit.Test)6 File (java.io.File)5 HttpConstraint (javax.servlet.annotation.HttpConstraint)5 HttpMethodConstraint (javax.servlet.annotation.HttpMethodConstraint)5 IOException (java.io.IOException)4 LoginService (org.eclipse.jetty.security.LoginService)4 ServerConnector (org.eclipse.jetty.server.ServerConnector)4 ResourceHandler (org.eclipse.jetty.server.handler.ResourceHandler)4 ServletHolder (org.eclipse.jetty.servlet.ServletHolder)4 HashSet (java.util.HashSet)3 ConstraintAware (org.eclipse.jetty.security.ConstraintAware)3