/** * Convenience method that allows a plain text password credential to be set */ public void setPassword(final String password) { if (password == null) { throw new IllegalArgumentException("Password can not be null."); } this.credential = new Password(password.toCharArray()); }
/** * Convenience method that allows a plain text password credential to be set */ public void setPassword(final String password) { if (password == null) { throw new IllegalArgumentException("Password can not be null."); } this.credential = new Password(password.toCharArray()); }
/** * Convenience method that allows a plain text password credential to be set */ public void setPassword(final String password) { if (password == null) { throw new IllegalArgumentException("Password can not be null."); } this.credential = new Password(password.toCharArray()); }
/** * Validate if the credential provided matches * * @param user * @param password * @return builder implementation */ public void validate(Agent user, String password) { Credentials credential = new UsernamePasswordCredentials(user.getLoginName(), new Password(password)); identityManager.validateCredentials(credential); this.credential = credential; } }
/** * This method creates a new User * * @param user */ @Override public void create(User user, String password) { identityManager.add(user); identityManager.updateCredential(user, new Password(password)); }
public static void setLdapPassword(ProviderSession providerSession, RealmModel realm, String username, String password) { // Update password directly in ldap. It's workaround, but LDIF import doesn't seem to work on windows for ApacheDS try { IdentityManager identityManager = new PicketlinkAuthenticationProvider(providerSession.getProvider(IdentityManagerProvider.class)).getIdentityManager(realm); User user = BasicModel.getUser(identityManager, username); identityManager.updateCredential(user, new Password(password.toCharArray())); } catch (Exception e) { throw new RuntimeException(e); } } }
/** * Reset user' password * * @param user User credential * @param currentPassword current password already registered * @param newPassword new password * @throws Exception */ @Override public void reset(User user, String currentPassword, String newPassword) { credentialMatcher.validate(user, currentPassword); if (credentialMatcher.hasExpired() || credentialMatcher.isValid()) { this.identityManager.updateCredential(user, new Password(newPassword)); } else { throw new AeroGearSecurityException(HttpStatus.PASSWORD_RESET_FAILED); } }
/** * Logs in the specified User. * * @param user represents a simple implementation that holds user's credentials. * @throws org.jboss.aerogear.security.exception.AeroGearSecurityException * on login failure. */ public boolean login(Agent user, String password) { credentials.setUserId(user.getLoginName()); credentials.setCredential(new Password(password)); credentialMatcher.validate(user, password); if (credentialMatcher.hasExpired()) { throw new AeroGearSecurityException(HttpStatus.CREDENTIAL_HAS_EXPIRED); } else if (identity.login() != Identity.AuthenticationResult.SUCCESS) { throw new AeroGearSecurityException(HttpStatus.AUTHENTICATION_FAILED); } return true; }
@Override public User login(String username, String password) { credentials.setUserId(username); credentials.setCredential(new Password(password)); final AuthenticationResult result; try { result = identity.login(); } catch (UserAlreadyLoggedInException ex) { throw new AlreadyLoggedInException("Already logged in as " + ((org.picketlink.idm.model.basic.User) identity.getAccount()).getLoginName()); } catch (RuntimeException ex) { throw new AuthenticationException("An error occurred while authenticating.", ex); } if (result != Identity.AuthenticationResult.SUCCESS) { throw new FailedAuthenticationException(); } final User user = createUser((org.picketlink.idm.model.basic.User) identity.getAccount(), getRolesOfCurrentUser()); return user; }
@Override public User login(String username, String password) { credentials.setUserId(username); credentials.setCredential(new Password(password)); final AuthenticationResult result; try { result = identity.login(); } catch (UserAlreadyLoggedInException ex) { throw new AlreadyLoggedInException("Already logged in as " + ((org.picketlink.idm.model.basic.User) identity.getAccount()).getLoginName()); } catch (RuntimeException ex) { throw new AuthenticationException("An error occurred while authenticating.", ex); } if (result != Identity.AuthenticationResult.SUCCESS) { throw new FailedAuthenticationException(); } final User user = createUser((org.picketlink.idm.model.basic.User) identity.getAccount(), getRolesOfCurrentUser()); return user; }
/** * <p> * Tests a unsuccessful validation. * </p> * * @throws Exception */ @Test public void testUnsuccessfulValidation() throws Exception { IdentityManager identityManager = getIdentityManager(); User user = loadOrCreateUser("someUser", true); Password plainTextPassword = new Password("updated_password".toCharArray()); identityManager.updateCredential(user, plainTextPassword, new Date(), null); UsernamePasswordCredentials badUserName = new UsernamePasswordCredentials(); badUserName.setUsername("Bad" + user.getId()); badUserName.setPassword(plainTextPassword); identityManager.validateCredentials(badUserName); Assert.assertEquals(Status.INVALID, badUserName.getStatus()); UsernamePasswordCredentials badPassword = new UsernamePasswordCredentials(); plainTextPassword = new Password("bad_password".toCharArray()); badPassword.setUsername(user.getId()); badPassword.setPassword(plainTextPassword); identityManager.validateCredentials(badPassword); Assert.assertEquals(Status.INVALID, badPassword.getStatus()); }
/** * <p> * Tests a successful validation. * </p> * * @throws Exception */ @Test public void testSuccessfulValidation() throws Exception { IdentityManager identityManager = getIdentityManager(); User user = loadOrCreateUser("someUser", true); Password plainTextPassword = new Password("updated_password".toCharArray()); identityManager.updateCredential(user, plainTextPassword, new Date(), null); UsernamePasswordCredentials credential = new UsernamePasswordCredentials(); credential.setUsername(user.getId()); credential.setPassword(plainTextPassword); identityManager.validateCredentials(credential); Assert.assertEquals(Status.VALID, credential.getStatus()); }
usernamePasswordCredentials.setPassword(new Password(password.toCharArray())); try { identityManager.validateCredentials(usernamePasswordCredentials);