Search in sources :

Example 11 with JID

use of org.xmpp.packet.JID 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)

Example 12 with JID

use of org.xmpp.packet.JID in project Openfire by igniterealtime.

the class CrowdGroupProvider method getGroup.

@Override
public Group getGroup(String name) throws GroupNotFoundException {
    try {
        Cache<String, org.jivesoftware.openfire.crowd.jaxb.Group> groupCache = CacheFactory.createLocalCache(GROUP_CACHE_NAME);
        org.jivesoftware.openfire.crowd.jaxb.Group group = groupCache.get(name);
        if (group == null) {
            group = manager.getGroup(name);
            groupCache.put(name, group);
        }
        Collection<JID> members = getGroupMembers(name);
        Collection<JID> admins = Collections.emptyList();
        return new Group(name, group.description, members, admins);
    } catch (RemoteException re) {
        LOG.error("Failure to load group:" + String.valueOf(name), re);
        throw new GroupNotFoundException(re);
    }
}
Also used : Group(org.jivesoftware.openfire.group.Group) JID(org.xmpp.packet.JID) GroupNotFoundException(org.jivesoftware.openfire.group.GroupNotFoundException) RemoteException(java.rmi.RemoteException)

Example 13 with JID

use of org.xmpp.packet.JID in project Openfire by igniterealtime.

the class AuthenticateUser method execute.

@Override
public void execute(SessionData data, Element command) {
    Element note = command.addElement("note");
    JID account;
    try {
        account = new JID(data.getData().get("accountjid").get(0));
    } catch (NullPointerException ne) {
        note.addAttribute("type", "error");
        note.setText("JID required parameter.");
        return;
    }
    if (!XMPPServer.getInstance().isLocal(account)) {
        note.addAttribute("type", "error");
        note.setText("Cannot authenticate remote user.");
        return;
    }
    String password = data.getData().get("password").get(0);
    // Get requested user
    User user;
    try {
        user = UserManager.getInstance().getUser(account.getNode());
    } catch (UserNotFoundException e) {
        // User not found
        note.addAttribute("type", "error");
        note.setText("User does not exists.");
        return;
    }
    try {
        AuthFactory.authenticate(user.getUsername(), password);
    } catch (UnauthorizedException | ConnectionException | InternalUnauthenticatedException e) {
        // Auth failed
        note.addAttribute("type", "error");
        note.setText("Authentication failed.");
        return;
    }
    // Answer that the operation was successful
    note.addAttribute("type", "info");
    note.setText("Operation finished successfully.");
}
Also used : UserNotFoundException(org.jivesoftware.openfire.user.UserNotFoundException) User(org.jivesoftware.openfire.user.User) JID(org.xmpp.packet.JID) Element(org.dom4j.Element) UnauthorizedException(org.jivesoftware.openfire.auth.UnauthorizedException) InternalUnauthenticatedException(org.jivesoftware.openfire.auth.InternalUnauthenticatedException) ConnectionException(org.jivesoftware.openfire.auth.ConnectionException)

Example 14 with JID

use of org.xmpp.packet.JID in project Openfire by igniterealtime.

the class PacketsNotification method execute.

@Override
public void execute(SessionData data, Element command) {
    boolean presenceEnabled = false;
    boolean messageEnabled = false;
    boolean iqEnabled = false;
    for (String packet_type : data.getData().get("packet_type")) {
        if ("presence".equals(packet_type)) {
            presenceEnabled = true;
        } else if ("iq".equals(packet_type)) {
            iqEnabled = true;
        } else if ("message".equals(packet_type)) {
            messageEnabled = true;
        }
    }
    boolean incoming = "incoming".equals(data.getData().get("direction").get(0));
    boolean processed = "true".equals(data.getData().get("processed").get(0));
    JID componentJID = data.getOwner();
    // Create or update subscription of the component to receive packet notifications
    PacketCopier.getInstance().addSubscriber(componentJID, iqEnabled, messageEnabled, presenceEnabled, incoming, processed);
    // Inform that everything went fine
    Element note = command.addElement("note");
    note.addAttribute("type", "info");
    note.setText("Operation finished successfully");
}
Also used : JID(org.xmpp.packet.JID) Element(org.dom4j.Element)

