Search in sources :

Example 41 with Roster

use of org.jivesoftware.openfire.roster.Roster in project Openfire by igniterealtime.

the class PEPService method canProbePresence.

/**
 * Returns true if the the prober is allowed to see the presence of the probee.
 *
 * @param prober the user that is trying to probe the presence of another user.
 * @param probee the username of the uset that is being probed.
 * @return true if the the prober is allowed to see the presence of the probee.
 * @throws UserNotFoundException If the probee does not exist in the local server or the prober
 *         is not present in the roster of the probee.
 */
private boolean canProbePresence(JID prober, JID probee) throws UserNotFoundException {
    Roster roster;
    roster = XMPPServer.getInstance().getRosterManager().getRoster(prober.getNode());
    RosterItem item = roster.getRosterItem(probee);
    return item.getSubStatus() == RosterItem.SUB_BOTH || item.getSubStatus() == RosterItem.SUB_FROM;
}
Also used : RosterItem(org.jivesoftware.openfire.roster.RosterItem) Roster(org.jivesoftware.openfire.roster.Roster)

Example 42 with Roster

use of org.jivesoftware.openfire.roster.Roster in project Openfire by igniterealtime.

the class PresenceAccess method canSubscribe.

@Override
public boolean canSubscribe(Node node, JID owner, JID subscriber) {
    // Let node owners and sysadmins always subcribe to the node
    if (node.isAdmin(owner)) {
        return true;
    }
    XMPPServer server = XMPPServer.getInstance();
    for (JID nodeOwner : node.getOwners()) {
        // Give access to the owner of the roster :)
        if (nodeOwner.equals(owner)) {
            return true;
        }
        // Check that the node owner is a local user
        if (server.isLocal(nodeOwner)) {
            try {
                Roster roster = server.getRosterManager().getRoster(nodeOwner.getNode());
                RosterItem item = roster.getRosterItem(owner);
                // Check that the subscriber is subscribe to the node owner's presence
                return item != null && (RosterItem.SUB_BOTH == item.getSubStatus() || RosterItem.SUB_FROM == item.getSubStatus());
            } catch (UserNotFoundException e) {
            // Do nothing
            }
        } else {
            // Owner of the node is a remote user. This should never happen.
            Log.warn("Node with access model Presence has a remote user as owner: {}", node.getUniqueIdentifier());
        }
    }
    return false;
}
Also used : UserNotFoundException(org.jivesoftware.openfire.user.UserNotFoundException) RosterItem(org.jivesoftware.openfire.roster.RosterItem) XMPPServer(org.jivesoftware.openfire.XMPPServer) JID(org.xmpp.packet.JID) Roster(org.jivesoftware.openfire.roster.Roster)

Aggregations

Roster (org.jivesoftware.openfire.roster.Roster)42 RosterItem (org.jivesoftware.openfire.roster.RosterItem)29 UserNotFoundException (org.jivesoftware.openfire.user.UserNotFoundException)27 JID (org.xmpp.packet.JID)20 UserAlreadyExistsException (org.jivesoftware.openfire.user.UserAlreadyExistsException)13 SharedGroupException (org.jivesoftware.openfire.SharedGroupException)9 ArrayList (java.util.ArrayList)7 StringTokenizer (java.util.StringTokenizer)4 PacketException (org.jivesoftware.openfire.PacketException)4 UnauthorizedException (org.jivesoftware.openfire.auth.UnauthorizedException)4 ServiceException (org.jivesoftware.openfire.plugin.rest.exceptions.ServiceException)4 Presence (org.xmpp.packet.Presence)4 NotFoundException (org.jivesoftware.util.NotFoundException)3 IQ (org.xmpp.packet.IQ)3 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)2 Email (net.sf.jml.Email)2 XMPPServer (org.jivesoftware.openfire.XMPPServer)2 ServiceException (org.jivesoftware.openfire.exceptions.ServiceException)2 Group (org.jivesoftware.openfire.group.Group)2 PacketRejectedException (org.jivesoftware.openfire.interceptor.PacketRejectedException)2