Search in sources :

Example 1 with BasicAuthenticator

use of org.mortbay.jetty.security.BasicAuthenticator in project exhibitor by soabase.

the class ExhibitorCreator method makeSecurityHandler.

private SecurityHandler makeSecurityHandler(String realm, String consoleUser, String consolePassword, String curatorUser, String curatorPassword) {
    HashUserRealm userRealm = new HashUserRealm(realm);
    userRealm.put(consoleUser, Credential.getCredential(consolePassword));
    userRealm.addUserToRole(consoleUser, "console");
    userRealm.put(curatorUser, Credential.getCredential(curatorPassword));
    userRealm.addUserToRole(curatorUser, "curator");
    Constraint console = new Constraint();
    console.setName("consoleauth");
    console.setRoles(new String[] { "console" });
    console.setAuthenticate(true);
    Constraint curator = new Constraint();
    curator.setName("curatorauth");
    curator.setRoles(new String[] { "curator", "console" });
    curator.setAuthenticate(true);
    ConstraintMapping consoleMapping = new ConstraintMapping();
    consoleMapping.setConstraint(console);
    consoleMapping.setPathSpec("/*");
    ConstraintMapping curatorMapping = new ConstraintMapping();
    curatorMapping.setConstraint(curator);
    curatorMapping.setPathSpec("/exhibitor/v1/cluster/list");
    SecurityHandler handler = new SecurityHandler();
    handler.setUserRealm(userRealm);
    handler.setConstraintMappings(new ConstraintMapping[] { consoleMapping, curatorMapping });
    handler.setAuthenticator(new BasicAuthenticator());
    return handler;
}
Also used : SecurityHandler(org.mortbay.jetty.security.SecurityHandler) ConstraintMapping(org.mortbay.jetty.security.ConstraintMapping) BasicAuthenticator(org.mortbay.jetty.security.BasicAuthenticator) Constraint(org.mortbay.jetty.security.Constraint) HashUserRealm(org.mortbay.jetty.security.HashUserRealm)

Aggregations

BasicAuthenticator (org.mortbay.jetty.security.BasicAuthenticator)1 Constraint (org.mortbay.jetty.security.Constraint)1 ConstraintMapping (org.mortbay.jetty.security.ConstraintMapping)1 HashUserRealm (org.mortbay.jetty.security.HashUserRealm)1 SecurityHandler (org.mortbay.jetty.security.SecurityHandler)1