Search in sources :

Example 51 with User

use of org.jivesoftware.openfire.user.User in project Openfire by igniterealtime.

the class SimpleSession method sendNotify.

public void sendNotify(Dialog dialog) throws ParseException, SipException, InvalidArgumentException {
    Request notifyRequest = prepareNotifyRequest(dialog);
    try {
        User me = XMPPServer.getInstance().getUserManager().getUser(getJID().getNode());
        Presence myPresence = XMPPServer.getInstance().getPresenceManager().getPresence(me);
        String presenceContent;
        SimplePresence simplePresence = new SimplePresence();
        simplePresence.setEntity("pres:" + registration.getUsername() + "@" + sipHost);
        simplePresence.setDmNote(myPresence.getStatus());
        if (myPresence.getStatus() != null && myPresence.getStatus().equalsIgnoreCase("Offline"))
            simplePresence.setTupleStatus(SimplePresence.TupleStatus.CLOSED);
        else {
            simplePresence.setTupleStatus(SimplePresence.TupleStatus.OPEN);
            if (myPresence.getShow() != null) {
                switch(myPresence.getShow()) {
                    case away:
                        simplePresence.setRpid(SimplePresence.Rpid.AWAY);
                        break;
                    case dnd:
                        simplePresence.setRpid(SimplePresence.Rpid.BUSY);
                        break;
                    case xa:
                        simplePresence.setRpid(SimplePresence.Rpid.AWAY);
                        break;
                    default:
                        break;
                }
            }
        }
        presenceContent = simplePresence.toXML();
        ContentTypeHeader contentTypeHeader = headerFactory.createContentTypeHeader("application", "pidf+xml");
        notifyRequest.setContent(presenceContent, contentTypeHeader);
    } catch (Exception e) {
        Log.debug("Unable to include presence details in the packet.", e);
    }
    sendRequest(notifyRequest, ListeningPoint.UDP, dialog);
}
Also used : User(org.jivesoftware.openfire.user.User) ContentTypeHeader(javax.sip.header.ContentTypeHeader) Request(javax.sip.message.Request) Presence(org.xmpp.packet.Presence) InvalidArgumentException(javax.sip.InvalidArgumentException) ParseException(java.text.ParseException) NotFoundException(org.jivesoftware.util.NotFoundException) TooManyListenersException(java.util.TooManyListenersException) SipException(javax.sip.SipException) UserNotFoundException(org.jivesoftware.openfire.user.UserNotFoundException)

Example 52 with User

use of org.jivesoftware.openfire.user.User in project Openfire by igniterealtime.

the class ConfigManager method savePermissions.

/**
     * Saves permissions settings from web interface.
     *
     * We validate all of the groups before actually adding them.
     *
     * @param transportName Name of the transport to have it's options saved (type of transport)
     * @param overallSetting The general "all(1), some(2), or none(3)" setting for the permissions.
     * @param users List of specific users that have access.
     * @param groups List of specific groups that have access.
     * @param strict Strict permissions associted with setting.
     * @return List of usernames and groups (@ preceded) that were rejected.
     */
