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;
}
Aggregations