securityHandler.setAuthenticatorFactory(authenticatorFactory); securityHandler.setAuthMethod(Constraint.__BASIC_AUTH); securityHandler.setRealmName(getClass().getSimpleName()); securityHandler.setConstraintMappings(Collections.singletonList(constraintMapping));
csh.setRealmName("myrealm"); csh.addConstraintMapping(healthcheckConstraintMapping); csh.addConstraintMapping(cm);
@Override public void customize(Server server) { LOG.debug("Customizing server to allow requests for {}", USER_AUTHORIZED); HashLoginService login = new HashLoginService(); login.putUser(USER_AUTHORIZED, Credential.getCredential(USER_PW), new String[] {"users"}); login.setName("users"); Constraint constraint = new Constraint(); constraint.setName(Constraint.__BASIC_AUTH); constraint.setRoles(new String[]{"users"}); constraint.setAuthenticate(true); ConstraintMapping cm = new ConstraintMapping(); cm.setConstraint(constraint); cm.setPathSpec("/*"); ConstraintSecurityHandler security = new ConstraintSecurityHandler(); security.setAuthenticator(new BasicAuthenticator()); security.setRealmName("users"); security.addConstraintMapping(cm); security.setLoginService(login); // chain the PQS handler to security security.setHandler(server.getHandlers()[0]); server.setHandler(security); } }
/** * Construct new security handler for basic authentication. */ public SecurityHandler getObject() throws Exception { ConstraintSecurityHandler securityHandler = new ConstraintSecurityHandler(); securityHandler.setAuthenticator(authenticator); securityHandler.setRealmName(realm); for (Entry<String, Constraint> constraint : constraints.entrySet()) { ConstraintMapping constraintMapping = new ConstraintMapping(); constraintMapping.setConstraint(constraint.getValue()); constraintMapping.setPathSpec(constraint.getKey()); securityHandler.addConstraintMapping(constraintMapping); } securityHandler.setLoginService(loginService); return securityHandler; }
@Override protected HandlerWrapper createHandler() { ConstraintSecurityHandler handler = new ConstraintSecurityHandler(); handler.setLoginService(loginServiceConfig.getLoginService()); handler.setRealmName(realmName); handler.setAuthenticator(authenticatorConfig.getAuthenticator()); for (ConstraintMappingConfig constraintMappingConfig : constraintMappings) { handler.addConstraintMapping(constraintMappingConfig.getConstraintMapping()); } return handler; }
private void setupBasicAuth(final ServletContextHandler context, final String pathSpec, final LoginService loginService, String... roles) { Constraint constraint = new Constraint(); constraint.setName(Constraint.__BASIC_AUTH); constraint.setRoles(roles); constraint.setAuthenticate(true); ConstraintMapping cm = new ConstraintMapping(); cm.setConstraint(constraint); cm.setPathSpec(pathSpec); ConstraintSecurityHandler sh = new ConstraintSecurityHandler(); sh.setAuthenticator(new BasicAuthenticator()); sh.setRealmName(TCUserRealm.class.getSimpleName()); sh.setLoginService(loginService); sh.setConstraintMappings(Collections.singletonList(cm)); context.setSecurityHandler(sh); }
private void setupBasicAuth(final ServletContextHandler context, final String pathSpec, final LoginService loginService, String... roles) { Constraint constraint = new Constraint(); constraint.setName(Constraint.__BASIC_AUTH); constraint.setRoles(roles); constraint.setAuthenticate(true); ConstraintMapping cm = new ConstraintMapping(); cm.setConstraint(constraint); cm.setPathSpec(pathSpec); ConstraintSecurityHandler sh = new ConstraintSecurityHandler(); sh.setAuthenticator(new BasicAuthenticator()); sh.setRealmName(TCUserRealm.class.getSimpleName()); sh.setLoginService(loginService); sh.setConstraintMappings(Collections.singletonList(cm)); context.setSecurityHandler(sh); }
@Override protected SecurityHandler createSecurityHandler() { HashLoginService l = new HashLoginService(); for (User user : Users.getUsers()) { String[] roles = user.getRolesAsArray(); if (user.getId().startsWith("admin")) roles = new String[] { "apiuser", "apiadmin"}; l.putUser(user.getId(), Credential.getCredential(user.getPassword()), roles); } l.setName("apimanrealm"); ConstraintSecurityHandler csh = new ConstraintSecurityHandler(); csh.setAuthenticator(new BasicAuthenticator()); csh.setRealmName("apimanrealm"); csh.setLoginService(l); return csh; }
@Override protected SecurityHandler createSecurityHandler() { HashLoginService l = new HashLoginService(); for (User user : Users.getUsers()) { String[] roles = user.getRolesAsArray(); if (user.getId().startsWith("admin")) roles = new String[] { "apiuser", "apiadmin"}; l.putUser(user.getId(), Credential.getCredential(user.getPassword()), roles); } l.setName("apimanrealm"); ConstraintSecurityHandler csh = new ConstraintSecurityHandler(); csh.setAuthenticator(new BasicAuthenticator()); csh.setRealmName("apimanrealm"); csh.setLoginService(l); return csh; }
static ConstraintSecurityHandler createSecurityHandler(String realm, List<String> roles) { final ConstraintSecurityHandler securityHandler = new ConstraintSecurityHandler(); Constraint constraint = new Constraint(); constraint.setAuthenticate(true); constraint.setRoles(roles.toArray(new String[0])); ConstraintMapping constraintMapping = new ConstraintMapping(); constraintMapping.setConstraint(constraint); constraintMapping.setMethod("*"); constraintMapping.setPathSpec("/*"); securityHandler.addConstraintMapping(constraintMapping); securityHandler.setAuthenticator(new BasicAuthenticator()); securityHandler.setLoginService(new JAASLoginService(realm)); securityHandler.setIdentityService(new DefaultIdentityService()); securityHandler.setRealmName(realm); return securityHandler; }
static ConstraintSecurityHandler createSecurityHandler(String realm, List<String> roles) { final ConstraintSecurityHandler securityHandler = new ConstraintSecurityHandler(); Constraint constraint = new Constraint(); constraint.setAuthenticate(true); constraint.setRoles(roles.toArray(new String[0])); ConstraintMapping constraintMapping = new ConstraintMapping(); constraintMapping.setConstraint(constraint); constraintMapping.setMethod("*"); constraintMapping.setPathSpec("/*"); securityHandler.addConstraintMapping(constraintMapping); securityHandler.setAuthenticator(new BasicAuthenticator()); securityHandler.setLoginService(new JAASLoginService(realm)); securityHandler.setIdentityService(new DefaultIdentityService()); securityHandler.setRealmName(realm); return securityHandler; }
protected ConstraintSecurityHandler configureCommonAuthentication(String constraintName, String[] allowedRoles, Authenticator authenticator, String realm, LoginService loginService) { Constraint constraint = new Constraint(); constraint.setName(constraintName); constraint.setRoles(allowedRoles); // This is telling Jetty to not allow unauthenticated requests through (very important!) constraint.setAuthenticate(true); ConstraintMapping cm = new ConstraintMapping(); cm.setConstraint(constraint); cm.setPathSpec("/*"); ConstraintSecurityHandler sh = new ConstraintSecurityHandler(); sh.setAuthenticator(authenticator); sh.setLoginService(loginService); sh.setConstraintMappings(new ConstraintMapping[]{cm}); sh.setRealmName(realm); return sh; }
/** * Creates a basic auth security handler. */ protected SecurityHandler createSecurityHandler() throws Exception { HashLoginService l = new HashLoginService(); for (User user : Users.getUsers()) { l.putUser(user.getId(), Credential.getCredential(user.getPassword()), user.getRolesAsArray()); } l.setName("apimanrealm"); ConstraintSecurityHandler csh = new ConstraintSecurityHandler(); csh.setAuthenticator(new BasicAuthenticator()); csh.setRealmName("apimanrealm"); csh.setLoginService(l); return csh; }
protected ConstraintSecurityHandler configureCommonAuthentication(String constraintName, String[] allowedRoles, Authenticator authenticator, String realm, LoginService loginService) { Constraint constraint = new Constraint(); constraint.setName(constraintName); constraint.setRoles(allowedRoles); // This is telling Jetty to not allow unauthenticated requests through (very important!) constraint.setAuthenticate(true); ConstraintMapping cm = new ConstraintMapping(); cm.setConstraint(constraint); cm.setPathSpec("/*"); ConstraintSecurityHandler sh = new ConstraintSecurityHandler(); sh.setAuthenticator(authenticator); sh.setLoginService(loginService); sh.setConstraintMappings(new ConstraintMapping[]{cm}); sh.setRealmName(realm); return sh; }
private void initAuthentication(String pathSpec, String authName) { authType = authName; Constraint constraint = new Constraint(); if (authName == null) { authName = Constraint.__BASIC_AUTH; } constraint.setName(authName); constraint.setRoles(new String[]{"users"}); constraint.setAuthenticate(true); ConstraintMapping cm = new ConstraintMapping(); cm.setConstraint(constraint); cm.setPathSpec(pathSpec); securityHandler.setRealmName("Test Server"); securityHandler.setAuthMethod(authName); securityHandler.setConstraintMappings(new ConstraintMapping[]{cm}); loginService = new HashLoginService("Test Server"); securityHandler.setLoginService(loginService); webappContext.setSecurityHandler(securityHandler); }
private void initAuthentication(String pathSpec, String authName) { authType = authName; Constraint constraint = new Constraint(); if (authName == null) { authName = Constraint.__BASIC_AUTH; } constraint.setName(authName); constraint.setRoles(new String[]{"users"}); constraint.setAuthenticate(true); ConstraintMapping cm = new ConstraintMapping(); cm.setConstraint(constraint); cm.setPathSpec(pathSpec); securityHandler.setRealmName("Test Server"); securityHandler.setAuthMethod(authName); securityHandler.setConstraintMappings(new ConstraintMapping[]{cm}); loginService = new HashLoginService("Test Server"); securityHandler.setLoginService(loginService); webappContext.setSecurityHandler(securityHandler); }
/** * Creates a basic auth security handler. */ protected SecurityHandler createSecurityHandler() throws Exception { HashLoginService l = new HashLoginService(); UserStore userStore = new UserStore(); l.setUserStore(userStore); for (User user : Users.getUsers()) { userStore.addUser(user.getId(), Credential.getCredential(user.getPassword()), user.getRolesAsArray()); } l.setName("apimanrealm"); ConstraintSecurityHandler csh = new ConstraintSecurityHandler(); csh.setAuthenticator(new BasicAuthenticator()); csh.setRealmName("apimanrealm"); csh.setLoginService(l); return csh; }
/** * Creates a basic auth security handler. * @throws Exception */ protected SecurityHandler createSecurityHandler() throws Exception { HashLoginService l = new HashLoginService(); // UserStore is now separate store entity and must be added to HashLoginService UserStore userStore = new UserStore(); l.setUserStore(userStore); for (User user : Users.getUsers()) { userStore.addUser(user.getId(), Credential.getCredential(user.getPassword()), user.getRolesAsArray()); } l.setName("apimanrealm"); ConstraintSecurityHandler csh = new ConstraintSecurityHandler(); csh.setAuthenticator(new BasicAuthenticator()); csh.setRealmName("apimanrealm"); csh.setLoginService(l); return csh; }
/** * Enables basic HTTP authentication on the server. */ public HttpService basicAuthentication(String username, String password) { HashLoginService l = new HashLoginService(); l.putUser(username, Credential.getCredential(password), new String[]{"user"}); l.setName("test-realm"); Constraint constraint = new Constraint(Constraint.__BASIC_AUTH, "user"); constraint.setAuthenticate(true); ConstraintMapping constraintMapping = new ConstraintMapping(); constraintMapping.setConstraint(constraint); constraintMapping.setPathSpec("/*"); ConstraintSecurityHandler csh = new ConstraintSecurityHandler(); csh.setAuthenticator(new BasicAuthenticator()); csh.setRealmName("test-realm"); csh.addConstraintMapping(constraintMapping); csh.setLoginService(l); this.securityHandler = Optional.of(csh); return this; }
private SecurityHandler getBasicAuth() { UserStore userStore = new UserStore(); userStore.addUser(USERNAME, getCredential(PASSWORD), new String[] {"user"}); HashLoginService l = new HashLoginService(); l.setUserStore(userStore); l.setName("private"); Constraint constraint = new Constraint(); constraint.setName(__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("testRealm"); csh.addConstraintMapping(cm); csh.setLoginService(l); return csh; }