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);
}
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");
}
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;
}
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;
}
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);
}
Aggregations