Search in sources :

Example 6 with LoginService

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

the class DeferredAuthentication method authenticate.

/* ------------------------------------------------------------ */
/**
     * @see org.eclipse.jetty.server.Authentication.Deferred#authenticate(javax.servlet.ServletRequest, javax.servlet.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 Authentication.User && identity_service != null)
            _previousAssociation = identity_service.associate(((Authentication.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 7 with LoginService

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

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 8 with LoginService

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

the class DeferredAuthentication method authenticate.

/* ------------------------------------------------------------ */
/**
     * @see Deferred#authenticate(ServletRequest)
     */
@Override
public Authentication authenticate(ServletRequest request) {
    try {
        Authentication authentication = _authenticator.validateRequest(request, __deferredResponse, true);
        if (authentication != null && (authentication instanceof User) && !(authentication instanceof ResponseSent)) {
            LoginService login_service = _authenticator.getLoginService();
            IdentityService identity_service = login_service.getIdentityService();
            if (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 9 with LoginService

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

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

the class SecuredHelloHandler method main.

public static void main(String[] args) throws Exception {
    // Create a basic jetty server object that will listen on port 8080.
    // Note that if you set this to port 0 then a randomly available port
    // will be assigned that you can either look in the logs for the port,
    // or programmatically obtain it for use in test cases.
    Server server = new Server(8080);
    // Since this example is for our test webapp, we need to setup a
    // LoginService so this shows how to create a very simple hashmap based
    // one. The name of the LoginService needs to correspond to what is
    // configured a webapp's web.xml and since it has a lifecycle of its own
    // we register it as a bean with the Jetty server object so it can be
    // started and stopped according to the lifecycle of the server itself.
    // In this example the name can be whatever you like since we are not
    // dealing with webapp realms.
    LoginService loginService = new HashLoginService("MyRealm", "src/test/resources/realm.properties");
    server.addBean(loginService);
    // A security handler is a jetty handler that secures content behind a
    // particular portion of a url space. The ConstraintSecurityHandler is a
    // more specialized handler that allows matching of urls to different
    // constraints. The server sets this as the first handler in the chain,
    // effectively applying these constraints to all subsequent handlers in
    // the chain.
    ConstraintSecurityHandler security = new ConstraintSecurityHandler();
    server.setHandler(security);
    // This constraint requires authentication and in addition that an
    // authenticated user be a member of a given set of roles for
    // authorization purposes.
    Constraint constraint = new Constraint();
    constraint.setName("auth");
    constraint.setAuthenticate(true);
    constraint.setRoles(new String[] { "user", "admin" });
    // Binds a url pattern with the previously created constraint. The roles
    // for this constraing mapping are mined from the Constraint itself
    // although methods exist to declare and bind roles separately as well.
    ConstraintMapping mapping = new ConstraintMapping();
    mapping.setPathSpec("/*");
    mapping.setConstraint(constraint);
    // First you see the constraint mapping being applied to the handler as
    // a singleton list, however you can passing in as many security
    // constraint mappings as you like so long as they follow the mapping
    // requirements of the servlet api. Next we set a BasicAuthenticator
    // instance which is the object that actually checks the credentials
    // followed by the LoginService which is the store of known users, etc.
    security.setConstraintMappings(Collections.singletonList(mapping));
    security.setAuthenticator(new BasicAuthenticator());
    security.setLoginService(loginService);
    // The Hello Handler is the handler we are securing so we create one,
    // and then set it as the handler on the
    // security handler to complain the simple handler chain.
    HelloHandler hh = new HelloHandler();
    // chain the hello handler into the security handler
    security.setHandler(hh);
    // Start things up!
    server.start();
    // The use of server.join() the will make the current thread join and
    // wait until the server is done executing.
    // See
    // http://docs.oracle.com/javase/7/docs/api/java/lang/Thread.html#join()
    server.join();
}
Also used : HashLoginService(org.eclipse.jetty.security.HashLoginService) ConstraintMapping(org.eclipse.jetty.security.ConstraintMapping) Server(org.eclipse.jetty.server.Server) BasicAuthenticator(org.eclipse.jetty.security.authentication.BasicAuthenticator) Constraint(org.eclipse.jetty.util.security.Constraint) ConstraintSecurityHandler(org.eclipse.jetty.security.ConstraintSecurityHandler) 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