Search in sources :

Example 21 with ConstraintMapping

use of org.eclipse.jetty.security.ConstraintMapping in project elasticsearch-jetty by sonian.

the class RestConstraintSecurityHandlerTests method forbidden.

protected ConstraintMapping forbidden(String method, String url) {
    ConstraintMapping constraintMapping = new ConstraintMapping();
    Constraint constraint = new Constraint();
    constraintMapping.setMethod(method);
    constraintMapping.setPathSpec(url);
    constraint.setAuthenticate(true);
    constraintMapping.setConstraint(constraint);
    return constraintMapping;
}
Also used : ConstraintMapping(org.eclipse.jetty.security.ConstraintMapping) Constraint(org.eclipse.jetty.util.security.Constraint)

Example 22 with ConstraintMapping

use of org.eclipse.jetty.security.ConstraintMapping 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 23 with ConstraintMapping

use of org.eclipse.jetty.security.ConstraintMapping 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 24 with ConstraintMapping

use of org.eclipse.jetty.security.ConstraintMapping 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 25 with ConstraintMapping

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

ConstraintMapping (org.eclipse.jetty.security.ConstraintMapping)50 Constraint (org.eclipse.jetty.util.security.Constraint)47 ConstraintSecurityHandler (org.eclipse.jetty.security.ConstraintSecurityHandler)35 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