private HashLoginService getLoginService(String pUser, String pPassword, String pRole) { Credential credential = Credential.getCredential(pPassword); HashLoginService loginService = new HashLoginService("jolokia Realm"); loginService.putUser(pUser, credential, new String[] {pRole}); return loginService; }
userStore.addUser(username, Credential.getCredential(password), new String[]{"user"}); HashLoginService l = new HashLoginService(); l.setUserStore(userStore);
String credentials = rs1.getString(_userTablePasswordField); return new JDBCUserPrincipal (username, Credential.getCredential(credentials), key);
roleArray = StringUtil.csvSplit(roles); known.add(username); Credential credential = Credential.getCredential(credentials); addUser(username, credential, roleArray); notifyUpdate(username, credential, roleArray);
protected UserIdentity putUser (String username, String credentials, String[] roles) { return putUser(username, Credential.getCredential(credentials),roles); }
private void putUser(String name, String sisma) { userStore.addUser(name, Credential.getCredential(sisma), new String[]{"user"}); }
@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); } }
private HashLoginService getLoginService(String pUser, String pPassword, String pRole) { Credential credential = Credential.getCredential(pPassword); HashLoginService loginService = new HashLoginService("jolokia Realm"); loginService.putUser(pUser, credential, new String[] {pRole}); return loginService; }
/** Put user into realm. * Called by implementations to put the user data loaded from * file/db etc into the user structure. * @param userName User name * @param info a UserIdentity instance, or a String password or Credential instance * @return User instance */ protected synchronized UserIdentity putUser(String userName, Object info) { final UserIdentity identity; if (info instanceof UserIdentity) identity=(UserIdentity)info; else { Credential credential = (info instanceof Credential)?(Credential)info:Credential.getCredential(info.toString()); Principal userPrincipal = new KnownUser(userName,credential); Subject subject = new Subject(); subject.getPrincipals().add(userPrincipal); subject.getPrivateCredentials().add(credential); subject.setReadOnly(); identity=_identityService.newUserIdentity(subject,userPrincipal,IdentityService.NO_ROLES); } _users.put(userName,identity); return identity; }
@Override protected void loadUsers() throws IOException { for (User user : users) { Credential credential = Credential.getCredential(user.getPassword()); Principal userPrincipal = new AbstractLoginService.UserPrincipal(user.getName(),credential); Subject subject = new Subject(); subject.getPrincipals().add(userPrincipal); subject.getPrivateCredentials().add(credential); String[] roleArray = IdentityService.NO_ROLES; if (user.getRoles() != null && user.getRoles().length > 0) { roleArray = user.getRoles(); } for (String role : roleArray) { subject.getPrincipals().add(new AbstractLoginService.RolePrincipal(role)); } subject.setReadOnly(); getKnownUserIdentities().put(user.getName(), getIdentityService().newUserIdentity(subject, userPrincipal, roleArray)); } } }
public Principal getUserPrincipal() { Credential credential = (credentials instanceof Credential) ? (Credential) credentials : Credential.getCredential(credentials.toString()); return new KnownUser(getX509PrincipalCN(userName), credential); }
@Override public UserIdentity login(String username, Object credentials, ServletRequest request) { try { Credential credential = Credential.getCredential((String) credentials); User user = lookupUser(username, credential); if (user != null) { UserIdentity userIdentity = createUserIdentity(username, credential); AbstractLoginService.UserPrincipal principal = (AbstractLoginService.UserPrincipal) userIdentity.getUserPrincipal(); if (principal.authenticate(credentials)) { bindUserDataToThread(user); ThreadContext.bind(userIdentity.getSubject()); return userIdentity; } } } catch (IResourceStore.ResourceStoreException e) { log.error("Could not process login.", e); } catch (IResourceStore.ResourceNotFoundException e) { //no user entity found for the given username } return null; }
/** * 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; }
@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; }
/** * 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; }
/** * 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; }