Search in sources :

Example 36 with Constraint

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

the class JettyLib method addPathConstraint.

public static void addPathConstraint(ConstraintSecurityHandler securityHandler, String pathSpec, String role) {
    Objects.requireNonNull(securityHandler);
    Objects.requireNonNull(pathSpec);
    ConstraintMapping mapping = new ConstraintMapping();
    Constraint constraint = new Constraint();
    String[] roles = new String[] { role };
    constraint.setRoles(roles);
    constraint.setName(securityHandler.getAuthenticator().getAuthMethod());
    constraint.setAuthenticate(true);
    mapping.setConstraint(constraint);
    mapping.setPathSpec(pathSpec);
    securityHandler.addConstraintMapping(mapping);
}
Also used : Constraint(org.eclipse.jetty.util.security.Constraint)

Example 37 with Constraint

use of org.eclipse.jetty.util.security.Constraint in project hive by apache.

the class HttpServer method setupPam.

/**
 * Secure the web server with PAM.
 */
void setupPam(Builder b, Handler handler) {
    LoginService loginService = new PamLoginService();
    webServer.addBean(loginService);
    ConstraintSecurityHandler security = new ConstraintSecurityHandler();
    Constraint constraint = new PamConstraint();
    ConstraintMapping mapping = new PamConstraintMapping(constraint);
    security.setConstraintMappings(Collections.singletonList(mapping));
    security.setAuthenticator(b.pamAuthenticator);
    security.setLoginService(loginService);
    security.setHandler(handler);
    webServer.setHandler(security);
}
Also used : ConstraintMapping(org.eclipse.jetty.security.ConstraintMapping) PamConstraintMapping(org.apache.hive.http.security.PamConstraintMapping) PamConstraint(org.apache.hive.http.security.PamConstraint) PamConstraint(org.apache.hive.http.security.PamConstraint) Constraint(org.eclipse.jetty.util.security.Constraint) PamConstraintMapping(org.apache.hive.http.security.PamConstraintMapping) ConstraintSecurityHandler(org.eclipse.jetty.security.ConstraintSecurityHandler) PamLoginService(org.apache.hive.http.security.PamLoginService) LoginService(org.eclipse.jetty.security.LoginService) PamLoginService(org.apache.hive.http.security.PamLoginService)

Example 38 with Constraint

use of org.eclipse.jetty.util.security.Constraint in project hive by apache.

the class ThriftHttpCLIService method constrainHttpMethods.

public void constrainHttpMethods(ServletContextHandler ctxHandler, boolean allowOptionsMethod) {
    Constraint c = new Constraint();
    c.setAuthenticate(true);
    ConstraintMapping cmt = new ConstraintMapping();
    cmt.setConstraint(c);
    cmt.setMethod("TRACE");
    cmt.setPathSpec("/*");
    ConstraintSecurityHandler securityHandler = new ConstraintSecurityHandler();
    if (!allowOptionsMethod) {
        ConstraintMapping cmo = new ConstraintMapping();
        cmo.setConstraint(c);
        cmo.setMethod("OPTIONS");
        cmo.setPathSpec("/*");
        securityHandler.setConstraintMappings(new ConstraintMapping[] { cmt, cmo });
    } else {
        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)

Example 39 with Constraint

use of org.eclipse.jetty.util.security.Constraint in project cayenne by apache.

the class Http2Server method basicAuth.

private static SecurityHandler basicAuth(String username, String password, String realm) {
    HashLoginService loginService = new HashLoginService();
    UserStore userStore = new UserStore();
    userStore.addUser(username, Credential.getCredential(password), new String[] { "cayenne-service-user" });
    loginService.setUserStore(userStore);
    loginService.setName(realm);
    Constraint constraint = new Constraint();
    constraint.setName(Constraint.__BASIC_AUTH);
    constraint.setRoles(new String[] { "cayenne-service-user" });
    constraint.setAuthenticate(true);
    ConstraintMapping constraintMapping = new ConstraintMapping();
    constraintMapping.setConstraint(constraint);
    constraintMapping.setPathSpec("/*");
    ConstraintSecurityHandler constraintSecurityHandler = new ConstraintSecurityHandler();
    constraintSecurityHandler.setAuthenticator(new BasicAuthenticator());
    constraintSecurityHandler.setRealmName(realm);
    constraintSecurityHandler.addConstraintMapping(constraintMapping);
    constraintSecurityHandler.setLoginService(loginService);
    return constraintSecurityHandler;
}
Also used : HashLoginService(org.eclipse.jetty.security.HashLoginService) ConstraintMapping(org.eclipse.jetty.security.ConstraintMapping) UserStore(org.eclipse.jetty.security.UserStore) BasicAuthenticator(org.eclipse.jetty.security.authentication.BasicAuthenticator) Constraint(org.eclipse.jetty.util.security.Constraint) ConstraintSecurityHandler(org.eclipse.jetty.security.ConstraintSecurityHandler)

Example 40 with Constraint

use of org.eclipse.jetty.util.security.Constraint in project elastic-core-maven by OrdinaryDude.

the class API method disableHttpMethod.

private static void disableHttpMethod(ConstraintSecurityHandler securityHandler, String httpMethod) {
    ConstraintMapping mapping = new ConstraintMapping();
    Constraint constraint = new Constraint();
    constraint.setName("Disable " + httpMethod);
    constraint.setAuthenticate(true);
    mapping.setConstraint(constraint);
    mapping.setPathSpec("/");
    mapping.setMethod(httpMethod);
    securityHandler.addConstraintMapping(mapping);
}
Also used : ConstraintMapping(org.eclipse.jetty.security.ConstraintMapping) Constraint(org.eclipse.jetty.util.security.Constraint)

Aggregations

Constraint (org.eclipse.jetty.util.security.Constraint)78 ConstraintMapping (org.eclipse.jetty.security.ConstraintMapping)46 ConstraintSecurityHandler (org.eclipse.jetty.security.ConstraintSecurityHandler)34 BasicAuthenticator (org.eclipse.jetty.security.authentication.BasicAuthenticator)27 HashLoginService (org.eclipse.jetty.security.HashLoginService)20 Test (org.junit.Test)15 Server (org.eclipse.jetty.server.Server)13 ArrayList (java.util.ArrayList)9 WebAppContext (org.eclipse.jetty.webapp.WebAppContext)8 Password (org.eclipse.jetty.util.security.Password)7 HashSet (java.util.HashSet)6 File (java.io.File)5 IOException (java.io.IOException)5 ResourceHandler (org.eclipse.jetty.server.handler.ResourceHandler)5 LoginService (org.eclipse.jetty.security.LoginService)4 ServerConnector (org.eclipse.jetty.server.ServerConnector)4 ContextHandler (org.eclipse.jetty.server.handler.ContextHandler)4 HandlerList (org.eclipse.jetty.server.handler.HandlerList)4 ServletContextHandler (org.eclipse.jetty.servlet.ServletContextHandler)4 ServletHolder (org.eclipse.jetty.servlet.ServletHolder)4