public List<String> savePermissions(String transportName, Integer overallSetting, List<String> users, List<String> groups, Boolean strict) {
    JiveGlobals.setProperty("plugin.gateway." + transportName + ".registration", overallSetting.toString());
    JiveGlobals.setProperty("plugin.gateway." + transportName + ".registrationstrict", strict ? "true" : "false");
    PermissionManager permissionManager = new PermissionManager(TransportType.valueOf(transportName));
    List<String> errorList = new ArrayList<String>();
    ArrayList<User> userList = new ArrayList<User>();
    UserManager userManager = UserManager.getInstance();
    for (String username : users) {
        if (username.matches("\\s*")) {
            continue;
        }
        try {
            if (username.contains("@")) {
                JID jid = new JID(username);
                if (!jid.getDomain().equals(XMPPServer.getInstance().getServerInfo().getXMPPDomain())) {
                    throw new UserNotFoundException();
                }
                username = username.substring(0, username.indexOf("@"));
            }
            User user = userManager.getUser(username);
            if (user == null || user.getUsername() == null) {
                throw new UserNotFoundException();
            }
            userList.add(user);
        } catch (UserNotFoundException e) {
            Log.warn("User " + username + " not found while adding access rules.");
            errorList.add(username);
        }
    }
    permissionManager.storeUserList(userList);
    ArrayList<Group> groupList = new ArrayList<Group>();
    GroupManager groupManager = GroupManager.getInstance();
    for (String grpname : groups) {
        if (grpname.matches("\\s*")) {
            continue;
        }
        try {
            Group group = groupManager.getGroup(grpname);
            if (group == null || group.getName() == null) {
                throw new GroupNotFoundException();
            }
            groupList.add(group);
        } catch (GroupNotFoundException e) {
            Log.warn("Group " + grpname + " not found while adding access rules.");
            errorList.add("@" + grpname);
        }
    }
    permissionManager.storeGroupList(groupList);
    return errorList;
}
Also used : UserNotFoundException(org.jivesoftware.openfire.user.UserNotFoundException) Group(org.jivesoftware.openfire.group.Group) User(org.jivesoftware.openfire.user.User) JID(org.xmpp.packet.JID) PermissionManager(net.sf.kraken.permissions.PermissionManager) ArrayList(java.util.ArrayList) GroupManager(org.jivesoftware.openfire.group.GroupManager) UserManager(org.jivesoftware.openfire.user.UserManager) GroupNotFoundException(org.jivesoftware.openfire.group.GroupNotFoundException)

Example 53 with User

use of org.jivesoftware.openfire.user.User in project Openfire by igniterealtime.

the class PresencePlugin method getPresence.

/**
     * Returns the presence of the requested user or <tt>null</tt> if the user is offline. If
     * presences are not public then the user presence will be returned if and only if the sender
     * of the request is subscribed to the user presence.
     *
     * @param sender the bare JID of the user making the request.
     * @param jid the bare JID of the entity whose presence is being probed.
     * @return the presence of the requested user.
     * @throws UserNotFoundException If presences are not public and the sender is null or the
     *         sender cannot probe the presence of the requested user. Or if the requested user
     *         does not exist in the local server.
     */
public Presence getPresence(String sender, String jid) throws UserNotFoundException {
    if (jid == null) {
        throw new UserNotFoundException("Target JID not found in request");
    }
    JID targetJID = new JID(jid);
    // Check that the sender is not requesting information of a remote server entity
    if (targetJID.getDomain() == null || XMPPServer.getInstance().isRemote(targetJID)) {
        throw new UserNotFoundException("Domain does not matches local server domain");
    }
    if (!hostname.equals(targetJID.getDomain())) {
        // Sender is requesting information about component presence, so we send a 
        // presence probe to the component.
        presenceManager.probePresence(componentJID, targetJID);
        // Wait 30 seconds until we get the probe presence result
        int count = 0;
        Presence presence = probedPresence.get(jid);
        while (presence == null) {
            if (count > 300) {
                // After 30 seconds, timeout
                throw new UserNotFoundException("Request for component presence has timed-out.");
            }
            try {
                Thread.sleep(100);
            } catch (InterruptedException e) {
            // don't care!
            }
            presence = probedPresence.get(jid);
            count++;
        }
        // Clean-up probe presence result
        probedPresence.remove(jid);
        // Return component presence
        return presence;
    }
    if (targetJID.getNode() == null || !UserManager.getInstance().isRegisteredUser(targetJID.getNode())) {
        // Sender is requesting presence information of an anonymous user
        throw new UserNotFoundException("Username is null");
    }
    if (!isPresencePublic()) {
        if (sender == null) {
            throw new UserNotFoundException("Sender is null");
        } else {
            //  If sender is same as target, then we can see ourselves
            JID senderJID = new JID(sender);
            if (!senderJID.getNode().equals(targetJID.getNode()) && !presenceManager.canProbePresence(new JID(sender), targetJID.getNode())) {
                throw new UserNotFoundException("Sender is not allowed to probe this user");
            }
        }
    }
    User user = userManager.getUser(targetJID.getNode());
    return presenceManager.getPresence(user);
}
Also used : UserNotFoundException(org.jivesoftware.openfire.user.UserNotFoundException) User(org.jivesoftware.openfire.user.User) JID(org.xmpp.packet.JID) Presence(org.xmpp.packet.Presence)

