/** * @param group * @throws org.apache.directory.fortress.core.CreateException */ Group create(Group group) throws CreateException { LdapConnection ld = null; String nodeDn = getDn(group.getName(), group.getContextId()); try { LOG.debug("create group dn [{}]", nodeDn); Entry myEntry = new DefaultEntry(nodeDn); myEntry.add(SchemaConstants.OBJECT_CLASS_AT, GROUP_OBJ_CLASS); myEntry.add(SchemaConstants.CN_AT, group.getName()); // protocol is required: myEntry.add(GROUP_PROTOCOL_ATTR_IMPL, group.getProtocol()); // type is required: myEntry.add(GlobalIds.TYPE, group.getType().toString()); loadAttrs(group.getMembers(), myEntry, SchemaConstants.MEMBER_AT); loadProperties(group.getProperties(), myEntry, GROUP_PROPERTY_ATTR_IMPL, '='); if (StringUtils.isNotEmpty(group.getDescription())) { myEntry.add(SchemaConstants.DESCRIPTION_AT, group.getDescription()); } ld = getAdminConnection(); add(ld, myEntry); } catch (LdapException e) { String error = "create group node dn [" + nodeDn + "] caught LDAPException=" + e.getMessage(); throw new CreateException(GlobalErrIds.GROUP_ADD_FAILED, error, e); } finally { closeAdminConnection(ld); } return group; }
public void addMembership(Group membership) { if (membership == null) { throw new IllegalArgumentException("Membership to add cannot be null"); } this.memberships.add(membership); membership.getMembers().add(this); }
/** * Deletes a user from all the groups where he/she belongs. The most probable cause for this * request is that the user has been deleted from the system. * * <p>TODO: remove this method and use events isntead. * * @param user the deleted user from the system. */ public void deleteUser(User user) { JID userJID = XMPPServer.getInstance().createJID(user.getUsername(), null); for (Group group : getGroups(userJID)) { if (group.getAdmins().contains(userJID)) { group.getAdmins().remove(userJID); } else { group.getMembers().remove(userJID); } } }
/** * Deletes a user from all the groups where he/she belongs. The most probable cause for this * request is that the user has been deleted from the system. * * @param user the deleted user from the system. */ public void deleteUser(User user) { JID userJID = XmppServer.getInstance().createJID(user.getUsername(), null); for (Group group : getGroups(userJID)) { if (group.getAdmins().contains(userJID)) { if (group.getAdmins().remove(userJID)) { // Remove the group from cache. groupCache.remove(group.getName()); } } else { if (group.getMembers().remove(userJID)) { // Remove the group from cache. groupCache.remove(group.getName()); } } } }
/** * @param group * @return * @throws org.apache.directory.fortress.core.CreateException */ Group update(Group group) throws FinderException, UpdateException { LdapConnection ld = null; String nodeDn = getDn(group.getName(), group.getContextId()); try { LOG.debug("update group dn [{}]", nodeDn); List<Modification> mods = new ArrayList<Modification>(); if (StringUtils.isNotEmpty(group.getDescription())) { mods.add( new DefaultModification( ModificationOperation.REPLACE_ATTRIBUTE, SchemaConstants.DESCRIPTION_AT, group.getDescription())); } if (StringUtils.isNotEmpty(group.getProtocol())) { mods.add( new DefaultModification( ModificationOperation.REPLACE_ATTRIBUTE, GROUP_PROTOCOL_ATTR_IMPL, group.getProtocol())); } loadAttrs(group.getMembers(), mods, SchemaConstants.MEMBER_AT); loadProperties(group.getProperties(), mods, GROUP_PROPERTY_ATTR_IMPL, true, '='); if (mods.size() > 0) { ld = getAdminConnection(); modify(ld, nodeDn, mods, group); } } catch (LdapException e) { String error = "update group node dn [" + nodeDn + "] caught LDAPException=" + e.getMessage(); throw new UpdateException(GlobalErrIds.GROUP_UPDATE_FAILED, error, e); } finally { closeAdminConnection(ld); } return get(group); }