use of org.eclipse.jetty.security.ConstraintSecurityHandler in project camel by apache.
the class JettyTestServer method basicAuth.
private SecurityHandler basicAuth(String username, String password, String realm) {
HashLoginService l = new HashLoginService();
l.putUser(username, Credential.getCredential(password), new String[] { "user" });
l.setName(realm);
Constraint constraint = new Constraint();
constraint.setName(Constraint.__BASIC_AUTH);
constraint.setRoles(new String[] { "user" });
constraint.setAuthenticate(true);
ConstraintMapping cm = new ConstraintMapping();
cm.setConstraint(constraint);
cm.setPathSpec("/*");
ConstraintSecurityHandler csh = new ConstraintSecurityHandler();
csh.setAuthenticator(new BasicAuthenticator());
csh.setRealmName("myrealm");
csh.addConstraintMapping(cm);
csh.setLoginService(l);
return csh;
}
use of org.eclipse.jetty.security.ConstraintSecurityHandler in project camel by apache.
the class HttpAuthMethodPriorityTest method getSecurityHandler.
private SecurityHandler getSecurityHandler() throws IOException {
Constraint constraint = new Constraint(Constraint.__BASIC_AUTH, "user");
constraint.setAuthenticate(true);
ConstraintMapping cm = new ConstraintMapping();
cm.setPathSpec("/*");
cm.setConstraint(constraint);
ConstraintSecurityHandler sh = new ConstraintSecurityHandler();
sh.setAuthenticator(new BasicAuthenticator());
sh.setConstraintMappings(Arrays.asList(new ConstraintMapping[] { cm }));
HashLoginService loginService = new HashLoginService("MyRealm", "src/test/resources/myRealm.properties");
sh.setLoginService(loginService);
sh.setConstraintMappings(Arrays.asList(new ConstraintMapping[] { cm }));
return sh;
}
use of org.eclipse.jetty.security.ConstraintSecurityHandler in project jetty.project by eclipse.
the class ServletContextHandlerTest method testFindContainer.
@Test
public void testFindContainer() throws Exception {
ContextHandlerCollection contexts = new ContextHandlerCollection();
_server.setHandler(contexts);
ServletContextHandler root = new ServletContextHandler(contexts, "/", ServletContextHandler.SESSIONS);
SessionHandler session = root.getSessionHandler();
ServletHandler servlet = root.getServletHandler();
SecurityHandler security = new ConstraintSecurityHandler();
root.setSecurityHandler(security);
_server.start();
assertEquals(root, AbstractHandlerContainer.findContainerOf(_server, ContextHandler.class, session));
assertEquals(root, AbstractHandlerContainer.findContainerOf(_server, ContextHandler.class, security));
assertEquals(root, AbstractHandlerContainer.findContainerOf(_server, ContextHandler.class, servlet));
}
use of org.eclipse.jetty.security.ConstraintSecurityHandler in project jetty.project by eclipse.
the class DigestPostTest method setUpServer.
@BeforeClass
public static void setUpServer() {
try {
_server = new Server();
_server.setConnectors(new Connector[] { new ServerConnector(_server) });
ServletContextHandler context = new ServletContextHandler(ServletContextHandler.SECURITY);
context.setContextPath("/test");
context.addServlet(PostServlet.class, "/");
TestLoginService realm = new TestLoginService("test");
realm.putUser("testuser", new Password("password"), new String[] { "test" });
_server.addBean(realm);
ConstraintSecurityHandler security = (ConstraintSecurityHandler) context.getSecurityHandler();
security.setAuthenticator(new DigestAuthenticator());
security.setLoginService(realm);
Constraint constraint = new Constraint("SecureTest", "test");
constraint.setAuthenticate(true);
ConstraintMapping mapping = new ConstraintMapping();
mapping.setConstraint(constraint);
mapping.setPathSpec("/*");
security.setConstraintMappings(Collections.singletonList(mapping));
HandlerCollection handlers = new HandlerCollection();
handlers.setHandlers(new Handler[] { context, new DefaultHandler() });
_server.setHandler(handlers);
_server.start();
} catch (final Exception e) {
e.printStackTrace();
}
}
use of org.eclipse.jetty.security.ConstraintSecurityHandler in project jetty.project by eclipse.
the class HttpClientAuthenticationTest method start.
private void start(Authenticator authenticator, Handler handler) throws Exception {
server = new Server();
File realmFile = MavenTestingUtils.getTestResourceFile("realm.properties");
LoginService loginService = new HashLoginService(realm, realmFile.getAbsolutePath());
server.addBean(loginService);
ConstraintSecurityHandler securityHandler = new ConstraintSecurityHandler();
Constraint constraint = new Constraint();
constraint.setAuthenticate(true);
//allow any authenticated user
constraint.setRoles(new String[] { "**" });
ConstraintMapping mapping = new ConstraintMapping();
mapping.setPathSpec("/secure");
mapping.setConstraint(constraint);
securityHandler.addConstraintMapping(mapping);
securityHandler.setAuthenticator(authenticator);
securityHandler.setLoginService(loginService);
securityHandler.setHandler(handler);
start(securityHandler);
}
Aggregations