Search in sources :

Example 26 with GroupNotFoundException

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

the class GroupMemberRemoved method execute.

@Override
public void execute(SessionData sessionData, Element command) {
    Element note = command.addElement("note");
    Map<String, List<String>> data = sessionData.getData();
    // Get the group name
    String groupname;
    try {
        groupname = get(data, "groupName", 0);
    } catch (NullPointerException npe) {
        note.addAttribute("type", "error");
        note.setText("Group name required parameter.");
        return;
    }
    // Creates event params.
    Map<String, Object> params = null;
    try {
        // Get the member
        String member = get(data, "member", 0);
        // Adds the member
        params = new HashMap<>();
        params.put("member", member);
    } catch (NullPointerException npe) {
        note.addAttribute("type", "error");
        note.setText("Member required parameter.");
        return;
    }
    // Sends the event
    Group group;
    try {
        group = GroupManager.getInstance().getGroup(groupname, true);
        // Fire event.
        GroupEventDispatcher.dispatchEvent(group, GroupEventDispatcher.EventType.member_removed, params);
    } catch (GroupNotFoundException e) {
        note.addAttribute("type", "error");
        note.setText("Group not found.");
    }
    // Answer that the operation was successful
    note.addAttribute("type", "info");
    note.setText("Operation finished successfully");
}
Also used : Group(org.jivesoftware.openfire.group.Group) Element(org.dom4j.Element) List(java.util.List) GroupNotFoundException(org.jivesoftware.openfire.group.GroupNotFoundException)

Example 27 with GroupNotFoundException

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

the class GroupDeleting method execute.

@Override
public void execute(SessionData sessionData, Element command) {
    Element note = command.addElement("note");
    Map<String, List<String>> data = sessionData.getData();
    // Get the group name
    String groupname;
    try {
        groupname = get(data, "groupName", 0);
    } catch (NullPointerException npe) {
        note.addAttribute("type", "error");
        note.setText("Group name required parameter.");
        return;
    }
    // Sends the event
    Group group;
    try {
        group = GroupManager.getInstance().getGroup(groupname, true);
        // Fire event.
        Map<String, Object> params = Collections.emptyMap();
        GroupEventDispatcher.dispatchEvent(group, GroupEventDispatcher.EventType.group_deleting, params);
    } catch (GroupNotFoundException e) {
        note.addAttribute("type", "error");
        note.setText("Group not found.");
    }
    // Answer that the operation was successful
    note.addAttribute("type", "info");
    note.setText("Operation finished successfully");
}
Also used : Group(org.jivesoftware.openfire.group.Group) Element(org.dom4j.Element) List(java.util.List) GroupNotFoundException(org.jivesoftware.openfire.group.GroupNotFoundException)

Example 28 with GroupNotFoundException

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

the class GroupMemberAdded method execute.

@Override
public void execute(SessionData sessionData, Element command) {
    Element note = command.addElement("note");
    Map<String, List<String>> data = sessionData.getData();
    // Get the group name
    String groupname;
    try {
        groupname = get(data, "groupName", 0);
    } catch (NullPointerException npe) {
        note.addAttribute("type", "error");
        note.setText("Group name required parameter.");
        return;
    }
    // Creates event params.
    Map<String, Object> params = null;
    try {
        // Get the member
        String member = get(data, "member", 0);
        // Adds the member
        params = new HashMap<>();
        params.put("member", member);
    } catch (NullPointerException npe) {
        note.addAttribute("type", "error");
        note.setText("Member required parameter.");
        return;
    }
    // Sends the event
    Group group;
    try {
        group = GroupManager.getInstance().getGroup(groupname, true);
        // Fire event.
        GroupEventDispatcher.dispatchEvent(group, GroupEventDispatcher.EventType.member_added, params);
    } catch (GroupNotFoundException e) {
        note.addAttribute("type", "error");
        note.setText("Group not found.");
    }
    // Answer that the operation was successful
    note.addAttribute("type", "info");
    note.setText("Operation finished successfully");
}
Also used : Group(org.jivesoftware.openfire.group.Group) Element(org.dom4j.Element) List(java.util.List) GroupNotFoundException(org.jivesoftware.openfire.group.GroupNotFoundException)

Example 29 with GroupNotFoundException

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

the class LdapGroupProvider method getGroup.

@Override
public Group getGroup(String groupName) throws GroupNotFoundException {
    LdapContext ctx = null;
    try {
        String groupDN = manager.findGroupDN(groupName);
        // Load record.
        ctx = manager.getContext(manager.getGroupsBaseDN(groupName));
        Attributes attrs = ctx.getAttributes(groupDN, standardAttributes);
        return processGroup(ctx, attrs);
    } catch (Exception e) {
        Log.error(e.getMessage(), e);
        throw new GroupNotFoundException("Group with name " + groupName + " not found.", e);
    } finally {
        try {
            if (ctx != null) {
                ctx.setRequestControls(null);
                ctx.close();
            }
        } catch (Exception ignored) {
        // Ignore.
        }
    }
}
Also used : Attributes(javax.naming.directory.Attributes) GroupNotFoundException(org.jivesoftware.openfire.group.GroupNotFoundException) LdapContext(javax.naming.ldap.LdapContext) NamingException(javax.naming.NamingException) GroupNotFoundException(org.jivesoftware.openfire.group.GroupNotFoundException) UserNotFoundException(org.jivesoftware.openfire.user.UserNotFoundException)

Example 30 with GroupNotFoundException

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

the class LdapManager method findGroupDN.

