/** * Convert the import format to the internal format. * * @param importEntry * The raw imported user. * @return The internal format of the user. */ private UserOrg toUserOrg(final UserOrgEditionVo importEntry) { final UserOrg user = new UserOrg(); importEntry.copy(user); user.setGroups(new ArrayList<>()); final List<String> mails = new ArrayList<>(); CollectionUtils.addIgnoreNull(mails, importEntry.getMail()); user.setMails(mails); return user; }
@Override public UserOrg findById(final String login) { // Always found final UserOrg user = new UserOrg(); user.setId(login); user.setFirstName("First"); user.setLastName("Last"); user.setMails(Collections.singletonList(login + "@sample.com")); user.setDn("CN=" + login); return user; }
@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; }
@Override public void updateUser(final UserOrg user) { final DirContextOperations context = template .lookupContext(org.springframework.ldap.support.LdapUtils.newLdapName(user.getDn())); mapToContext(user, context); template.modifyAttributes(context); // Also, update the cache final UserOrg userLdap = findById(user.getId()); user.copy((SimpleUser) userLdap); userLdap.setMails(user.getMails()); cacheRepository.update(user); }