Search in sources :

Example 26 with CaseInsensitiveHashSet

use of com.sun.identity.common.CaseInsensitiveHashSet in project OpenAM by OpenRock.

the class OrganizationConfigManager method loadDefaultServices.

/**
     * Loads default services to a newly created realm
     */
public static void loadDefaultServices(SSOToken token, OrganizationConfigManager ocm) throws SMSException {
    // Check if DIT has been migrated to 7.0
    if (!migratedTo70) {
        return;
    }
    Set defaultServices = ServiceManager.servicesAssignedByDefault();
    // Load the default services automatically
    OrganizationConfigManager parentOrg = ocm.getParentOrgConfigManager();
    if (defaultServices == null) {
        // There are no services to be loaded
        return;
    }
    Set assignedServices = new CaseInsensitiveHashSet(parentOrg.getAssignedServices());
    if (SMSEntry.debug.messageEnabled()) {
        SMSEntry.debug.message("OrganizationConfigManager" + "::loadDefaultServices " + "assignedServices : " + assignedServices);
    }
    boolean doAuthServiceLater = false;
    boolean doAuthHttpBasicLater = false;
    String serviceName = null;
    // Copy service configuration
    Iterator items = defaultServices.iterator();
    while (items.hasNext() || doAuthHttpBasicLater || doAuthServiceLater) {
        if (items.hasNext()) {
            serviceName = (String) items.next();
            if (serviceName.equals(ISAuthConstants.AUTH_SERVICE_NAME)) {
                doAuthServiceLater = true;
                continue;
            } else if (serviceName.equals(ISAuthConstants.AUTH_HTTP_BASIC_SERVICE_NAME)) {
                doAuthHttpBasicLater = true;
                continue;
            }
        } else if (doAuthHttpBasicLater) {
            serviceName = ISAuthConstants.AUTH_HTTP_BASIC_SERVICE_NAME;
            doAuthHttpBasicLater = false;
        } else if (doAuthServiceLater) {
            serviceName = ISAuthConstants.AUTH_SERVICE_NAME;
            doAuthServiceLater = false;
        }
        if (SMSEntry.debug.messageEnabled()) {
            SMSEntry.debug.message("OrganizationConfigManager" + "::loadDefaultServices:ServiceName " + serviceName);
        }
        try {
            ServiceConfig sc = parentOrg.getServiceConfig(serviceName);
            ServiceSchema ss = parentOrg.getServiceSchema(serviceName);
            Map attrs = null;
            if (sc != null && assignedServices.contains(serviceName)) {
                attrs = sc.getAttributesWithoutDefaults();
                if (SMSEntry.debug.messageEnabled()) {
                    SMSEntry.debug.message("OrganizationConfigManager" + "::loadDefaultServices " + "Copying service from parent: " + serviceName);
                }
                ServiceConfig scn = ocm.addServiceConfig(serviceName, attrs);
                // Copy sub-configurations, if any
                copySubConfig(sc, scn, ss);
            }
        } catch (SSOException ssoe) {
            if (SMSEntry.debug.messageEnabled()) {
                SMSEntry.debug.message("OrganizationConfigManager.loadDefaultServices " + "SSOException in loading default services ", ssoe);
            }
            throw (new SMSException(SMSEntry.bundle.getString(SMS_INVALID_SSO_TOKEN), SMS_INVALID_SSO_TOKEN));
        }
    }
}
Also used : CaseInsensitiveHashSet(com.sun.identity.common.CaseInsensitiveHashSet) Set(java.util.Set) CaseInsensitiveHashSet(com.sun.identity.common.CaseInsensitiveHashSet) HashSet(java.util.HashSet) Iterator(java.util.Iterator) SSOException(com.iplanet.sso.SSOException) HashMap(java.util.HashMap) Map(java.util.Map)

Example 27 with CaseInsensitiveHashSet

use of com.sun.identity.common.CaseInsensitiveHashSet in project OpenAM by OpenRock.

the class SMSEnhancedFlatFileObject method getSubEntries.

/**
     * Real routine to get sub entries, used by subEntries() and 
     * schemaSubEntries(). 
     *
     * @throws ServiceNotFoundException if the configuration object is 
     * not found.
     * @throws SchemaException if a sub directory name is not in the 
     * expected "ou=..." format.
     */
