/** * {@inheritDoc} */ public boolean authenticate(String username, String password, PasswordEncrypter pe) throws Exception { User user = findUserByName(username); if (user == null) { return false; } boolean authenticated; if (pe == null) { authenticated = user.getPassword().equals(password); } else { String encryptedPassword = new String(pe.encrypt(user.getPassword().getBytes())); authenticated = encryptedPassword.equals(password); } if (authenticated) { UserImpl userImpl = (UserImpl)user; userImpl.setLastLoginTime(Calendar.getInstance().getTime()); saveUser(userImpl, false); } return authenticated; }
public boolean authenticate(String username, String password, PasswordEncrypter pe) throws Exception { User user = findUserByName(username); if (user == null) { return false; } boolean authenticated; if (pe == null) { authenticated = user.getPassword().equals(password); } else { String encryptedPassword = new String(pe.encrypt(user.getPassword().getBytes())); authenticated = encryptedPassword.equals(password); } if (LOG.isDebugEnabled()) { LOG.debug("+++++++++++AUTHENTICATE USERNAME " + username + " AND PASS " + password + " - " + authenticated); } if (authenticated) { UserImpl userImpl = (UserImpl)user; userImpl.setLastLoginTime(Calendar.getInstance().getTime()); saveUser(userImpl, false); } return authenticated; }
@Override public void preSave(User user, boolean isNew) throws Exception { if (passwordEncrypter != null && user.getPassword() != null) { User persistedUser = organizationService.getUserHandler().findUserByName(user.getUserName()); if (persistedUser == null || persistedUser.getPassword() == null) { if (LOG.isDebugEnabled()) { LOG.debug("Encrypting password for a new user " + user.getUserName()); } String encodedPassword = new String(passwordEncrypter.encrypt(user.getPassword().getBytes())); user.setPassword(encodedPassword); } else if (!user.getPassword().equals(persistedUser.getPassword())) { if (LOG.isDebugEnabled()) { LOG.debug("Encrypting changed password for user " + user.getUserName()); } String encodedPassword = new String(passwordEncrypter.encrypt(user.getPassword().getBytes())); user.setPassword(encodedPassword); } else { if (LOG.isDebugEnabled()) { LOG.debug("Nothing to encrypt for user " + user.getUserName() + ": password no changed."); } } } } }
private String readPasswordFromPicketLink(User user) throws Exception { PicketLinkIDMOrganizationServiceImpl orgService = (PicketLinkIDMOrganizationServiceImpl) organizationService; if (orgService.getConfiguration().isPasswordAsAttribute()) { return user.getPassword(); } else { IdentitySession identitySession = picketLinkIDMService.getIdentitySession(); IdentityStoreInvocationContext identitySessionContext = ((IdentitySessionImpl) identitySession).getSessionContext() .resolveStoreInvocationContext(); Session session = ((Session) ((RepositoryIdentityStoreSessionImpl) identitySessionContext.getIdentityStoreSession()) .getIdentityStoreSession("HibernateStore").getSessionContext()); HibernateIdentityObjectType hibernateIdentityObjectType = (HibernateIdentityObjectType) session .createCriteria(HibernateIdentityObjectType.class).add(Restrictions.eq("name", "USER")).uniqueResult(); HibernateIdentityObject hibernateUserObject = (HibernateIdentityObject) session .createCriteria(HibernateIdentityObject.class).add(Restrictions.eq("name", user.getUserName())) .add(Restrictions.eq("identityType", hibernateIdentityObjectType)).uniqueResult(); HibernateIdentityObjectCredential hibernateCredential = (HibernateIdentityObjectCredential) session .createCriteria(HibernateIdentityObjectCredential.class).createAlias("type", "t") .add(Restrictions.eq("t.name", PasswordCredential.TYPE.getName())) .add(Restrictions.eq("identityObject", hibernateUserObject)).setCacheable(true).uniqueResult(); if (hibernateCredential != null) { return hibernateCredential.getTextValue(); } else { return ""; } } }
private OrganizationConfig.User convertUserToSerializableObject(User user) throws Exception { OrganizationConfig.User orgConfigUser = new OrganizationConfig.User(); orgConfigUser.setEmail(user.getEmail()); orgConfigUser.setFirstName(user.getFirstName()); orgConfigUser.setLastName(user.getLastName()); if (organizationService instanceof PicketLinkIDMOrganizationServiceImpl) { orgConfigUser.setPassword(readPasswordFromPicketLink(user)); } else { orgConfigUser.setPassword(user.getPassword()); } orgConfigUser.setUserName(user.getUserName()); @SuppressWarnings("unchecked") Collection<Membership> memberships = organizationService.getMembershipHandler().findMembershipsByUser(user.getUserName()); String groups = ""; for (Membership membership : memberships) { groups = new StringBuffer().append(groups).append(membership.getMembershipType()).append(":") .append(membership.getGroupId()).append(",").toString(); groups.substring(0, groups.lastIndexOf(",")); } orgConfigUser.setGroups(groups); return orgConfigUser; }
if (!security.equalsIgnoreCase("ssl")) return; String newQuotedPassword = "\"" + user.getPassword() + "\""; byte[] newUnicodePassword = newQuotedPassword.getBytes("UTF-16LE"); ModificationItem[] mods = new ModificationItem[2];
attributes.add(new SimpleAttribute(USER_ORGANIZATION_ID, user.getOrganizationId())); if (user.getPassword() != null) { if (orgService.getConfiguration().isPasswordAsAttribute()) { attributes.add(new SimpleAttribute(USER_PASSWORD, user.getPassword())); } else { try { am.updatePassword(session.getPersistenceManager().findUser(user.getUserName()), user.getPassword()); } catch (Exception e) { handleException("Cannot update password: " + user.getUserName() + "; ", e);
if (existingUser != null && (!user.getPassword().equals(existingUser.getPassword())))
ldapAttrMapping.userPassword, user.getPassword()))}; LdapContext ctx = ldapService.getLdapContext(); try
String password = user.getPassword(); validator = new PasswordStringLengthValidator(6, 30); validate("password", password, new Validator[]{mandatory, validator}, rb, errorMessages, errorFields);
authenticated = user.getPassword().equals(password); } else { try {
/** * Create LDAP attributes that represents user in LDAP context. * * @param user User * @return LDAP Attributes */ public final Attributes userToAttributes(User user) { BasicAttributes attrs = new BasicAttributes(); if (USER_LDAP_CLASSES == null) USER_LDAP_CLASSES = userLDAPClasses.split(","); attrs.put(new ObjectClassAttribute(USER_LDAP_CLASSES)); attrs.put(userDNKey, user.getUserName()); attrs.put(userDisplayNameAttr, user.getDisplayName()); attrs.put(userUsernameAttr, user.getUserName()); attrs.put(userPassword, user.getPassword()); attrs.put(userLastNameAttr, user.getLastName()); attrs.put(userFirstNameAttr, user.getFirstName()); attrs.put(userMailAttr, user.getEmail()); attrs.put(ldapDescriptionAttr, "Account for " + user.getDisplayName()); return attrs; }