Example 15 with JID

use of org.xmpp.packet.JID in project Openfire by igniterealtime.

the class AddGroup method execute.

@Override
public void execute(SessionData data, Element command) {
    Element note = command.addElement("note");
    // Check if groups cannot be modified (backend is read-only)
    if (GroupManager.getInstance().isReadOnly()) {
        note.addAttribute("type", "error");
        note.setText("Groups are read only");
        return;
    }
    // Get requested group
    Group group;
    try {
        group = GroupManager.getInstance().createGroup(data.getData().get("group").get(0));
    } catch (GroupAlreadyExistsException e) {
        // Group not found
        note.addAttribute("type", "error");
        note.setText("Group already exists");
        return;
    }
    List<String> desc = data.getData().get("desc");
    if (desc != null && !desc.isEmpty()) {
        group.setDescription(desc.get(0));
    }
    List<String> members = data.getData().get("members");
    boolean withErrors = false;
    if (members != null) {
        Collection<JID> users = group.getMembers();
        for (String user : members) {
            try {
                users.add(new JID(user));
            } catch (Exception e) {
                Log.warn("User not added to group", e);
                withErrors = true;
            }
        }
    }
    String showInRoster = data.getData().get("showInRoster").get(0);
    if ("nobody".equals(showInRoster)) {
        // New group is not a shared group
        group.getProperties().put("sharedRoster.showInRoster", "nobody");
        group.getProperties().put("sharedRoster.displayName", " ");
        group.getProperties().put("sharedRoster.groupList", " ");
    } else {
        // New group is configured as a shared group
        if ("spefgroups".equals(showInRoster)) {
            // Show shared group to other groups
            showInRoster = "onlyGroup";
        }
        List<String> displayName = data.getData().get("displayName");
        List<String> groupList = data.getData().get("groupList");
        if (displayName != null) {
            group.getProperties().put("sharedRoster.showInRoster", showInRoster);
            group.getProperties().put("sharedRoster.displayName", displayName.get(0));
            if (groupList != null) {
                StringBuilder buf = new StringBuilder();
                String sep = "";
                for (String groupName : groupList) {
                    buf.append(sep).append(groupName);
                    sep = ",";
                }
                group.getProperties().put("sharedRoster.groupList", buf.toString());
            }
        } else {
            withErrors = true;
        }
    }
    note.addAttribute("type", "info");
    note.setText("Operation finished" + (withErrors ? " with errors" : " successfully"));
}
Also used : Group(org.jivesoftware.openfire.group.Group) JID(org.xmpp.packet.JID) GroupAlreadyExistsException(org.jivesoftware.openfire.group.GroupAlreadyExistsException) Element(org.dom4j.Element) GroupAlreadyExistsException(org.jivesoftware.openfire.group.GroupAlreadyExistsException)

Aggregations

JID (org.xmpp.packet.JID)330 UserNotFoundException (org.jivesoftware.openfire.user.UserNotFoundException)76 Element (org.dom4j.Element)70 ArrayList (java.util.ArrayList)55 IQ (org.xmpp.packet.IQ)38 Presence (org.xmpp.packet.Presence)38 SQLException (java.sql.SQLException)36 PreparedStatement (java.sql.PreparedStatement)31 Connection (java.sql.Connection)30 Group (org.jivesoftware.openfire.group.Group)30 Date (java.util.Date)28 ResultSet (java.sql.ResultSet)27 Message (org.xmpp.packet.Message)25 GroupJID (org.jivesoftware.openfire.group.GroupJID)23 GroupNotFoundException (org.jivesoftware.openfire.group.GroupNotFoundException)23 NotFoundException (org.jivesoftware.util.NotFoundException)22 Roster (org.jivesoftware.openfire.roster.Roster)21 UnauthorizedException (org.jivesoftware.openfire.auth.UnauthorizedException)20 RosterItem (org.jivesoftware.openfire.roster.RosterItem)19 User (org.jivesoftware.openfire.user.User)17