Example 54 with User

use of org.jivesoftware.openfire.user.User in project Openfire by igniterealtime.

the class TextPresenceProvider method sendInfo.

@Override
public void sendInfo(HttpServletRequest request, HttpServletResponse response, Presence presence) throws IOException {
    response.setContentType("text/plain");
    PrintWriter out = response.getWriter();
    if (presence == null) {
        // Recreate the unavailable presence with the last known status
        JID targetJID = new JID(request.getParameter("jid"));
        presence = new Presence(Presence.Type.unavailable);
        XMPPServer server = XMPPServer.getInstance();
        try {
            User user = server.getUserManager().getUser(targetJID.getNode());
            String status = server.getPresenceManager().getLastPresenceStatus(user);
            if (status != null) {
                presence.setStatus(status);
            } else {
                presence.setStatus(JiveGlobals.getProperty("plugin.presence.unavailable.status", "Unavailable"));
            }
        } catch (UserNotFoundException e) {
        }
        presence.setFrom(targetJID);
    }
    out.println(presence.getStatus());
    out.flush();
}
Also used : UserNotFoundException(org.jivesoftware.openfire.user.UserNotFoundException) XMPPServer(org.jivesoftware.openfire.XMPPServer) User(org.jivesoftware.openfire.user.User) JID(org.xmpp.packet.JID) Presence(org.xmpp.packet.Presence) PrintWriter(java.io.PrintWriter)

Example 55 with User

use of org.jivesoftware.openfire.user.User in project Openfire by igniterealtime.

the class XMLPresenceProvider method sendInfo.

@Override
public void sendInfo(HttpServletRequest request, HttpServletResponse response, Presence presence) throws IOException {
    response.setContentType("text/xml");
    PrintWriter out = response.getWriter();
    if (presence == null) {
        // Recreate the unavailable presence with the last known status
        JID targetJID = new JID(request.getParameter("jid"));
        presence = new Presence(Presence.Type.unavailable);
        XMPPServer server = XMPPServer.getInstance();
        try {
            User user = server.getUserManager().getUser(targetJID.getNode());
            String status = server.getPresenceManager().getLastPresenceStatus(user);
            if (status != null) {
                presence.setStatus(status);
            } else {
                presence.setStatus(JiveGlobals.getProperty("plugin.presence.unavailable.status", "Unavailable"));
            }
        } catch (UserNotFoundException e) {
        }
        presence.setFrom(targetJID);
    }
    out.println(presence.toXML());
    out.flush();
}
Also used : UserNotFoundException(org.jivesoftware.openfire.user.UserNotFoundException) XMPPServer(org.jivesoftware.openfire.XMPPServer) User(org.jivesoftware.openfire.user.User) JID(org.xmpp.packet.JID) Presence(org.xmpp.packet.Presence) PrintWriter(java.io.PrintWriter)

Aggregations

User (org.jivesoftware.openfire.user.User)58 UserNotFoundException (org.jivesoftware.openfire.user.UserNotFoundException)26 Element (org.dom4j.Element)17 JID (org.xmpp.packet.JID)17 UserManager (org.jivesoftware.openfire.user.UserManager)10 ArrayList (java.util.ArrayList)9 Group (org.jivesoftware.openfire.group.Group)9 IQ (org.xmpp.packet.IQ)7 List (java.util.List)6 UserAlreadyExistsException (org.jivesoftware.openfire.user.UserAlreadyExistsException)6 RosterItem (org.jivesoftware.openfire.roster.RosterItem)5 Date (java.util.Date)4 GroupNotFoundException (org.jivesoftware.openfire.group.GroupNotFoundException)4 Message (org.xmpp.packet.Message)4 Presence (org.xmpp.packet.Presence)4 HashSet (java.util.HashSet)3 StringTokenizer (java.util.StringTokenizer)3 UnauthorizedException (org.jivesoftware.openfire.auth.UnauthorizedException)3 ByteArrayInputStream (java.io.ByteArrayInputStream)2 FileInputStream (java.io.FileInputStream)2