protected Set getSubEntries(String objName, String filter, String sidFilter, boolean isSubConfig, int numOfEntries, boolean sortResults, boolean ascendingOrder) throws SMSException {
    String objKey = objName.toLowerCase();
    Set subentries = null;
    // wait indefinitely for the read lock.
    mRWLock.readRequest();
    try {
        SMSFlatFileTreeNode node = root.getChild(objKey);
        if (node == null) {
            String errmsg = "SMSEnhancedFlatFileObject.getSubEntries: " + objName + " : not found in objects map.";
            mDebug.warning(errmsg);
            throw new ServiceNotFoundException(errmsg);
        }
        // Create file filter for filter and sid filter.
        NodeNameFilter subEntNodeFilter = new NodeNameFilter(filter);
        NodeNameFilter sidNameFilter = getSidNodeFilter(sidFilter, isSubConfig);
        // Create set for return, use sorted set if sortResults is true.
        if (sortResults) {
            subentries = new CaseInsensitiveTreeSet(ascendingOrder);
        } else {
            subentries = new CaseInsensitiveHashSet();
        }
        // Set all entries that match filter, and that match 
        // sunserviceid/sunxmlkeyvalye if sidFilter was not null.
        Set subEntries = node.searchChildren(subEntNodeFilter, false);
        int numEntriesAdded = 0;
        int sz = subEntries.size();
        boolean done = false;
        for (Iterator i = subEntries.iterator(); i.hasNext() && !done; ) {
            SMSFlatFileTreeNode n = (SMSFlatFileTreeNode) i.next();
            String nodeDN = n.getName();
            boolean accept = (sidNameFilter == null);
            if (!accept) {
                Set sids = n.searchChildren(sidNameFilter, false);
                accept = (sids != null) && !sids.isEmpty();
            }
            if (accept) {
                int idx = nodeDN.indexOf('=');
                if ((idx == -1) || (idx == (nodeDN.length() - 1))) {
                    String errmsg = "SMSEnhancedFlatFileObject.getSubEntries: " + "Invalid sub entry name found: " + nodeDN;
                    mDebug.error(errmsg);
                    throw new SchemaException(errmsg);
                }
                String subentryname = FileNameDecoder.decode(nodeDN.substring(idx + 1));
                subentries.add(subentryname);
                numEntriesAdded++;
                // stop if number of entries requested has been reached.
                // if sort results, need to get the whole list first.
                done = !sortResults && (numOfEntries > 0) && (numEntriesAdded == numOfEntries);
            }
        }
        if (sortResults && (numOfEntries > 0)) {
            while ((numEntriesAdded - numOfEntries) > 0) {
                Object l = ((CaseInsensitiveTreeSet) subentries).last();
                subentries.remove(l);
                numEntriesAdded--;
            }
        }
    } finally {
        mRWLock.readDone();
    }
    return subentries;
}
Also used : CaseInsensitiveHashSet(com.sun.identity.common.CaseInsensitiveHashSet) SchemaException(com.sun.identity.sm.SchemaException) CaseInsensitiveHashSet(com.sun.identity.common.CaseInsensitiveHashSet) HashSet(java.util.HashSet) CaseInsensitiveTreeSet(com.sun.identity.common.CaseInsensitiveTreeSet) Set(java.util.Set) ServiceNotFoundException(com.sun.identity.sm.ServiceNotFoundException) Iterator(java.util.Iterator) CaseInsensitiveTreeSet(com.sun.identity.common.CaseInsensitiveTreeSet)

Example 28 with CaseInsensitiveHashSet

use of com.sun.identity.common.CaseInsensitiveHashSet in project OpenAM by OpenRock.

the class DJLDAPv3Repo method getServiceAttributes.

/**
     * Returns the service attributes in binary or string format for the given identity.
     * In case of a USER this will retrieve first the service attributes from the user entry, and later it will also
     * query the service attributes of the current realm. When a user-specific setting is missing the realm-specific one
     * will be returned instead.
     * In case of a REALM it will return a defensive copy of the service attributes stored locally.
     *
     * @param type The type of the identity, this should be always USER or REALM.
     * @param name The name of the identity to query. Only used when identity type is USER.
     * @param serviceName The name of the service, which in case of USER may be null.
     * @param attrNames The name of the service attributes that needs to be queried. In case of USER this may NOT be
     * null. In case of REALM, when null this will return all attributes for the service.
     * @param extractor The attribute extractor to use.
     * @param converter The attribute filter to use.
     * @return The matching service attributes.
     * @throws IdRepoException If there was an error while retrieving the service attributes from the user, or if the
     * identity type was invalid.
     */
