Search in sources :

Example 1 with GroupProvider

use of org.jivesoftware.openfire.group.GroupProvider in project Openfire by igniterealtime.

the class CrowdAdminProvider method getAdmins.

@Override
public List<JID> getAdmins() {
    List<JID> results = new ArrayList<>();
    GroupProvider provider = GroupManager.getInstance().getProvider();
    String groups = JiveGlobals.getProperty(JIVE_AUTHORIZED_GROUPS);
    groups = (groups == null || groups.trim().length() == 0) ? "" : groups;
    // make sure the property is created
    JiveGlobals.setProperty(JIVE_AUTHORIZED_GROUPS, groups);
    StringTokenizer tokenizer = new StringTokenizer(groups, ",");
    while (tokenizer.hasMoreTokens()) {
        String groupName = tokenizer.nextToken().trim().toLowerCase();
        if (groupName != null && groupName.length() > 0) {
            try {
                LOG.info("Adding admin users from group: " + groupName);
                Group group = provider.getGroup(groupName);
                if (group != null) {
                    results.addAll(group.getMembers());
                }
            } catch (GroupNotFoundException gnfe) {
                LOG.error("Error when trying to load the members of group:" + String.valueOf(groupName), gnfe);
            }
        }
    }
    if (results.isEmpty()) {
        // Add default admin account when none was specified
        results.add(new JID("admin", XMPPServer.getInstance().getServerInfo().getXMPPDomain(), null, true));
    }
    if (LOG.isDebugEnabled()) {
        LOG.debug("admin users: " + results.toString());
    }
    return results;
}
Also used : Group(org.jivesoftware.openfire.group.Group) StringTokenizer(java.util.StringTokenizer) JID(org.xmpp.packet.JID) ArrayList(java.util.ArrayList) GroupNotFoundException(org.jivesoftware.openfire.group.GroupNotFoundException) GroupProvider(org.jivesoftware.openfire.group.GroupProvider)

Aggregations

ArrayList (java.util.ArrayList)1 StringTokenizer (java.util.StringTokenizer)1 Group (org.jivesoftware.openfire.group.Group)1 GroupNotFoundException (org.jivesoftware.openfire.group.GroupNotFoundException)1 GroupProvider (org.jivesoftware.openfire.group.GroupProvider)1 JID (org.xmpp.packet.JID)1