/**
     * Finds a groups's dn using it's group name. Normally, this search will
     * be performed using the field "cn", but this can be changed by setting
     * the <tt>groupNameField</tt> property.<p>
     *
     * Searches are performed over all subtrees relative to the <tt>baseDN</tt>.
     * If the search fails in the <tt>baseDN</tt> then another search will be
     * performed in the <tt>alternateBaseDN</tt>. For example, if the <tt>baseDN</tt>
     * is "o=jivesoftware, o=com" and we do a search for "managers", then we might
     * find a groupDN of "uid=managers,ou=Groups". This kind of searching is a good
     * thing since it doesn't make the assumption that all user records are stored
     * in a flat structure. However, it does add the requirement that "cn" field
     * (or the other field specified) must be unique over the entire subtree from
     * the <tt>baseDN</tt>. For example, it's entirely possible to create two dn's
     * in your LDAP directory with the same cn: "cn=managers,ou=Financial" and
     * "cn=managers,ou=Engineers". In such a case, it's not possible to
     * uniquely identify a group, so this method will throw an error.<p>
     *
     * The dn that's returned is relative to the default <tt>baseDN</tt>.
     *
     * @param groupname the groupname to lookup the dn for.
     * @param baseDN the base DN to use for this search.
     * @return the dn associated with <tt>groupname</tt>.
     * @throws Exception if the search for the dn fails.
     * @see #findGroupDN(String) to search using the default baseDN and alternateBaseDN.
     */
public String findGroupDN(String groupname, String baseDN) throws Exception {
    boolean debug = Log.isDebugEnabled();
    if (debug) {
        Log.debug("LdapManager: Trying to find a groups's DN based on it's groupname. " + groupNameField + ": " + groupname + ", Base DN: " + baseDN + "...");
    }
    DirContext ctx = null;
    try {
        ctx = getContext(baseDN);
        if (debug) {
            Log.debug("LdapManager: Starting LDAP search...");
        }
        // Search for the dn based on the groupname.
        SearchControls constraints = new SearchControls();
        // If sub-tree searching is enabled (default is true) then search the entire tree.
        if (subTreeSearch) {
            constraints.setSearchScope(SearchControls.SUBTREE_SCOPE);
        } else // Otherwise, only search a single level.
        {
            constraints.setSearchScope(SearchControls.ONELEVEL_SCOPE);
        }
        constraints.setReturningAttributes(new String[] { groupNameField });
        String filter = MessageFormat.format(getGroupSearchFilter(), sanitizeSearchFilter(groupname));
        NamingEnumeration<SearchResult> answer = ctx.search("", filter, constraints);
        if (debug) {
            Log.debug("LdapManager: ... search finished");
        }
        if (answer == null || !answer.hasMoreElements()) {
            if (debug) {
                Log.debug("LdapManager: Group DN based on groupname '" + groupname + "' not found.");
            }
            throw new GroupNotFoundException("Groupname " + groupname + " not found");
        }
        String groupDN = answer.next().getName();
        // The baseDN must be set correctly so that this doesn't happen.
        if (answer.hasMoreElements()) {
            if (debug) {
                Log.debug("LdapManager: Search for groupDN based on groupname '" + groupname + "' found multiple " + "responses, throwing exception.");
            }
            throw new GroupNotFoundException("LDAP groupname lookup for " + groupname + " matched multiple entries.");
        }
        // Close the enumeration.
        answer.close();
        // following code converts a referral back to a "partial" LDAP string.
        if (groupDN.startsWith("ldap://")) {
            groupDN = groupDN.replace("," + baseDN, "");
            groupDN = groupDN.substring(groupDN.lastIndexOf("/") + 1);
            groupDN = java.net.URLDecoder.decode(groupDN, "UTF-8");
        }
        if (encloseGroupDN) {
            groupDN = getEnclosedDN(groupDN);
        }
        return groupDN;
    } catch (Exception e) {
        if (debug) {
            Log.debug("LdapManager: Exception thrown when searching for groupDN based on groupname '" + groupname + "'", e);
        }
        throw e;
    } finally {
        try {
            ctx.close();
        } catch (Exception ignored) {
        // Ignore.
        }
    }
}
Also used : SearchControls(javax.naming.directory.SearchControls) SearchResult(javax.naming.directory.SearchResult) GroupNotFoundException(org.jivesoftware.openfire.group.GroupNotFoundException) InitialDirContext(javax.naming.directory.InitialDirContext) DirContext(javax.naming.directory.DirContext) NamingException(javax.naming.NamingException) GroupNotFoundException(org.jivesoftware.openfire.group.GroupNotFoundException) UserNotFoundException(org.jivesoftware.openfire.user.UserNotFoundException)

Aggregations

GroupNotFoundException (org.jivesoftware.openfire.group.GroupNotFoundException)40 Group (org.jivesoftware.openfire.group.Group)38 Element (org.dom4j.Element)15 JID (org.xmpp.packet.JID)12 ArrayList (java.util.ArrayList)11 List (java.util.List)8 StringTokenizer (java.util.StringTokenizer)6 ServiceException (org.jivesoftware.openfire.plugin.rest.exceptions.ServiceException)5 GroupManager (org.jivesoftware.openfire.group.GroupManager)4 UserNotFoundException (org.jivesoftware.openfire.user.UserNotFoundException)4 GroupJID (org.jivesoftware.openfire.group.GroupJID)3 GroupEntity (org.jivesoftware.openfire.plugin.rest.entity.GroupEntity)3 User (org.jivesoftware.openfire.user.User)3 Presence (org.xmpp.packet.Presence)3 HashMap (java.util.HashMap)2 NamingException (javax.naming.NamingException)2 MUCRole (org.jivesoftware.openfire.muc.MUCRole)2 DataForm (org.xmpp.forms.DataForm)2 FormField (org.xmpp.forms.FormField)2 RemoteException (java.rmi.RemoteException)1