Search in sources :

Example 41 with ConstraintMapping

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

the class HttpBasicAuthTest method getSecurityHandler.

private SecurityHandler getSecurityHandler() throws IOException {
    Constraint constraint = new Constraint(Constraint.__BASIC_AUTH, "user");
    constraint.setAuthenticate(true);
    ConstraintMapping cm = new ConstraintMapping();
    cm.setPathSpec("/*");
    cm.setConstraint(constraint);
    ConstraintSecurityHandler sh = new ConstraintSecurityHandler();
    sh.setAuthenticator(new BasicAuthenticator());
    sh.setConstraintMappings(Arrays.asList(new ConstraintMapping[] { cm }));
    HashLoginService loginService = new HashLoginService("MyRealm", "src/test/resources/myRealm.properties");
    sh.setLoginService(loginService);
    sh.setConstraintMappings(Arrays.asList(new ConstraintMapping[] { cm }));
    return sh;
}
Also used : ConstraintMapping(org.eclipse.jetty.security.ConstraintMapping) HashLoginService(org.eclipse.jetty.security.HashLoginService) BasicAuthenticator(org.eclipse.jetty.security.authentication.BasicAuthenticator) Constraint(org.eclipse.jetty.util.security.Constraint) ConstraintSecurityHandler(org.eclipse.jetty.security.ConstraintSecurityHandler)

Example 42 with ConstraintMapping

use of org.eclipse.jetty.security.ConstraintMapping in project cdap by caskdata.

the class AbstractAuthenticationHandler method init.

/**
 * Initialize the handler context and other related services.
 */
public void init(Map<String, String> handlerProps) throws Exception {
    this.handlerProps = handlerProps;
    Constraint constraint = new Constraint();
    constraint.setRoles(new String[] { "*" });
    constraint.setAuthenticate(true);
    if (Boolean.parseBoolean(handlerProps.get(Constants.Security.SSL.EXTERNAL_ENABLED))) {
        constraint.setDataConstraint(Constraint.DC_CONFIDENTIAL);
    }
    ConstraintMapping constraintMapping = new ConstraintMapping();
    constraintMapping.setConstraint(constraint);
    constraintMapping.setPathSpec("/*");
    this.setConstraintMappings(new ConstraintMapping[] { constraintMapping });
    this.setStrict(false);
    this.setIdentityService(getHandlerIdentityService());
    this.setAuthenticator(getHandlerAuthenticator());
    this.setLoginService(getHandlerLoginService());
    this.doStart();
}
Also used : ConstraintMapping(org.eclipse.jetty.security.ConstraintMapping) Constraint(org.eclipse.jetty.util.security.Constraint)

Example 43 with ConstraintMapping

use of org.eclipse.jetty.security.ConstraintMapping in project rest-assured by rest-assured.

the class WithJetty method startJetty.

@BeforeClass
public static void startJetty() throws Exception {
    server = new Server();
    HttpConfiguration httpConfig = new HttpConfiguration();
    httpConfig.setSecureScheme("https");
    httpConfig.setSecurePort(8443);
    httpConfig.setOutputBufferSize(32768);
    ServerConnector http = new ServerConnector(server, new HttpConnectionFactory(httpConfig));
    http.setPort(8080);
    http.setIdleTimeout(30000);
    HttpConfiguration httpsConfig = new HttpConfiguration(httpConfig);
    httpsConfig.addCustomizer(new SecureRequestCustomizer());
    String file = WithJetty.class.getClassLoader().getResource("jetty_localhost_server.jks").getFile();
    SslContextFactory sslContextFactory = new SslContextFactory(file);
    sslContextFactory.setKeyStorePassword("test1234");
    ServerConnector https = new ServerConnector(server, new SslConnectionFactory(sslContextFactory, HttpVersion.HTTP_1_1.asString()), new HttpConnectionFactory(httpsConfig));
    https.setPort(8443);
    https.setIdleTimeout(50000);
    String canonicalPath = new File(".").getCanonicalPath();
    String scalatraPath = "/examples/scalatra-webapp";
    // Security config
    Constraint constraint = new Constraint();
    constraint.setName(Constraint.__BASIC_AUTH);
    constraint.setRoles(new String[] { "user", "admin", "moderator" });
    constraint.setAuthenticate(true);
    ConstraintMapping mapping = new ConstraintMapping();
    mapping.setConstraint(constraint);
    mapping.setPathSpec("/secured/*");
    final String realmPath = scalatraPath + "/etc/realm.properties";
    LoginService loginService = new HashLoginService("MyRealm", isExecutedFromMaven(canonicalPath) ? gotoProjectRoot().getCanonicalPath() + realmPath : canonicalPath + realmPath);
    server.addBean(loginService);
    ConstraintSecurityHandler security = new ConstraintSecurityHandler();
    server.setHandler(security);
    security.setConstraintMappings(Collections.singletonList(mapping));
    security.setAuthenticator(new BasicAuthenticator());
    security.setLoginService(loginService);
    // End security config
    WebAppContext wac = new WebAppContext();
    wac.setContextPath("/");
    String webAppPath = "/src/main/webapp";
    final String scalatraWebAppPath = scalatraPath + webAppPath;
    String warPath = isExecutedFromMaven(canonicalPath) ? gotoProjectRoot().getCanonicalPath() + scalatraWebAppPath : canonicalPath + scalatraWebAppPath;
    wac.setWar(warPath);
    wac.setServer(server);
    security.setHandler(wac);
    server.setHandler(security);
    server.setConnectors(new Connector[] { http, https });
    dontSendDateHeader(server);
    server.start();
}
Also used : ConstraintMapping(org.eclipse.jetty.security.ConstraintMapping) Constraint(org.eclipse.jetty.util.security.Constraint) LoginService(org.eclipse.jetty.security.LoginService) HashLoginService(org.eclipse.jetty.security.HashLoginService) WebAppContext(org.eclipse.jetty.webapp.WebAppContext) SslContextFactory(org.eclipse.jetty.util.ssl.SslContextFactory) HashLoginService(org.eclipse.jetty.security.HashLoginService) BasicAuthenticator(org.eclipse.jetty.security.authentication.BasicAuthenticator) ConstraintSecurityHandler(org.eclipse.jetty.security.ConstraintSecurityHandler) File(java.io.File)

Example 44 with ConstraintMapping

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

the class HttpServer method createSecurityHandler.

private static SecurityHandler createSecurityHandler(LoginService loginService) {
    Constraint constraint = new Constraint();
    constraint.setAuthenticate(false);
    ConstraintMapping constraintMapping = new ConstraintMapping();
    constraintMapping.setConstraint(constraint);
    constraintMapping.setPathSpec("/*");
    ConstraintSecurityHandler securityHandler = new ConstraintSecurityHandler();
    securityHandler.setLoginService(loginService);
    // TODO: support for other auth schemes (digest, etc)
    securityHandler.setAuthenticator(new BasicAuthenticator());
    securityHandler.setConstraintMappings(ImmutableList.of(constraintMapping));
    return securityHandler;
}
Also used : ConstraintMapping(org.eclipse.jetty.security.ConstraintMapping) BasicAuthenticator(org.eclipse.jetty.security.authentication.BasicAuthenticator) Constraint(org.eclipse.jetty.util.security.Constraint) ConstraintSecurityHandler(org.eclipse.jetty.security.ConstraintSecurityHandler)

Example 45 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)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