Search in sources :

Example 6 with XMPPServer

use of org.jivesoftware.openfire.XMPPServer in project Openfire by igniterealtime.

the class STUNService method startSTUNService.

private void startSTUNService() {
    XMPPServer server = XMPPServer.getInstance();
    // Register the STUN feature in disco.
    server.getIQDiscoInfoHandler().addServerFeature(NAMESPACE);
    // Add an IQ handler.
    stunIQHandler = new STUNIQHandler();
    server.getIQRouter().addHandler(stunIQHandler);
}
Also used : XMPPServer(org.jivesoftware.openfire.XMPPServer)

Example 7 with XMPPServer

use of org.jivesoftware.openfire.XMPPServer in project Openfire by igniterealtime.

the class UserCreationPlugin method generateMessages.

public void generateMessages() {
    JiveGlobals.setProperty("conversation.maxTimeDebug", String.valueOf(DEFAULT_MAX_TIME_DEBUG));
    XMPPServer server = XMPPServer.getInstance();
    ExecutorService taskExecutor = Executors.newFixedThreadPool(8);
    for (User user : UserManager.getInstance().getUsers()) {
        final JID userJid = server.createJID(user.getUsername(), null);
        System.out.println("Creating messages for user: " + userJid.getNode());
        for (RosterItem ri : user.getRoster().getRosterItems()) {
            final JID rosterItemJid = ri.getJid();
            taskExecutor.execute(new Runnable() {

                @Override
                public void run() {
                    for (int j = 0; j < NUMBER_CONVERSATION; j++) {
                        String thread = RandomStringUtils.randomAlphanumeric(6);
                        for (int i = 0; i < NUMBER_MESSAGES; i++) {
                            if (i % 2 == 0) {
                                Message msg = new Message();
                                msg.setBody("Hello to " + rosterItemJid.getNode() + " from " + userJid.getNode() + ", conversation number " + j + " of " + NUMBER_CONVERSATION + ", message " + i + " of " + NUMBER_MESSAGES + " thread " + thread);
                                msg.setType(Message.Type.chat);
                                msg.setFrom(userJid);
                                msg.setTo(rosterItemJid);
                                msg.setThread(thread);
                                XMPPServer.getInstance().getMessageRouter().route(msg);
                                try {
                                    /* otherwise monitoring plugin stores messages out of order */
                                    Thread.sleep(1);
                                } catch (InterruptedException e) {
                                    e.printStackTrace();
                                }
                            } else {
                                Message msg = new Message();
                                msg.setBody("Hello to " + userJid.getNode() + " from " + rosterItemJid.getNode() + ", conversation number " + j + " of " + NUMBER_CONVERSATION + ", message " + i + " of " + NUMBER_MESSAGES + " thread " + thread);
                                msg.setType(Message.Type.chat);
                                msg.setFrom(rosterItemJid);
                                msg.setTo(userJid);
                                msg.setThread(thread);
                                XMPPServer.getInstance().getMessageRouter().route(msg);
                                try {
                                    /* otherwise monitoring plugin stores messages out of order */
                                    Thread.sleep(1);
                                } catch (InterruptedException e) {
                                    e.printStackTrace();
                                }
                            }
                        }
                        try {
                            Thread.sleep(DEFAULT_MAX_TIME_DEBUG);
                        } catch (InterruptedException e) {
                            e.printStackTrace();
                        }
                    }
                }
            });
        }
    }
    taskExecutor.shutdown();
    try {
        taskExecutor.awaitTermination(2, TimeUnit.HOURS);
        System.out.println("Conversation generation finished");
    } catch (InterruptedException e) {
        e.printStackTrace();
    }
    JiveGlobals.deleteProperty("conversation.maxTimeDebug");
}
Also used : RosterItem(org.jivesoftware.openfire.roster.RosterItem) XMPPServer(org.jivesoftware.openfire.XMPPServer) User(org.jivesoftware.openfire.user.User) JID(org.xmpp.packet.JID) Message(org.xmpp.packet.Message) ExecutorService(java.util.concurrent.ExecutorService)

Example 8 with XMPPServer

use of org.jivesoftware.openfire.XMPPServer in project Openfire by igniterealtime.

the class LdapGroupProvider method getGroupNames.

