userStore.addUser(username, Credential.getCredential(password), new String[]{"user"}); HashLoginService l = new HashLoginService(); l.setUserStore(userStore); l.setName(realm);
/** Create a Jetty {@link SecurityHandler} for basic authentication. * See {@linkplain #addPathConstraint(ConstraintSecurityHandler, String)} * for adding the {@code pathspec} to apply it to. */ public static ConstraintSecurityHandler makeSecurityHandler(String realm, UserStore userStore, String role, AuthScheme authMode) { // role can be "**" for any authenticated user. Objects.requireNonNull(userStore); Objects.requireNonNull(role); if ( authMode == null ) authMode = dftAuthMode; ConstraintSecurityHandler securityHandler = new ConstraintSecurityHandler(); IdentityService identService = new DefaultIdentityService(); securityHandler.setIdentityService(identService); // ---- HashLoginService HashLoginService loginService = new HashLoginService(realm); loginService.setUserStore(userStore); loginService.setIdentityService(identService); securityHandler.setLoginService(loginService); securityHandler.setAuthenticator( authMode == AuthScheme.BASIC ? new BasicAuthenticator() : new DigestAuthenticator() ); if ( realm != null ) securityHandler.setRealmName(realm); return securityHandler; }
/** Create a Jetty {@link SecurityHandler} for basic authentication. * See {@linkplain #addPathConstraint(ConstraintSecurityHandler, String)} * for adding the {@code pathspec} to apply it to. */ public static ConstraintSecurityHandler makeSecurityHandler(String realm, UserStore userStore, String role, AuthScheme authMode) { // role can be "**" for any authenticated user. Objects.requireNonNull(userStore); Objects.requireNonNull(role); if ( authMode == null ) authMode = dftAuthMode; ConstraintSecurityHandler securityHandler = new ConstraintSecurityHandler(); IdentityService identService = new DefaultIdentityService(); securityHandler.setIdentityService(identService); // ---- HashLoginService HashLoginService loginService = new HashLoginService(realm); loginService.setUserStore(userStore); loginService.setIdentityService(identService); securityHandler.setLoginService(loginService); securityHandler.setAuthenticator( authMode == AuthScheme.BASIC ? new BasicAuthenticator() : new DigestAuthenticator() ); if ( realm != null ) securityHandler.setRealmName(realm); return securityHandler; }
UserStore userStore = new UserStore(); HashLoginService loginService = new HashLoginService(); loginService.setUserStore(userStore); userStore.addUser("oshai", new Password("oshai"), new String[]{"user"}); securityHandler.setLoginService(loginService);
/** * Creates a basic auth security handler. */ private SecurityHandler createSecurityHandler() { HashLoginService l = new HashLoginService(); UserStore userStore = new UserStore(); l.setUserStore(userStore); for (String [] userInfo : TestUsers.USERS) { String user = userInfo[0]; String pwd = userInfo[1]; String[] roles = new String[] { "apiuser" }; if (user.startsWith("admin")) { roles = new String[] { "apiuser", "apiadmin"}; } userStore.addUser(user, Credential.getCredential(pwd), roles); } l.setName("apimanrealm"); ConstraintSecurityHandler csh = new ConstraintSecurityHandler(); csh.setAuthenticator(new BasicAuthenticator()); csh.setRealmName("apimanrealm"); csh.setLoginService(l); return csh; }
/** * Configures a security realm for a test. */ protected LoginService configureUserRealm() { HashLoginService realm = new HashLoginService(); realm.setName("default"); // this is the magic realm name to make it effective on everywhere UserStore userStore = new UserStore(); realm.setUserStore( userStore ); userStore.addUser("alice", new Password("alice"), new String[]{"user","female"}); userStore.addUser("bob", new Password("bob"), new String[]{"user","male"}); userStore.addUser("charlie", new Password("charlie"), new String[]{"user","male"}); return realm; }
/** * Configures a security realm for a test. */ protected LoginService configureUserRealm() { HashLoginService realm = new HashLoginService(); realm.setName("default"); // this is the magic realm name to make it effective on everywhere UserStore userStore = new UserStore(); realm.setUserStore( userStore ); userStore.addUser("alice", new Password("alice"), new String[]{"user","female"}); userStore.addUser("bob", new Password("bob"), new String[]{"user","male"}); userStore.addUser("charlie", new Password("charlie"), new String[]{"user","male"}); return realm; }
private void configureServer(Server server, WebAuthConfig authConfig, Handler servletHandler) throws BaleenException { Handler serverHandler; if (authConfig == null || authConfig.getType() == AuthType.NONE) { LOGGER.warn("No security applied to API"); // No security serverHandler = servletHandler; } else if (authConfig.getType() == AuthType.BASIC) { // Basic authentication LOGGER.info("Using Basic HTTP authentication for API"); HashLoginService loginService = new HashLoginService(authConfig.getName()); UserStore userStore = new UserStore(); for (WebUser user : authConfig.getUsers()) { Credential credential = Credential.getCredential(user.getPassword()); userStore.addUser(user.getUsername(), credential, user.getRolesAsArray()); } loginService.setUserStore(userStore); server.addBean(loginService); ConstraintSecurityHandler securityHandler = new ConstraintSecurityHandler(); securityHandler.setHandler(servletHandler); securityHandler.setConstraintMappings(constraintMappings); securityHandler.setAuthenticator(new BasicAuthenticator()); securityHandler.setLoginService(loginService); serverHandler = securityHandler; } else { throw new InvalidParameterException("Configuration of authentication failed"); } server.setHandler(serverHandler); }
private void configureServer(Server server, WebAuthConfig authConfig, Handler servletHandler) throws BaleenException { Handler serverHandler; if (authConfig == null || authConfig.getType() == AuthType.NONE) { LOGGER.warn("No security applied to API"); // No security serverHandler = servletHandler; } else if (authConfig.getType() == AuthType.BASIC) { // Basic authentication LOGGER.info("Using Basic HTTP authentication for API"); HashLoginService loginService = new HashLoginService(authConfig.getName()); UserStore userStore = new UserStore(); for (WebUser user : authConfig.getUsers()) { Credential credential = Credential.getCredential(user.getPassword()); userStore.addUser(user.getUsername(), credential, user.getRolesAsArray()); } loginService.setUserStore(userStore); server.addBean(loginService); ConstraintSecurityHandler securityHandler = new ConstraintSecurityHandler(); securityHandler.setHandler(servletHandler); securityHandler.setConstraintMappings(constraintMappings); securityHandler.setAuthenticator(new BasicAuthenticator()); securityHandler.setLoginService(loginService); serverHandler = securityHandler; } else { throw new InvalidParameterException("Configuration of authentication failed"); } server.setHandler(serverHandler); }
loginService.setUserStore(new UserStore()); this.server.addBean(loginService);
/** * 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; }
public BasicAuth() { HashLoginService loginService = new HashLoginService(); UserStore userStore = new UserStore(); Credential credential = Credential.getCredential(Main.configuration.password); String[] roles = new String[]{"user"}; userStore.addUser(Main.configuration.username, credential, roles); loginService.setUserStore(userStore); loginService.setName(Main.configuration.realm); Constraint constraint = new Constraint(); constraint.setName(Constraint.__BASIC_AUTH); constraint.setRoles(new String[]{"user"}); constraint.setAuthenticate(true); ConstraintMapping cm = new ConstraintMapping(); cm.setConstraint(constraint); cm.setPathSpec("/*"); // Configure this ConstraintSecurityHandler: setAuthenticator(new BasicAuthenticator()); setRealmName("myrealm"); addConstraintMapping(cm); setLoginService(loginService); } }
loginService.setUserStore(userStore); loginService.setIdentityService(identService) ;
loginService.setUserStore(userStore); loginService.setIdentityService(identService) ;
loginService.setUserStore(userStore); loginService.setIdentityService(identService) ;
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; }