Beispiel #1
0
  /**
   * Deletes a group from the system.
   *
   * @param group the group to delete.
   */
  public void deleteGroup(Group group) {
    Map<String, Object> emptyMap = new HashMap<String, Object>();

    // Fire event.
    GroupEventDispatcher.dispatchEvent(
        group, GroupEventDispatcher.EventType.group_deleting, emptyMap);

    // Delete the group.
    provider.deleteGroup(group.getName());

    // Expire cache.
    groupCache.remove(group.getName());
  }
Beispiel #2
0
 /**
  * Factory method for creating a new Group. A unique name is the only required field.
  *
  * @param name the new and unique name for the group.
  * @return a new Group.
  * @throws GroupAlreadyExistsException if the group name already exists in the system.
  */
 public Group createGroup(String name) throws GroupAlreadyExistsException {
   synchronized (name.intern()) {
     Group newGroup;
     try {
       getGroup(name);
       // The group already exists since now exception, so:
       throw new GroupAlreadyExistsException();
     } catch (GroupNotFoundException unfe) {
       // The group doesn't already exist so we can create a new group
       newGroup = provider.createGroup(name);
       // Update caches.
       groupCache.put(name, newGroup);
       Map<String, Object> emptyMap = new HashMap<String, Object>();
       // Fire event.
       GroupEventDispatcher.dispatchEvent(
           newGroup, GroupEventDispatcher.EventType.group_created, emptyMap);
     }
     return newGroup;
   }
 }
Beispiel #3
0
  private GroupManager() {
    // Initialize caches.
    groupCache = CacheFactory.createCache("Group");

    // A cache for meta-data around groups: count, group names, groups associated with
    // a particular user
    groupMetaCache = CacheFactory.createCache("Group Metadata Cache");

    initProvider();

    GroupEventDispatcher.addListener(
        new IGroupEventListener() {
          public void groupCreated(Group group, Map<String, Object> params) {

            // Adds default properties if they don't exists, since the creator of
            // the group could set them.
            if (group.getProperties().get("sharedRoster.showInRoster") == null) {
              group.getProperties().put("sharedRoster.showInRoster", "nobody");
              group.getProperties().put("sharedRoster.displayName", "");
              group.getProperties().put("sharedRoster.groupList", "");
            }

            // Since the group could be created by the provider, add it possible again
            groupCache.put(group.getName(), group);

            groupMetaCache.clear();
          }

          public void groupDeleting(Group group, Map<String, Object> params) {
            // Since the group could be deleted by the provider, remove it possible again
            groupCache.remove(group.getName());

            groupMetaCache.clear();
          }

          public void groupModified(Group group, Map<String, Object> params) {
            String type = (String) params.get("type");
            // If shared group settings changed, expire the cache.
            if (type != null
                && (type.equals("propertyModified")
                    || type.equals("propertyDeleted")
                    || type.equals("propertyAdded"))) {
              if (params.get("propertyKey") != null
                  && params.get("propertyKey").equals("sharedRoster.showInRoster")) {
                groupMetaCache.clear();
              }
            }
            // Set object again in cache. This is done so that other cluster nodes
            // get refreshed with latest version of the object
            groupCache.put(group.getName(), group);
          }

          public void memberAdded(Group group, Map<String, Object> params) {
            groupMetaCache.clear();
            // Set object again in cache. This is done so that other cluster nodes
            // get refreshed with latest version of the object
            groupCache.put(group.getName(), group);
          }

          public void memberRemoved(Group group, Map<String, Object> params) {
            groupMetaCache.clear();
            // Set object again in cache. This is done so that other cluster nodes
            // get refreshed with latest version of the object
            groupCache.put(group.getName(), group);
          }

          public void adminAdded(Group group, Map<String, Object> params) {
            groupMetaCache.clear();
            // Set object again in cache. This is done so that other cluster nodes
            // get refreshed with latest version of the object
            groupCache.put(group.getName(), group);
          }

          public void adminRemoved(Group group, Map<String, Object> params) {
            groupMetaCache.clear();
            // Set object again in cache. This is done so that other cluster nodes
            // get refreshed with latest version of the object
            groupCache.put(group.getName(), group);
          }
        });

    UserEventDispatcher.addListener(
        new IUserEventListener() {
          public void userCreated(User user, Map<String, Object> params) {
            // ignore
          }

          public void userDeleting(User user, Map<String, Object> params) {
            deleteUser(user);
          }

          public void userModified(User user, Map<String, Object> params) {
            // ignore
          }
        });

    // Detect when a new auth provider class is set
    PropertyEventListener propListener =
        new PropertyEventListener() {
          public void propertySet(String property, Map<String, Object> params) {
            if ("provider.group.className".equals(property)) {
              initProvider();
            }
          }

          public void propertyDeleted(String property, Map<String, Object> params) {
            // Ignore
          }

          public void xmlPropertySet(String property, Map<String, Object> params) {
            // Ignore
          }

          public void xmlPropertyDeleted(String property, Map<String, Object> params) {
            // Ignore
          }
        };
    PropertyEventDispatcher.addListener(propListener);

    // Pre-load shared groups. This will provide a faster response
    // time to the first client that logs in.
    Runnable task =
        new Runnable() {
          public void run() {
            Collection<Group> groups = getSharedGroups();
            // Load each group into cache.
            for (Group group : groups) {
              // Load each user in the group into cache.
              for (JID jid : group.getMembers()) {
                try {
                  if (XmppServer.getInstance().isLocal(jid)) {
                    UserManager.getInstance().getUser(jid.getNode());
                  }
                } catch (UserNotFoundException unfe) {
                  // Ignore.
                }
              }
            }
          }
        };
    TaskEngine.getInstance().submit(task);
  }