@Override
public Collection<String> getGroupNames(JID user) {
    // Get DN of specified user
    XMPPServer server = XMPPServer.getInstance();
    String username;
    if (!manager.isPosixMode()) {
        // Check if the user exists (only if user is a local user)
        if (!server.isLocal(user)) {
            return Collections.emptyList();
        }
        username = JID.unescapeNode(user.getNode());
        try {
            final String relativePart = Arrays.stream(manager.findUserRDN(username)).map(Rdn::toString).collect(Collectors.joining(","));
            username = relativePart + "," + manager.getUsersBaseDN(username);
        } catch (Exception e) {
            Log.error("Could not find user in LDAP " + username);
            return Collections.emptyList();
        }
    } else {
        username = server.isLocal(user) ? JID.unescapeNode(user.getNode()) : user.toString();
    }
    // Do nothing if the user is empty or null
    if (username == null || "".equals(username)) {
        return Collections.emptyList();
    }
    Set<String> groupNames = new LinkedHashSet<>(search(manager.getGroupMemberField(), username));
    if (manager.isFlattenNestedGroups()) {
        // search groups that contain the given groups
        Set<String> checkedGroups = new HashSet<>();
        Deque<String> todo = new ArrayDeque<>(groupNames);
        String group;
        while (null != (group = todo.pollFirst())) {
            if (checkedGroups.contains(group)) {
                continue;
            }
            checkedGroups.add(group);
            try {
                // get the DN of the group
                LdapName groupDN = manager.findGroupAbsoluteDN(group);
                if (manager.isPosixMode()) {
                    // in posix mode we need to search for the "uid" of the group.
                    List<String> uids = manager.retrieveAttributeOf(manager.getUsernameField(), groupDN);
                    if (uids.isEmpty()) {
                        // group not there or has not the "uid" attribute
                        continue;
                    }
                    group = uids.get(0);
                } else {
                    group = groupDN.toString();
                }
                // search for groups that have the given group (DN normal, UID posix) as member
                Collection<String> containingGroupNames = search(manager.getGroupMemberField(), group);
                // add the found groups to the result and to the groups to be checked transitively
                todo.addAll(containingGroupNames);
                groupNames.addAll(containingGroupNames);
            } catch (Exception e) {
                Log.warn("Error looking up group: {}", group);
            }
        }
    }
    return groupNames;
}
Also used : LinkedHashSet(java.util.LinkedHashSet) XMPPServer(org.jivesoftware.openfire.XMPPServer) NamingException(javax.naming.NamingException) GroupNotFoundException(org.jivesoftware.openfire.group.GroupNotFoundException) UserNotFoundException(org.jivesoftware.openfire.user.UserNotFoundException) ArrayDeque(java.util.ArrayDeque) HashSet(java.util.HashSet) LinkedHashSet(java.util.LinkedHashSet) LdapName(javax.naming.ldap.LdapName)

Example 9 with XMPPServer

use of org.jivesoftware.openfire.XMPPServer in project Openfire by igniterealtime.

the class RosterAccess method canSubscribe.

@Override
public boolean canSubscribe(Node node, JID owner, JID subscriber) {
    // Let node owners and sysadmins always subscribe to the node
    if (node.isAdmin(owner)) {
        return true;
    }
    for (JID nodeOwner : node.getOwners()) {
        if (nodeOwner.equals(owner)) {
            return true;
        }
    }
    // Check that the subscriber is a local user
    XMPPServer server = XMPPServer.getInstance();
    if (server.isLocal(owner)) {
        GroupManager gMgr = GroupManager.getInstance();
        Collection<String> nodeGroups = node.getRosterGroupsAllowed();
        for (String groupName : nodeGroups) {
            try {
                Group group = gMgr.getGroup(groupName);
                // access allowed if the node group is visible to the subscriber
                if (server.getRosterManager().isGroupVisible(group, owner)) {
                    return true;
                }
            } catch (GroupNotFoundException gnfe) {
            // ignore
            }
        }
    } else {
        // Subscriber is a remote user. This should never happen.
        Log.warn("Node with access model Roster has a remote user as subscriber: {}", node.getUniqueIdentifier());
    }
    return false;
}
Also used : Group(org.jivesoftware.openfire.group.Group) XMPPServer(org.jivesoftware.openfire.XMPPServer) JID(org.xmpp.packet.JID) GroupNotFoundException(org.jivesoftware.openfire.group.GroupNotFoundException) GroupManager(org.jivesoftware.openfire.group.GroupManager)

Example 10 with XMPPServer

use of org.jivesoftware.openfire.XMPPServer in project Openfire by igniterealtime.

the class LocaleUtils method getPluginResourceBundle.

/**
 * Retrieve the <code>ResourceBundle</code> that is used with this plugin.
 *
 * @param pluginName the name of the plugin.
 * @return the ResourceBundle used with this plugin.
 * @throws Exception thrown if an exception occurs.
 */
public static ResourceBundle getPluginResourceBundle(String pluginName) throws Exception {
    final Locale locale = JiveGlobals.getLocale();
    String i18nFile = getI18nFile(pluginName);
    // Retrieve classloader from pluginName.
    final XMPPServer xmppServer = XMPPServer.getInstance();
    PluginManager pluginManager = xmppServer.getPluginManager();
    Plugin plugin = pluginManager.getPlugin(pluginName);
    if (plugin == null) {
        throw new NullPointerException("Plugin could not be located.");
    }
    ClassLoader pluginClassLoader = pluginManager.getPluginClassloader(plugin);
    return ResourceBundle.getBundle(i18nFile, locale, pluginClassLoader);
}
Also used : Locale(java.util.Locale) PluginManager(org.jivesoftware.openfire.container.PluginManager) XMPPServer(org.jivesoftware.openfire.XMPPServer) Plugin(org.jivesoftware.openfire.container.Plugin)

Aggregations

XMPPServer (org.jivesoftware.openfire.XMPPServer)27 JID (org.xmpp.packet.JID)11 UserNotFoundException (org.jivesoftware.openfire.user.UserNotFoundException)8 GroupNotFoundException (org.jivesoftware.openfire.group.GroupNotFoundException)5 NamingException (javax.naming.NamingException)3 LdapName (javax.naming.ldap.LdapName)3 Group (org.jivesoftware.openfire.group.Group)3 User (org.jivesoftware.openfire.user.User)3 Presence (org.xmpp.packet.Presence)3 PrintWriter (java.io.PrintWriter)2 Locale (java.util.Locale)2 TreeSet (java.util.TreeSet)2 Matcher (java.util.regex.Matcher)2 Pattern (java.util.regex.Pattern)2 NamingEnumeration (javax.naming.NamingEnumeration)2 Attribute (javax.naming.directory.Attribute)2 Attributes (javax.naming.directory.Attributes)2 SearchControls (javax.naming.directory.SearchControls)2 SearchResult (javax.naming.directory.SearchResult)2 Plugin (org.jivesoftware.openfire.container.Plugin)2