private <T> Map<String, T> getServiceAttributes(IdType type, String name, String serviceName, Set<String> attrNames, Function<Attribute, T, IdRepoException> extractor, Function<Map<String, Set<String>>, Map<String, T>, IdRepoException> converter) throws IdRepoException {
    if (type.equals(IdType.USER)) {
        Map<String, T> attrsFromUser = getAttributes(type, name, attrNames, extractor);
        if (serviceName == null || serviceName.isEmpty()) {
            return attrsFromUser;
        }
        Map<String, Set<String>> attrsFromRealm = serviceMap.get(serviceName);
        Map<String, Set<String>> filteredAttrsFromRealm = new HashMap<String, Set<String>>();
        if (attrsFromRealm == null || attrsFromRealm.isEmpty()) {
            return attrsFromUser;
        } else {
            attrNames = new CaseInsensitiveHashSet(attrNames);
            for (Map.Entry<String, Set<String>> entry : attrsFromRealm.entrySet()) {
                String attrName = entry.getKey();
                if (attrNames.contains(attrName)) {
                    filteredAttrsFromRealm.put(attrName, entry.getValue());
                }
            }
        }
        Map<String, T> filteredAttrsFromRealm2 = converter.apply(filteredAttrsFromRealm);
        Set<String> attrNameSet = new CaseInsensitiveHashSet(attrsFromUser.keySet());
        for (Map.Entry<String, T> entry : filteredAttrsFromRealm2.entrySet()) {
            String attrName = entry.getKey();
            if (!attrNameSet.contains(attrName)) {
                attrsFromUser.put(attrName, entry.getValue());
            }
        }
        return attrsFromUser;
    } else if (type.equals(IdType.REALM)) {
        Map<String, T> attrs = converter.apply(serviceMap.get(serviceName));
        Map<String, T> results = new HashMap<String, T>();
        if (attrs == null || attrs.isEmpty()) {
            return results;
        }
        if (attrNames == null || attrNames.isEmpty()) {
            results.putAll(attrs);
            return results;
        } else {
            Set<String> attributeNames = new CaseInsensitiveHashSet(attrs.keySet());
            for (String attrName : attrNames) {
                if (attributeNames.contains(attrName)) {
                    results.put(attrName, attrs.get(attrName));
                }
            }
            return results;
        }
    } else {
        throw new IdRepoUnsupportedOpException(IdRepoBundle.BUNDLE_NAME, IdRepoErrorCode.SERVICES_NOT_SUPPORTED_FOR_AGENTS_AND_GROUPS, new Object[] { CLASS_NAME });
    }
}
Also used : Set(java.util.Set) CaseInsensitiveHashSet(com.sun.identity.common.CaseInsensitiveHashSet) HashSet(java.util.HashSet) LinkedHashSet(java.util.LinkedHashSet) CollectionUtils.asSet(org.forgerock.openam.utils.CollectionUtils.asSet) HashMap(java.util.HashMap) CaseInsensitiveHashMap(com.sun.identity.common.CaseInsensitiveHashMap) ByteString(org.forgerock.opendj.ldap.ByteString) CaseInsensitiveHashSet(com.sun.identity.common.CaseInsensitiveHashSet) IdRepoUnsupportedOpException(com.sun.identity.idm.IdRepoUnsupportedOpException) Map(java.util.Map) HashMap(java.util.HashMap) CaseInsensitiveHashMap(com.sun.identity.common.CaseInsensitiveHashMap)

Example 29 with CaseInsensitiveHashSet

use of com.sun.identity.common.CaseInsensitiveHashSet in project OpenAM by OpenRock.

the class GenericRepoTest method setAttributesAddsNecessaryObjectClasses.

