use of org.eclipse.jetty.security.ConstraintMapping in project camel by apache.
the class HttpBasicAuthTest 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.ConstraintMapping in project cdap by caskdata.
the class AbstractAuthenticationHandler method init.
/**
* Initialize the handler context and other related services.
*/
public void init(Map<String, String> handlerProps) throws Exception {
this.handlerProps = handlerProps;
Constraint constraint = new Constraint();
constraint.setRoles(new String[] { "*" });
constraint.setAuthenticate(true);
if (Boolean.parseBoolean(handlerProps.get(Constants.Security.SSL.EXTERNAL_ENABLED))) {
constraint.setDataConstraint(Constraint.DC_CONFIDENTIAL);
}
ConstraintMapping constraintMapping = new ConstraintMapping();
constraintMapping.setConstraint(constraint);
constraintMapping.setPathSpec("/*");
this.setConstraintMappings(new ConstraintMapping[] { constraintMapping });
this.setStrict(false);
this.setIdentityService(getHandlerIdentityService());
this.setAuthenticator(getHandlerAuthenticator());
this.setLoginService(getHandlerLoginService());
this.doStart();
}
use of org.eclipse.jetty.security.ConstraintMapping in project rest-assured by rest-assured.
the class WithJetty method startJetty.
@BeforeClass
public static void startJetty() throws Exception {
server = new Server();
HttpConfiguration httpConfig = new HttpConfiguration();
httpConfig.setSecureScheme("https");
httpConfig.setSecurePort(8443);
httpConfig.setOutputBufferSize(32768);
ServerConnector http = new ServerConnector(server, new HttpConnectionFactory(httpConfig));
http.setPort(8080);
http.setIdleTimeout(30000);
HttpConfiguration httpsConfig = new HttpConfiguration(httpConfig);
httpsConfig.addCustomizer(new SecureRequestCustomizer());
String file = WithJetty.class.getClassLoader().getResource("jetty_localhost_server.jks").getFile();
SslContextFactory sslContextFactory = new SslContextFactory(file);
sslContextFactory.setKeyStorePassword("test1234");
ServerConnector https = new ServerConnector(server, new SslConnectionFactory(sslContextFactory, HttpVersion.HTTP_1_1.asString()), new HttpConnectionFactory(httpsConfig));
https.setPort(8443);
https.setIdleTimeout(50000);
String canonicalPath = new File(".").getCanonicalPath();
String scalatraPath = "/examples/scalatra-webapp";
// Security config
Constraint constraint = new Constraint();
constraint.setName(Constraint.__BASIC_AUTH);
constraint.setRoles(new String[] { "user", "admin", "moderator" });
constraint.setAuthenticate(true);
ConstraintMapping mapping = new ConstraintMapping();
mapping.setConstraint(constraint);
mapping.setPathSpec("/secured/*");
final String realmPath = scalatraPath + "/etc/realm.properties";
LoginService loginService = new HashLoginService("MyRealm", isExecutedFromMaven(canonicalPath) ? gotoProjectRoot().getCanonicalPath() + realmPath : canonicalPath + realmPath);
server.addBean(loginService);
ConstraintSecurityHandler security = new ConstraintSecurityHandler();
server.setHandler(security);
security.setConstraintMappings(Collections.singletonList(mapping));
security.setAuthenticator(new BasicAuthenticator());
security.setLoginService(loginService);
// End security config
WebAppContext wac = new WebAppContext();
wac.setContextPath("/");
String webAppPath = "/src/main/webapp";
final String scalatraWebAppPath = scalatraPath + webAppPath;
String warPath = isExecutedFromMaven(canonicalPath) ? gotoProjectRoot().getCanonicalPath() + scalatraWebAppPath : canonicalPath + scalatraWebAppPath;
wac.setWar(warPath);
wac.setServer(server);
security.setHandler(wac);
server.setHandler(security);
server.setConnectors(new Connector[] { http, https });
dontSendDateHeader(server);
server.start();
}
use of org.eclipse.jetty.security.ConstraintMapping in project airlift by airlift.
the class HttpServer method createSecurityHandler.
private static SecurityHandler createSecurityHandler(LoginService loginService) {
Constraint constraint = new Constraint();
constraint.setAuthenticate(false);
ConstraintMapping constraintMapping = new ConstraintMapping();
constraintMapping.setConstraint(constraint);
constraintMapping.setPathSpec("/*");
ConstraintSecurityHandler securityHandler = new ConstraintSecurityHandler();
securityHandler.setLoginService(loginService);
// TODO: support for other auth schemes (digest, etc)
securityHandler.setAuthenticator(new BasicAuthenticator());
securityHandler.setConstraintMappings(ImmutableList.of(constraintMapping));
return securityHandler;
}
use of org.eclipse.jetty.security.ConstraintMapping in project zookeeper by apache.
the class JettyAdminServer method constrainTraceMethod.
/**
* Add constraint to a given context to disallow TRACE method
* @param ctxHandler the context to modify
*/
private void constrainTraceMethod(ServletContextHandler ctxHandler) {
Constraint c = new Constraint();
c.setAuthenticate(true);
ConstraintMapping cmt = new ConstraintMapping();
cmt.setConstraint(c);
cmt.setMethod("TRACE");
cmt.setPathSpec("/*");
ConstraintSecurityHandler securityHandler = new ConstraintSecurityHandler();
securityHandler.setConstraintMappings(new ConstraintMapping[] { cmt });
ctxHandler.setSecurityHandler(securityHandler);
}
Aggregations