use of java.util.LinkedHashSet in project OpenAM by OpenRock.
the class ExternalLdapConfig method getLDAPURLs.
/**
* The hosts to connect to.
* @return A set of connection details with serverId/siteId preferences.
*/
public Set<LDAPURL> getLDAPURLs() {
String serverId = null;
String siteId = "";
try {
serverId = WebtopNaming.getAMServerID();
siteId = WebtopNaming.getSiteID(serverId);
} catch (ServerEntryNotFoundException senfe) {
if (debug.warningEnabled()) {
debug.warning("ServerEntryNotFoundException, serverId=" + serverId + ", siteId=" + siteId);
}
}
String hosts = this.hosts.get();
Set<String> urls = new LinkedHashSet<String>();
urls.addAll(Arrays.asList(hosts.split(",")));
boolean isSSL = isSSLMode();
Set<LDAPURL> ldapurls = new LinkedHashSet<LDAPURL>();
for (LDAPURL url : LDAPUtils.prioritizeServers(urls, serverId, siteId)) {
ldapurls.add(LDAPURL.valueOf(url.getHost(), url.getPort(), isSSL));
}
if (debug.messageEnabled()) {
debug.message("Priotized server list [" + hosts + "] using server ID [" + serverId + "] and site ID [" + siteId + "]");
}
return ldapurls;
}
use of java.util.LinkedHashSet in project OpenAM by OpenRock.
the class ServerGroupConfiguration method getLDAPURLs.
/**
* Creates a list of {@link LDAPURL} instances based on the server instances available in the servergroup.
*
* @return A non null, but possibly empty list of {@link LDAPURL} instances based on the configured server
* instances in the corresponding server group.
*/
public Set<LDAPURL> getLDAPURLs() {
Collection<Server> servers = group.getServersList();
Set<LDAPURL> ret = new LinkedHashSet<LDAPURL>(servers.size());
for (Server server : servers) {
ret.add(LDAPURL.valueOf(server.getServerName(), server.getPort(), Server.Type.CONN_SSL.equals(server.getConnectionType())));
}
return ret;
}
use of java.util.LinkedHashSet in project OpenAM by OpenRock.
the class LDAPUtils method prioritizeServers.
/**
* Prioritizes the incoming LDAP servers based on their assigned servers/sites.
* The format of the server list can be either one of the followings:
* <ul>
* <li><code>host:port</code> - The LDAP server has no preferred
* server/site</li>
* <li><code>host:port|serverid</code> - The LDAP server should be mainly
* used by an OpenAM instance with the same serverid</li>
* <li><code>host:port|serverid|siteid</code> - The LDAP server should be
* mainly used by an OpenAM instance with the same serverid or with the same
* siteid</li>
* </ul>
* The resulting priority list will have the following order:
* <ul>
* <li>servers that are linked with this server</li>
* <li>servers that are linked with the current site</li>
* <li>any other server that did not match in the same order as they were defined</li>
* </ul>
*
* @param servers The Set of servers that needs to be prioritized in the previously described format.
* @param hostServerId This server's ID.
* @param hostSiteId This server's site ID.
* @return The prioritized Set of LDAP URLs that can be used to create connection factories.
*/
public static Set<LDAPURL> prioritizeServers(Set<String> servers, String hostServerId, String hostSiteId) {
Set<LDAPURL> ldapServers = new LinkedHashSet<LDAPURL>(servers.size());
Set<LDAPURL> serverDefined = new LinkedHashSet<LDAPURL>(servers.size());
Set<LDAPURL> siteDefined = new LinkedHashSet<LDAPURL>(servers.size());
Set<LDAPURL> nonMatchingServers = new LinkedHashSet<LDAPURL>(servers.size());
for (String server : servers) {
StringTokenizer tokenizer = new StringTokenizer(server, "|");
String ldapUrl = tokenizer.nextToken();
String assignedServerId = "";
String assignedSiteId = "";
if (tokenizer.hasMoreTokens()) {
assignedServerId = tokenizer.nextToken();
}
if (tokenizer.hasMoreTokens()) {
assignedSiteId = tokenizer.nextToken();
}
if (!assignedServerId.isEmpty() && assignedServerId.equals(hostServerId)) {
serverDefined.add(LDAPURL.valueOf(ldapUrl));
} else if (!assignedSiteId.isEmpty() && assignedSiteId.equals(hostSiteId)) {
siteDefined.add(LDAPURL.valueOf(ldapUrl));
} else {
nonMatchingServers.add(LDAPURL.valueOf(ldapUrl));
}
}
//Let's add them in the order of priority to the ldapServers set, this way the most appropriate servers should
//be at the beginning of the list and towards the end of the list are the possibly most remote servers.
ldapServers.addAll(serverDefined);
ldapServers.addAll(siteDefined);
ldapServers.addAll(nonMatchingServers);
return ldapServers;
}
use of java.util.LinkedHashSet in project OpenAM by OpenRock.
the class SMSEmbeddedLdapObject method initialize.
/**
* Synchronized initialized method
*/
private synchronized void initialize() throws SMSException {
auditorFactory = InjectorHolder.getInstance(ConfigAuditorFactory.class);
if (initialized) {
return;
}
// Obtain the I18N resource bundle & Debug
debug = Debug.getInstance("amSMSEmbeddedLdap");
AMResourceBundleCache amCache = AMResourceBundleCache.getInstance();
bundle = amCache.getResBundle(IUMSConstants.UMS_BUNDLE_NAME, java.util.Locale.ENGLISH);
orgUnitAttr = new LinkedHashSet<>(1);
orgUnitAttr.add(getNamingAttribute());
orgAttr = new LinkedHashSet<>(1);
orgAttr.add(getOrgNamingAttribute());
icConn = InternalClientConnection.getRootConnection();
try {
String serviceDN = SMSEntry.SERVICES_RDN + SMSEntry.COMMA + getRootSuffix();
if (!entryExists(serviceDN)) {
Map attrs = new HashMap();
Set attrValues = new HashSet();
attrValues.add(SMSEntry.OC_TOP);
attrValues.add(SMSEntry.OC_ORG_UNIT);
attrs.put(SMSEntry.ATTR_OBJECTCLASS, attrValues);
internalCreate(null, serviceDN, attrs);
}
} catch (Exception e) {
// Unable to initialize (trouble!!)
debug.error("SMSEmbeddedLdapObject.initialize: " + "Unable to initalize(exception):", e);
throw (new SMSException(IUMSConstants.UMS_BUNDLE_NAME, IUMSConstants.CONFIG_MGR_ERROR, null));
}
String[] smsAttrs = getAttributeNames();
smsAttributes = new LinkedHashSet(smsAttrs.length);
for (int i = 0; i < smsAttrs.length; i++) {
smsAttributes.add(smsAttrs[i]);
}
initialized = true;
}
use of java.util.LinkedHashSet in project OpenAM by OpenRock.
the class ConfigurationBase method getSiteConfigurationIds.
protected static Set getSiteConfigurationIds(SSOToken ssoToken, ServiceConfig rootNode, String name, boolean bPrimaryOnly) throws SMSException, SSOException {
if (rootNode == null) {
rootNode = getRootSiteConfig(ssoToken);
}
ServiceConfig sc = rootNode.getSubConfig(name);
if (sc == null) {
return Collections.EMPTY_SET;
}
Set currentIds = new LinkedHashSet();
ServiceConfig accessPoint = sc.getSubConfig(SUBCONFIG_ACCESS_URL);
Map map = accessPoint.getAttributes();
Set set = (Set) map.get(ATTR_PRIMARY_SITE_ID);
currentIds.add(set.iterator().next());
if (!bPrimaryOnly) {
Set failovers = accessPoint.getSubConfigNames("*");
if ((failovers != null) && !failovers.isEmpty()) {
for (Iterator i = failovers.iterator(); i.hasNext(); ) {
String foName = (String) i.next();
ServiceConfig s = accessPoint.getSubConfig(foName);
Map mapValues = s.getAttributes();
set = (Set) mapValues.get(ATTR_SEC_ID);
if ((set != null) && !set.isEmpty()) {
currentIds.add(set.iterator().next());
}
}
}
}
return currentIds;
}
Aggregations