Search in sources :

Example 31 with BasicAuthenticator

use of org.eclipse.jetty.security.authentication.BasicAuthenticator in project jena by apache.

the class FusekiTestAuth method makeSimpleSecurityHandler.

/** Create a Jetty {@link SecurityHandler} for basic authentication, one user/password/role. */
public static SecurityHandler makeSimpleSecurityHandler(String pathSpec, String realm, String user, String password, String role) {
    Objects.requireNonNull(user);
    Objects.requireNonNull(password);
    Objects.requireNonNull(role);
    Constraint constraint = new Constraint();
    constraint.setName(Constraint.__BASIC_AUTH);
    String[] roles = new String[] { role };
    constraint.setRoles(roles);
    constraint.setAuthenticate(true);
    ConstraintMapping mapping = new ConstraintMapping();
    mapping.setConstraint(constraint);
    mapping.setPathSpec("/*");
    IdentityService identService = new DefaultIdentityService();
    ConstraintSecurityHandler securityHandler = new ConstraintSecurityHandler();
    securityHandler.addConstraintMapping(mapping);
    securityHandler.setIdentityService(identService);
    UserStore userStore = makeUserStore(user, password, role);
    HashLoginService loginService = new HashLoginService("Fuseki Authentication");
    loginService.setUserStore(userStore);
    loginService.setIdentityService(identService);
    securityHandler.setLoginService(loginService);
    securityHandler.setAuthenticator(new BasicAuthenticator());
    if (realm != null)
        securityHandler.setRealmName(realm);
    return securityHandler;
}
Also used : BasicAuthenticator(org.eclipse.jetty.security.authentication.BasicAuthenticator) Constraint(org.eclipse.jetty.util.security.Constraint)

Example 32 with BasicAuthenticator

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

the class HttpServer method configureBasicAuthentication.

protected ConstraintSecurityHandler configureBasicAuthentication(Server server, ServerConnector connector, AvaticaServerConfiguration config) {
    final String[] allowedRoles = config.getAllowedRoles();
    final String realm = config.getHashLoginServiceRealm();
    final String loginServiceProperties = config.getHashLoginServiceProperties();
    HashLoginService loginService = new HashLoginService(realm, loginServiceProperties);
    server.addBean(loginService);
    return configureCommonAuthentication(server, connector, config, Constraint.__BASIC_AUTH, allowedRoles, new BasicAuthenticator(), null, loginService);
}
Also used : HashLoginService(org.eclipse.jetty.security.HashLoginService) BasicAuthenticator(org.eclipse.jetty.security.authentication.BasicAuthenticator)

Example 33 with BasicAuthenticator

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

the class HttpBasicAuthComponentConfiguredTest 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 34 with BasicAuthenticator

use of org.eclipse.jetty.security.authentication.BasicAuthenticator 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 35 with BasicAuthenticator

use of org.eclipse.jetty.security.authentication.BasicAuthenticator 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)

Aggregations

BasicAuthenticator (org.eclipse.jetty.security.authentication.BasicAuthenticator)40 Constraint (org.eclipse.jetty.util.security.Constraint)27 ConstraintMapping (org.eclipse.jetty.security.ConstraintMapping)17 ConstraintSecurityHandler (org.eclipse.jetty.security.ConstraintSecurityHandler)17 HashLoginService (org.eclipse.jetty.security.HashLoginService)17 Test (org.junit.Test)12 Server (org.eclipse.jetty.server.Server)6 HashSet (java.util.HashSet)3 ServletContextHandler (org.eclipse.jetty.servlet.ServletContextHandler)3 Password (org.eclipse.jetty.util.security.Password)3 WebAppContext (org.eclipse.jetty.webapp.WebAppContext)3 File (java.io.File)2 ArrayList (java.util.ArrayList)2 LoginService (org.eclipse.jetty.security.LoginService)2 ClientCertAuthenticator (org.eclipse.jetty.security.authentication.ClientCertAuthenticator)2 DigestAuthenticator (org.eclipse.jetty.security.authentication.DigestAuthenticator)2 FormAuthenticator (org.eclipse.jetty.security.authentication.FormAuthenticator)2 SpnegoAuthenticator (org.eclipse.jetty.security.authentication.SpnegoAuthenticator)2 Connector (org.eclipse.jetty.server.Connector)2 Handler (org.eclipse.jetty.server.Handler)2