//Disabled, because this would require a bit more clever schema object in IdRepoTestBase.
@Test(enabled = false)
public void setAttributesAddsNecessaryObjectClasses() throws Exception {
    Map<String, Set<String>> attrs = idrepo.getAttributes(null, IdType.USER, DEMO, asSet("objectclass"));
    assertThat(attrs).hasSize(1);
    Set<String> attr = new CaseInsensitiveHashSet(attrs.entrySet().iterator().next().getValue());
    assertThat(attr.contains("pilotPerson")).isFalse();
    Map<String, Set<String>> changes = new HashMap<String, Set<String>>();
    changes.put("otherMailbox", asSet("DemoLand"));
    idrepo.setAttributes(null, IdType.USER, DEMO, changes, true);
    attrs = idrepo.getAttributes(null, IdType.USER, DEMO, asSet("objectclass"));
    assertThat(attrs).hasSize(1);
    attr = new CaseInsensitiveHashSet(attrs.entrySet().iterator().next().getValue());
    assertThat(attr.contains("pilotPerson")).isTrue();
}
Also used : CaseInsensitiveHashSet(com.sun.identity.common.CaseInsensitiveHashSet) CaseInsensitiveHashSet(com.sun.identity.common.CaseInsensitiveHashSet) HashSet(java.util.HashSet) CollectionUtils.asOrderedSet(org.forgerock.openam.utils.CollectionUtils.asOrderedSet) Set(java.util.Set) CollectionUtils.asSet(org.forgerock.openam.utils.CollectionUtils.asSet) HashMap(java.util.HashMap) CaseInsensitiveHashMap(com.sun.identity.common.CaseInsensitiveHashMap) Test(org.testng.annotations.Test)

Example 30 with CaseInsensitiveHashSet

use of com.sun.identity.common.CaseInsensitiveHashSet in project OpenAM by OpenRock.

the class IdServicesImpl method mapAttributeNames.

private Set mapAttributeNames(Set attrNames, Map configMap) {
    if (attrNames == null || attrNames.isEmpty()) {
        return attrNames;
    }
    Map[] mapArray = getAttributeNameMap(configMap);
    Set resultSet;
    if (mapArray == null) {
        resultSet = attrNames;
    } else {
        resultSet = new CaseInsensitiveHashSet();
        Map forwardMap = mapArray[0];
        Iterator it = attrNames.iterator();
        while (it.hasNext()) {
            String curr = (String) it.next();
            if (forwardMap.containsKey(curr)) {
                resultSet.add((String) forwardMap.get(curr));
            } else {
                resultSet.add(curr);
            }
        }
    }
    return resultSet;
}
Also used : CaseInsensitiveHashSet(com.sun.identity.common.CaseInsensitiveHashSet) Set(java.util.Set) OrderedSet(com.sun.identity.shared.datastruct.OrderedSet) CaseInsensitiveHashSet(com.sun.identity.common.CaseInsensitiveHashSet) HashSet(java.util.HashSet) Iterator(java.util.Iterator) Map(java.util.Map) AMHashMap(com.iplanet.am.sdk.AMHashMap) HashMap(java.util.HashMap) CaseInsensitiveHashMap(com.sun.identity.common.CaseInsensitiveHashMap)

Aggregations

CaseInsensitiveHashSet (com.sun.identity.common.CaseInsensitiveHashSet)37 Set (java.util.Set)30 HashSet (java.util.HashSet)27 HashMap (java.util.HashMap)19 CaseInsensitiveHashMap (com.sun.identity.common.CaseInsensitiveHashMap)18 Map (java.util.Map)16 Iterator (java.util.Iterator)13 ByteString (org.forgerock.opendj.ldap.ByteString)9 SSOException (com.iplanet.sso.SSOException)6 IdRepoException (com.sun.identity.idm.IdRepoException)6 IdRepoUnsupportedOpException (com.sun.identity.idm.IdRepoUnsupportedOpException)6 SMSException (com.sun.identity.sm.SMSException)6 CollectionUtils.asSet (org.forgerock.openam.utils.CollectionUtils.asSet)6 LinkedHashSet (java.util.LinkedHashSet)5 CaseInsensitiveTreeSet (com.sun.identity.common.CaseInsensitiveTreeSet)4 PolicyException (com.sun.identity.policy.PolicyException)3 OrderedSet (com.sun.identity.shared.datastruct.OrderedSet)3 ServiceConfig (com.sun.identity.sm.ServiceConfig)3 ServiceNotFoundException (com.sun.identity.sm.ServiceNotFoundException)3 File (java.io.File)3