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 = JettyLib.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, 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(Constraint.__BASIC_AUTH, allowedRoles, new BasicAuthenticator(), null, loginService);
}
use of org.eclipse.jetty.security.authentication.BasicAuthenticator 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.authentication.BasicAuthenticator in project EventHub by Codecademy.
the class EventHubHandler method main.
public static void main(String[] args) throws Exception {
Properties properties = new Properties();
properties.load(EventHub.class.getClassLoader().getResourceAsStream("hub.properties"));
properties.load(EventHubHandler.class.getClassLoader().getResourceAsStream("web.properties"));
properties.putAll(System.getProperties());
Injector injector = Guice.createInjector(Modules.override(new DmaIdListModule(), new DatedEventIndexModule(), new ShardedEventIndexModule(), new PropertiesIndexModule(), new UserEventIndexModule(), new EventStorageModule(), new UserStorageModule(), new EventHubModule(properties)).with(new Module()));
final EventHubHandler eventHubHandler = injector.getInstance(EventHubHandler.class);
int port = injector.getInstance(Key.get(Integer.class, Names.named("eventhubhandler.port")));
final Server server = new Server(port);
@SuppressWarnings("ConstantConditions") String webDir = EventHubHandler.class.getClassLoader().getResource("frontend").toExternalForm();
HashLoginService loginService = new HashLoginService();
loginService.putUser(properties.getProperty("eventhubhandler.username"), new Password(properties.getProperty("eventhubhandler.password")), new String[] { "user" });
server.addBean(loginService);
ConstraintSecurityHandler securityHandler = new ConstraintSecurityHandler();
Constraint constraint = new Constraint();
constraint.setName("auth");
constraint.setAuthenticate(true);
constraint.setRoles(new String[] { "user", "admin" });
ConstraintMapping mapping = new ConstraintMapping();
mapping.setPathSpec("/*");
mapping.setConstraint(constraint);
securityHandler.setConstraintMappings(Collections.singletonList(mapping));
securityHandler.setAuthenticator(new BasicAuthenticator());
securityHandler.setLoginService(loginService);
ResourceHandler resourceHandler = new ResourceHandler();
resourceHandler.setDirectoriesListed(false);
resourceHandler.setWelcomeFiles(new String[] { "main.html" });
resourceHandler.setResourceBase(webDir);
HandlerList handlers = new HandlerList();
handlers.setHandlers(new Handler[] { new JsonpCallbackHandler(eventHubHandler), securityHandler });
server.setHandler(handlers);
securityHandler.setHandler(resourceHandler);
server.start();
Runtime.getRuntime().addShutdownHook(new Thread(new Runnable() {
@Override
public void run() {
if (server.isStarted()) {
try {
server.stop();
eventHubHandler.close();
} catch (Exception e) {
e.printStackTrace();
}
}
}
}, "Stop Jetty Hook"));
server.join();
}
use of org.eclipse.jetty.security.authentication.BasicAuthenticator in project Manga by herrlock.
the class JettyServer method createShutdownHandler.
private Handler createShutdownHandler() {
String pwConfig = new File("conf/jetty-users.dsc").getAbsolutePath();
HashLoginService loginService = new HashLoginService("MangaDownloader-Realm", pwConfig);
this.server.addBean(loginService, true);
ConstraintSecurityHandler secHandler = new ConstraintSecurityHandler();
secHandler.setAuthenticator(new BasicAuthenticator());
ConstraintMapping cm = new ConstraintMapping();
final Constraint userConstraint = new Constraint(Constraint.__BASIC_AUTH, "**");
userConstraint.setAuthenticate(true);
cm.setConstraint(userConstraint);
cm.setPathSpec("/shutdown/*");
secHandler.setConstraintMappings(Arrays.asList(cm));
secHandler.setHandler(new ShutdownHandler(SUPER_SECRET_MAGIC_TOKEN_FOR_SHUTDOWN, false, true));
secHandler.setLoginService(loginService);
return secHandler;
}
Aggregations