use of org.mortbay.jetty.security.HashUserRealm in project hudson-2.x by hudson.
the class HudsonTestCase method configureUserRealm.
/**
* Configures a security realm for a test.
*/
protected UserRealm configureUserRealm() {
HashUserRealm realm = new HashUserRealm();
// this is the magic realm name to make it effective on everywhere
realm.setName("default");
realm.put("alice", "alice");
realm.put("bob", "bob");
realm.put("charlie", "charlie");
realm.addUserToRole("alice", "female");
realm.addUserToRole("bob", "male");
realm.addUserToRole("charlie", "male");
return realm;
}
use of org.mortbay.jetty.security.HashUserRealm in project maven-plugins by apache.
the class ProjectInfoReportUtilsTest method startJetty.
private void startJetty(boolean isSSL, boolean withAuth) throws Exception {
jettyServer = new Server();
jettyServer.setStopAtShutdown(true);
Connector connector = (isSSL ? getSSLConnector() : getDefaultConnector());
jettyServer.setConnectors(new Connector[] { connector });
WebAppContext webapp = new WebAppContext();
webapp.setContextPath("/");
webapp.setResourceBase(getBasedir() + "/target/classes/");
webapp.setServer(jettyServer);
if (withAuth) {
Constraint constraint = new Constraint();
constraint.setName(Constraint.__BASIC_AUTH);
constraint.setRoles(new String[] { "user", "admin" });
constraint.setAuthenticate(true);
ConstraintMapping cm = new ConstraintMapping();
cm.setConstraint(constraint);
cm.setPathSpec("/*");
SecurityHandler sh = new SecurityHandler();
sh.setUserRealm(new HashUserRealm("MyRealm", getBasedir() + "/src/test/resources/realm.properties"));
sh.setConstraintMappings(new ConstraintMapping[] { cm });
webapp.addHandler(sh);
}
DefaultHandler defaultHandler = new DefaultHandler();
defaultHandler.setServer(jettyServer);
Handler[] handlers = new Handler[2];
handlers[0] = webapp;
handlers[1] = defaultHandler;
jettyServer.setHandlers(handlers);
jettyServer.start();
port = connector.getLocalPort();
}
use of org.mortbay.jetty.security.HashUserRealm in project sonatype-aether by sonatype.
the class HttpServer method newSecurityHandler.
protected Handler newSecurityHandler() {
List<ConstraintMapping> mappings = new ArrayList<ConstraintMapping>();
for (String pathSpec : securedRealms.keySet()) {
String[] roles = securedRealms.get(pathSpec);
Constraint constraint = new Constraint();
constraint.setName(Constraint.__BASIC_AUTH);
constraint.setRoles(roles);
constraint.setAuthenticate(true);
ConstraintMapping constraintMapping = new ConstraintMapping();
constraintMapping.setConstraint(constraint);
constraintMapping.setPathSpec(pathSpec);
mappings.add(constraintMapping);
}
HashUserRealm userRealm = new HashUserRealm("TestRealm");
for (String username : userPasswords.keySet()) {
String password = userPasswords.get(username);
String[] roles = userRoles.get(username);
userRealm.put(username, password);
if (roles != null) {
for (String role : roles) {
userRealm.addUserToRole(username, role);
}
}
}
SecurityHandler securityHandler = new SecurityHandler();
securityHandler.setUserRealm(userRealm);
securityHandler.setConstraintMappings(mappings.toArray(new ConstraintMapping[mappings.size()]));
return securityHandler;
}
use of org.mortbay.jetty.security.HashUserRealm 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