use of org.eclipse.jetty.security.authentication.BasicAuthenticator in project jena by apache.
the class FusekiTestAuth method makeSimpleSecurityHandler.
/** Create a Jetty {@link SecurityHandler} for basic authentication, one user/password/role. */
public static SecurityHandler makeSimpleSecurityHandler(String pathSpec, String realm, String user, String password, String role) {
Objects.requireNonNull(user);
Objects.requireNonNull(password);
Objects.requireNonNull(role);
Constraint constraint = new Constraint();
constraint.setName(Constraint.__BASIC_AUTH);
String[] roles = new String[] { role };
constraint.setRoles(roles);
constraint.setAuthenticate(true);
ConstraintMapping mapping = new ConstraintMapping();
mapping.setConstraint(constraint);
mapping.setPathSpec("/*");
IdentityService identService = new DefaultIdentityService();
ConstraintSecurityHandler securityHandler = new ConstraintSecurityHandler();
securityHandler.addConstraintMapping(mapping);
securityHandler.setIdentityService(identService);
UserStore userStore = makeUserStore(user, password, role);
HashLoginService loginService = new HashLoginService("Fuseki Authentication");
loginService.setUserStore(userStore);
loginService.setIdentityService(identService);
securityHandler.setLoginService(loginService);
securityHandler.setAuthenticator(new BasicAuthenticator());
if (realm != null)
securityHandler.setRealmName(realm);
return securityHandler;
}
use of org.eclipse.jetty.security.authentication.BasicAuthenticator in project calcite-avatica by apache.
the class HttpServer method configureBasicAuthentication.
protected ConstraintSecurityHandler configureBasicAuthentication(Server server, ServerConnector connector, AvaticaServerConfiguration config) {
final String[] allowedRoles = config.getAllowedRoles();
final String realm = config.getHashLoginServiceRealm();
final String loginServiceProperties = config.getHashLoginServiceProperties();
HashLoginService loginService = new HashLoginService(realm, loginServiceProperties);
server.addBean(loginService);
return configureCommonAuthentication(server, connector, config, Constraint.__BASIC_AUTH, allowedRoles, new BasicAuthenticator(), null, loginService);
}
use of org.eclipse.jetty.security.authentication.BasicAuthenticator in project camel by apache.
the class HttpBasicAuthComponentConfiguredTest 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.authentication.BasicAuthenticator 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.authentication.BasicAuthenticator 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();
}
Aggregations