/** * 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()); }
public String getPassword() { if (credential != null && credential instanceof Password) { Password ptp = (Password) credential; return new String(ptp.getValue()); } return null; }
@Override public void invalidate() { setStatus(Status.INVALID); password.clear(); } }
/** * 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()); }
public String getPassword() { if (credential != null && credential instanceof Password) { Password ptp = (Password) credential; return new String(ptp.getValue()); } return null; }
@Override public void invalidate() { setStatus(Status.INVALID); password.clear(); } }
/** * 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()); }
public String getPassword() { if (credential != null && credential instanceof Password) { Password ptp = (Password) credential; return new String(ptp.getValue()); } return null; }
@Override public void invalidate() { setStatus(Status.INVALID); password.clear(); } }
/** * 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; } }
@Override public CredentialStorage createCredentialStorage(IdentityContext context, Account account, U password, S store, Date effectiveDate, Date expiryDate) { EncodedPasswordStorage hash = new EncodedPasswordStorage(); if (password.getValue() == null || isNullOrEmpty(password.getValue().toString())) { throw MESSAGES.credentialInvalidPassword(); } String rawPassword = new String(password.getValue()); String passwordSalt = generateSalt(); hash.setSalt(passwordSalt); hash.setEncodedHash(this.passwordEncoder.encode(saltPassword(rawPassword, passwordSalt))); if (effectiveDate != null) { hash.setEffectiveDate(effectiveDate); } hash.setExpiryDate(expiryDate); return hash; }
/** * 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)); }
@Override public void update(IdentityContext context, Account account, Password password, LDAPIdentityStore store, Date effectiveDate, Date expiryDate) { if (store.getConfig().isActiveDirectory()) { updateADPassword(account, new String(password.getValue()), store); } else { ModificationItem[] mods = new ModificationItem[1]; try { BasicAttribute mod0 = new BasicAttribute(USER_PASSWORD_ATTRIBUTE, new String(password.getValue())); mods[0] = new ModificationItem(DirContext.REPLACE_ATTRIBUTE, mod0); store.getOperationManager().modifyAttribute(store.getBindingDN(account, true), mod0); } catch (Exception e) { throw new IdentityManagementException("Error updating password.", e); } } }
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); } } }
@Override public CredentialStorage createCredentialStorage(IdentityContext context, Account account, U password, S store, Date effectiveDate, Date expiryDate) { EncodedPasswordStorage hash = new EncodedPasswordStorage(); if (password.getValue() == null || isNullOrEmpty(password.getValue().toString())) { throw MESSAGES.credentialInvalidPassword(); } String rawPassword = new String(password.getValue()); String passwordSalt = generateSalt(); hash.setSalt(passwordSalt); hash.setEncodedHash(this.passwordEncoder.encode(saltPassword(rawPassword, passwordSalt))); if (effectiveDate != null) { hash.setEffectiveDate(effectiveDate); } hash.setExpiryDate(expiryDate); return hash; }
/** * 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); } }
@Override public void update(IdentityContext context, Account account, Password password, LDAPIdentityStore store, Date effectiveDate, Date expiryDate) { if (store.getConfig().isActiveDirectory()) { updateADPassword(account, new String(password.getValue()), store); } else { ModificationItem[] mods = new ModificationItem[1]; try { BasicAttribute mod0 = new BasicAttribute(USER_PASSWORD_ATTRIBUTE, new String(password.getValue())); mods[0] = new ModificationItem(DirContext.REPLACE_ATTRIBUTE, mod0); store.getOperationManager().modifyAttribute(store.getBindingDN(account, true), mod0); } catch (Exception e) { throw new IdentityManagementException("Error updating password.", e); } } }
/** * 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 protected boolean validateCredential(IdentityContext context, final CredentialStorage storage, final V credentials, S store) { EncodedPasswordStorage hash = (EncodedPasswordStorage) storage; if (hash != null) { String rawPassword = new String(credentials.getPassword().getValue()); return this.passwordEncoder.verify(saltPassword(rawPassword, hash.getSalt()), hash.getEncodedHash()); } return false; }