/** * Generate a new password of given user and tag it as secured. The password generation is delegated to the first * password plug-in available. When no plug-in is found, the user is not tagged as secured. * * @param user * The user to update. * @param quiet * Flag to turn-off the possible notification such as mail. * @return The new generated password. When <code>null</code> no password could be generated, and the user is not * tagged as secured. */ protected String updatePassword(final UserOrg user, final boolean quiet) { return applicationContext.getBeansOfType(IPasswordGenerator.class).values().stream().findFirst().map(p -> { // Have to generate a new password final String password = p.generate(user.getId(), quiet); // This user is now secured user.setSecured(true); return password; }).orElse(null); }
@Override public UserOrg doMapFromContext(final DirContextOperations context) { final UserOrg user = new UserOrg(); user.setDn(context.getDn().toString()); user.setLastName(context.getStringAttribute(SN_ATTRIBUTE)); user.setFirstName(context.getStringAttribute(GIVEN_NAME_ATTRIBUTE)); user.setSecured(context.getObjectAttribute(PASSWORD_ATTRIBUTE) != null); user.setId(Normalizer.normalize(context.getStringAttribute(uidAttribute))); // Special and also optional attributes Optional.ofNullable(departmentAttribute).ifPresent(a -> user.setDepartment(context.getStringAttribute(a))); Optional.ofNullable(localIdAttribute).ifPresent(a -> user.setLocalId(context.getStringAttribute(a))); Optional.ofNullable(lockedAttribute).ifPresent(a -> fillLockedData(user, context.getStringAttribute(a))); // Save the normalized CN of the company user.setCompany(toCompany(user.getDn())); if (context.attributeExists(PWD_ACCOUNT_LOCKED_ATTRIBUTE)) { user.setLockedBy(PPOLICY_NAME); user.setLocked(parseLdapDate(context.getStringAttribute(PWD_ACCOUNT_LOCKED_ATTRIBUTE))); } // Save the mails user.setMails( new ArrayList<>(CollectionUtils.emptyIfNull(context.getAttributeSortedStringSet(MAIL_ATTRIBUTE)))); return user; }