use of org.eclipse.jetty.util.security.Constraint 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.util.security.Constraint 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.util.security.Constraint 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;
}
use of org.eclipse.jetty.util.security.Constraint in project alluxio by Alluxio.
the class WebServer method disableMethod.
/**
* @param method to disable
*/
private void disableMethod(String method) {
Constraint constraint = new Constraint();
constraint.setAuthenticate(true);
constraint.setName("Disable " + method);
ConstraintMapping disableMapping = new ConstraintMapping();
disableMapping.setConstraint(constraint);
disableMapping.setMethod(method.toUpperCase());
disableMapping.setPathSpec("/");
mSecurityHandler.addConstraintMapping(disableMapping);
}
use of org.eclipse.jetty.util.security.Constraint 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;
}
Aggregations