Search in sources :

Example 56 with LinkedHashSet

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;
}
Also used : LinkedHashSet(java.util.LinkedHashSet) ServerEntryNotFoundException(com.iplanet.services.naming.ServerEntryNotFoundException) LDAPURL(org.forgerock.openam.ldap.LDAPURL)

Example 57 with LinkedHashSet

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;
}
Also used : LinkedHashSet(java.util.LinkedHashSet) Server(com.iplanet.services.ldap.Server) LDAPURL(org.forgerock.openam.ldap.LDAPURL)

Example 58 with LinkedHashSet

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;
}
Also used : LinkedHashSet(java.util.LinkedHashSet) StringTokenizer(java.util.StringTokenizer) ByteString(org.forgerock.opendj.ldap.ByteString)

Example 59 with LinkedHashSet

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;
}
Also used : LinkedHashSet(java.util.LinkedHashSet) Set(java.util.Set) HashSet(java.util.HashSet) LinkedHashSet(java.util.LinkedHashSet) HashMap(java.util.HashMap) SMSException(com.sun.identity.sm.SMSException) NamingException(javax.naming.NamingException) DirectoryException(org.opends.server.types.DirectoryException) SSOException(com.iplanet.sso.SSOException) SMSException(com.sun.identity.sm.SMSException) AMResourceBundleCache(com.sun.identity.shared.locale.AMResourceBundleCache) Map(java.util.Map) HashMap(java.util.HashMap) HashSet(java.util.HashSet) LinkedHashSet(java.util.LinkedHashSet)

Example 60 with LinkedHashSet

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;
}
Also used : LinkedHashSet(java.util.LinkedHashSet) Set(java.util.Set) HashSet(java.util.HashSet) LinkedHashSet(java.util.LinkedHashSet) ServiceConfig(com.sun.identity.sm.ServiceConfig) Iterator(java.util.Iterator) Map(java.util.Map)

Aggregations

LinkedHashSet (java.util.LinkedHashSet)3111 ArrayList (java.util.ArrayList)632 Set (java.util.Set)410 HashSet (java.util.HashSet)334 HashMap (java.util.HashMap)312 Map (java.util.Map)284 List (java.util.List)269 File (java.io.File)266 LinkedHashMap (java.util.LinkedHashMap)257 IOException (java.io.IOException)240 Test (org.junit.Test)239 LinkedList (java.util.LinkedList)139 Collection (java.util.Collection)103 URL (java.net.URL)83 ProcessResult (org.asqatasun.entity.audit.ProcessResult)76 Iterator (java.util.Iterator)73 SourceCodeRemark (org.asqatasun.entity.audit.SourceCodeRemark)73 TreeMap (java.util.TreeMap)70 TreeSet (java.util.TreeSet)70 Collectors (java.util.stream.Collectors)69