use of org.jivesoftware.openfire.XMPPServer in project Openfire by igniterealtime.
the class FileTransferProxy method startProxy.
private void startProxy() {
connectionManager.processConnections(bindInterface, getProxyPort());
routingTable.addComponentRoute(getAddress(), this);
XMPPServer server = XMPPServer.getInstance();
server.getIQDiscoItemsHandler().addServerItemsProvider(this);
}
use of org.jivesoftware.openfire.XMPPServer in project Openfire by igniterealtime.
the class Fixtures method mockXMPPServer.
public static XMPPServer mockXMPPServer() {
final XMPPServer xmppServer = mock(XMPPServer.class, withSettings().lenient());
doAnswer(invocationOnMock -> {
final JID jid = invocationOnMock.getArgument(0);
return jid.getDomain().equals(XMPP_DOMAIN);
}).when(xmppServer).isLocal(any(JID.class));
doAnswer(invocationOnMock -> new JID(invocationOnMock.getArgument(0), XMPP_DOMAIN, invocationOnMock.getArgument(1))).when(xmppServer).createJID(any(String.class), nullable(String.class));
doAnswer(invocationOnMock -> new JID(invocationOnMock.getArgument(0), XMPP_DOMAIN, invocationOnMock.getArgument(1), invocationOnMock.getArgument(2))).when(xmppServer).createJID(any(String.class), nullable(String.class), any(Boolean.class));
doReturn(mockXMPPServerInfo()).when(xmppServer).getServerInfo();
doReturn(mockIQRouter()).when(xmppServer).getIQRouter();
return xmppServer;
}
use of org.jivesoftware.openfire.XMPPServer in project Openfire by igniterealtime.
the class UpdateManager method buildPluginsUpdateList.
/**
* Recreate the list of plugins that need to be updated based on the list of
* available plugins at igniterealtime.org.
*/
private void buildPluginsUpdateList() {
// Reset list of plugins that need to be updated
pluginUpdates = new ArrayList<>();
XMPPServer server = XMPPServer.getInstance();
Version currentServerVersion = XMPPServer.getInstance().getServerInfo().getVersion();
// Compare local plugins versions with latest ones
for (final PluginMetadata plugin : server.getPluginManager().getMetadataExtractedPlugins().values()) {
final AvailablePlugin latestPlugin = availablePlugins.get(plugin.getName());
if (latestPlugin == null) {
continue;
}
final Version latestPluginVersion = latestPlugin.getVersion();
if (latestPluginVersion.isNewerThan(plugin.getVersion())) {
// Check if the update can run in the current version of the server
final Version pluginMinServerVersion = latestPlugin.getMinServerVersion();
if (pluginMinServerVersion != null && pluginMinServerVersion.isNewerThan(currentServerVersion)) {
continue;
}
final Version pluginPriorToServerVersion = latestPlugin.getPriorToServerVersion();
if (pluginPriorToServerVersion != null && !pluginPriorToServerVersion.isNewerThan(currentServerVersion)) {
continue;
}
final Update update = new Update(plugin.getName(), latestPlugin.getVersion().getVersionString(), latestPlugin.getChangelog().toExternalForm(), latestPlugin.getDownloadURL().toExternalForm());
pluginUpdates.add(update);
}
}
}
use of org.jivesoftware.openfire.XMPPServer in project Openfire by igniterealtime.
the class LdapGroupProvider method processGroup.
private Group processGroup(LdapContext ctx, Attributes a, Set<String> membersToIgnore) throws NamingException {
XMPPServer server = XMPPServer.getInstance();
String serverName = server.getServerInfo().getXMPPDomain();
// Build `3 groups.
// group 1: uid=
// group 2: rest of the text until first comma
// group 3: rest of the text
Pattern pattern = Pattern.compile("(?i)(^" + manager.getUsernameField() + "=)([^,]+)(.+)");
// We have to process Active Directory differently.
boolean isAD = manager.getUsernameField().equals("sAMAccountName");
String[] returningAttributes = isAD ? new String[] { "distinguishedName", manager.getUsernameField() } : new String[] { manager.getUsernameField() };
SearchControls searchControls = new SearchControls();
searchControls.setReturningAttributes(returningAttributes);
// See if recursive searching is enabled. Otherwise, only search one level.
if (manager.isSubTreeSearch()) {
searchControls.setSearchScope(SearchControls.SUBTREE_SCOPE);
} else {
searchControls.setSearchScope(SearchControls.ONELEVEL_SCOPE);
}
String name;
String description;
try {
name = ((String) ((a.get(manager.getGroupNameField())).get()));
} catch (Exception e) {
name = "";
}
try {
description = ((String) ((a.get(manager.getGroupDescriptionField())).get()));
} catch (Exception e) {
description = "";
}
Set<JID> members = new TreeSet<>();
Attribute memberField = a.get(manager.getGroupMemberField());
Log.debug("Loading members of group: {}", name);
if (memberField != null) {
NamingEnumeration ne = memberField.getAll();
while (ne.hasMore()) {
String username = (String) ne.next();
LdapName userDN = null;
// If not posix mode, each group member is stored as a full DN.
if (!manager.isPosixMode()) {
// Create an LDAP name with the full DN.
userDN = new LdapName(username);
try {
// Try to find the username with a regex pattern match.
Matcher matcher = pattern.matcher(username);
if (matcher.matches() && matcher.groupCount() == 3) {
// The username is in the DN, no additional search needed
username = matcher.group(2);
} else // The regex pattern match failed. This will happen if the
// the member DN's don't use the standard username field. For
// example, Active Directory has a username field of
// sAMAccountName, but stores group members as "CN=...".
{
// Turn the LDAP name into something we can use in a
// search by stripping off the comma.
StringBuilder userFilter = new StringBuilder();
userFilter.append("(&(");
userFilter.append(userDN.get(userDN.size() - 1));
userFilter.append(')');
userFilter.append(MessageFormat.format(manager.getSearchFilter(), "*"));
userFilter.append(')');
NamingEnumeration usrAnswer = ctx.search("", userFilter.toString(), searchControls);
if (usrAnswer.hasMoreElements()) {
SearchResult searchResult = null;
// Iterate through the entire set to find a matching distinguished name.
while (usrAnswer.hasMoreElements()) {
searchResult = (SearchResult) usrAnswer.nextElement();
Attributes attrs = searchResult.getAttributes();
if (isAD) {
Attribute userdnAttr = attrs.get("distinguishedName");
if (username.equals((String) userdnAttr.get())) {
// Exact match found, use it.
username = (String) attrs.get(manager.getUsernameField()).get();
break;
}
} else {
// No iteration occurs here, which is probably a bug.
username = (String) attrs.get(manager.getUsernameField()).get();
break;
}
}
}
// Close the enumeration.
usrAnswer.close();
}
} catch (Exception e) {
// TODO: A NPE is occuring here
Log.error(e.getMessage(), e);
}
}
// it passes the filter.
try {
if (!membersToIgnore.contains(username)) {
JID userJID;
int position = username.indexOf("@" + serverName);
// Create JID of local user if JID does not match a component's JID
if (position == -1) {
// In order to lookup a username from the manager, the username
// must be a properly escaped JID node.
String escapedUsername = JID.escapeNode(username);
// Check if escaped username is valid
userManager.getUser(escapedUsername);
// No exception, so the user must exist. Add the user as a group
// member using the escaped username.
userJID = server.createJID(escapedUsername, null);
} else {
// This is a JID of a component or node of a server's component
String node = username.substring(0, position);
String escapedUsername = JID.escapeNode(node);
userJID = new JID(escapedUsername + "@" + serverName);
}
members.add(userJID);
}
} catch (UserNotFoundException e) {
// not a user!
// maybe it is a group?
boolean isGroup = false;
if (manager.isFlattenNestedGroups()) {
if (manager.isPosixMode()) {
// in posix mode, the DN has not been set...
// Look up the userDN using the UID
String userDNStr = manager.retrieveSingle(null, "(" + manager.getUsernameField() + "=" + LdapManager.sanitizeSearchFilter(username) + ")", true);
if (userDNStr != null)
userDN = new LdapName(userDNStr);
}
if (userDN != null && manager.isGroupDN(userDN)) {
isGroup = true;
if (!membersToIgnore.contains(userDN.toString()) && !membersToIgnore.contains(username)) {
// prevent endless adding of cyclic referenced groups
membersToIgnore.add(username);
membersToIgnore.add(userDN.toString());
// it's a sub group not already added, so add its members
Log.debug("Adding members of sub-group: {}", userDN);
Group subGroup = getGroupByDN(userDN, membersToIgnore);
members.addAll(subGroup.getMembers());
}
}
}
if (!isGroup) {
// So, we want to simply ignore the user as a group member.
if (manager.isDebugEnabled()) {
Log.debug("LdapGroupProvider: User not found: " + username);
}
}
}
}
// Close the enumeration.
ne.close();
}
if (manager.isDebugEnabled()) {
Log.debug("LdapGroupProvider: Adding group \"" + name + "\" with " + members.size() + " members.");
}
Collection<JID> admins = Collections.emptyList();
return new Group(name, description, members, admins);
}
use of org.jivesoftware.openfire.XMPPServer in project Openfire by igniterealtime.
the class LocaleUtils method getLocalizedString.
/**
* Returns an internationalized string loaded from a resource bundle from
* the passed in plugin, using the passed in Locale.
*
* If the plugin name is {@code null}, the key will be looked up using the
* standard resource bundle.
*
* If the locale is {@code null}, the Jive Global locale will be used.
*
* @param key
* the key to use for retrieving the string from the appropriate
* resource bundle.
* @param pluginName
* the name of the plugin to load the require resource bundle
* from.
* @param arguments
* a list of objects to use which are formatted, then inserted
* into the pattern at the appropriate places.
* @param locale
* the locale to use for retrieving the appropriate
* locale-specific string.
* @param fallback
* if {@code true}, the global locale used by Openfire will be
* used if the requested locale is not available)
* @return the localized string.
*/
public static String getLocalizedString(String key, String pluginName, List<?> arguments, Locale locale, boolean fallback) {
if (pluginName == null) {
return getLocalizedString(key, arguments);
}
if (locale == null) {
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: " + pluginName);
}
ClassLoader pluginClassLoader = pluginManager.getPluginClassloader(plugin);
try {
ResourceBundle bundle = ResourceBundle.getBundle(i18nFile, locale, pluginClassLoader);
return getLocalizedString(key, locale, arguments, bundle);
} catch (MissingResourceException mre) {
Locale jivesLocale = JiveGlobals.getLocale();
if (fallback && !jivesLocale.equals(locale)) {
Log.info("Could not find the requested locale. Falling back to default locale.", mre);
return getLocalizedString(key, pluginName, arguments, jivesLocale, false);
}
Log.error(mre.getMessage(), mre);
return key;
}
}
Aggregations