+ protected void prepare(UserDirectoryWorkingCopy wc) {
+ // delete
+ for (LdapName dn : wc.getDeletedUsers().keySet()) {
+ if (users.containsKey(dn))
+ users.remove(dn);
+ else if (groups.containsKey(dn))
+ groups.remove(dn);
+ else
+ throw new UserDirectoryException("User to delete not found " + dn);
+ }
+ // add
+ for (LdapName dn : wc.getNewUsers().keySet()) {
+ DirectoryUser user = wc.getNewUsers().get(dn);
+ if (users.containsKey(dn) || groups.containsKey(dn))
+ throw new UserDirectoryException("User to create found " + dn);
+ else if (Role.USER == user.getType())
+ users.put(dn, user);
+ else if (Role.GROUP == user.getType())
+ groups.put(dn, (DirectoryGroup) user);
+ else
+ throw new UserDirectoryException("Unsupported role type " + user.getType() + " for new user " + dn);
+ }
+ // modify
+ for (LdapName dn : wc.getModifiedUsers().keySet()) {
+ Attributes modifiedAttrs = wc.getModifiedUsers().get(dn);
+ DirectoryUser user;
+ if (users.containsKey(dn))
+ user = users.get(dn);
+ else if (groups.containsKey(dn))
+ user = groups.get(dn);
+ else
+ throw new UserDirectoryException("User to modify no found " + dn);
+ user.publishAttributes(modifiedAttrs);
+ }