Search in sources :

Example 11 with LoginService

use of org.eclipse.jetty.security.LoginService in project jetty.project by eclipse.

the class ServerSupport method configureLoginServices.

/**
     * Set up any security LoginServices provided.
     * 
     * @param server the server
     * @param loginServices the login services
     */
public static void configureLoginServices(Server server, LoginService[] loginServices) {
    if (server == null)
        throw new IllegalArgumentException("Server is null");
    if (loginServices != null) {
        for (LoginService loginService : loginServices) {
            PluginLog.getLog().debug(loginService.getClass().getName() + ": " + loginService.toString());
            server.addBean(loginService);
        }
    }
}
Also used : LoginService(org.eclipse.jetty.security.LoginService)

Example 12 with LoginService

use of org.eclipse.jetty.security.LoginService in project blade by biezhi.

the class DeferredAuthentication method authenticate.

/* ------------------------------------------------------------ */
/**
     * @see Deferred#authenticate(ServletRequest, ServletResponse)
     */
@Override
public Authentication authenticate(ServletRequest request, ServletResponse response) {
    try {
        LoginService login_service = _authenticator.getLoginService();
        IdentityService identity_service = login_service.getIdentityService();
        Authentication authentication = _authenticator.validateRequest(request, response, true);
        if (authentication instanceof User && identity_service != null)
            _previousAssociation = identity_service.associate(((User) authentication).getUserIdentity());
        return authentication;
    } catch (ServerAuthException e) {
        LOG.debug(e);
    }
    return this;
}
Also used : IdentityService(org.eclipse.jetty.security.IdentityService) UserAuthentication(org.eclipse.jetty.security.UserAuthentication) Authentication(org.eclipse.jetty.server.Authentication) ServerAuthException(org.eclipse.jetty.security.ServerAuthException) LoginService(org.eclipse.jetty.security.LoginService)

Example 13 with LoginService

use of org.eclipse.jetty.security.LoginService in project blade by biezhi.

the class SessionAuthentication method readObject.

private void readObject(ObjectInputStream stream) throws IOException, ClassNotFoundException {
    stream.defaultReadObject();
    SecurityHandler security = SecurityHandler.getCurrentSecurityHandler();
    if (security == null)
        throw new IllegalStateException("!SecurityHandler");
    LoginService login_service = security.getLoginService();
    if (login_service == null)
        throw new IllegalStateException("!LoginService");
    _userIdentity = login_service.login(_name, _credentials, null);
    LOG.debug("Deserialized and relogged in {}", this);
}
Also used : SecurityHandler(org.eclipse.jetty.security.SecurityHandler) LoginService(org.eclipse.jetty.security.LoginService)

Example 14 with LoginService

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

use of org.eclipse.jetty.security.LoginService in project cxf by apache.

the class BookServerSimpleSecurity method configureServer.

@Override
protected void configureServer(org.eclipse.jetty.server.Server server) throws Exception {
    URL resource = getClass().getResource("/org/apache/cxf/systest/jaxrs/security/jetty-realm.properties");
    LoginService realm = new HashLoginService("BookStoreRealm", resource.toString());
    server.addBean(realm);
}
Also used : HashLoginService(org.eclipse.jetty.security.HashLoginService) URL(java.net.URL) HashLoginService(org.eclipse.jetty.security.HashLoginService) LoginService(org.eclipse.jetty.security.LoginService)

Aggregations

LoginService (org.eclipse.jetty.security.LoginService)16 HashLoginService (org.eclipse.jetty.security.HashLoginService)5 ConstraintMapping (org.eclipse.jetty.security.ConstraintMapping)4 ConstraintSecurityHandler (org.eclipse.jetty.security.ConstraintSecurityHandler)4 IdentityService (org.eclipse.jetty.security.IdentityService)4 ServerAuthException (org.eclipse.jetty.security.ServerAuthException)4 UserAuthentication (org.eclipse.jetty.security.UserAuthentication)4 Authentication (org.eclipse.jetty.server.Authentication)4 Constraint (org.eclipse.jetty.util.security.Constraint)4 File (java.io.File)3 URL (java.net.URL)2 Connector (org.eclipse.jetty.ant.types.Connector)2 SecurityHandler (org.eclipse.jetty.security.SecurityHandler)2 BasicAuthenticator (org.eclipse.jetty.security.authentication.BasicAuthenticator)2 Server (org.eclipse.jetty.server.Server)2 WebAppContext (org.eclipse.jetty.webapp.WebAppContext)2 FileOutputStream (java.io.FileOutputStream)1 ArrayList (java.util.ArrayList)1 PamConstraint (org.apache.hive.http.security.PamConstraint)1 PamConstraintMapping (org.apache.hive.http.security.PamConstraintMapping)1