Search in sources :

Example 16 with CaseInsensitiveHashSet

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

the class AuthenticateToRealmCondition method evaluate.

/**
     * {@inheritDoc}
     */
@SuppressWarnings("unchecked")
@Override
public ConditionDecision evaluate(String realm, Subject subject, String resourceName, Map<String, Set<String>> env) throws EntitlementException {
    // We don't care about case of the realm when doing the comparison so use a CaseInsensitiveHashSet
    Set<String> requestAuthnRealms = new CaseInsensitiveHashSet();
    if (env.get(REQUEST_AUTHENTICATED_TO_REALMS) != null) {
        requestAuthnRealms.addAll(env.get(REQUEST_AUTHENTICATED_TO_REALMS));
        if (debug.messageEnabled()) {
            debug.message("At AuthenticateToRealmCondition.getConditionDecision(): requestAuthnRealms, from " + "request = " + requestAuthnRealms);
        }
    } else {
        Set<String> authenticatedRealms = null;
        SSOToken token = (subject == null) ? null : (SSOToken) subject.getPrivateCredentials().iterator().next();
        if (token != null) {
            authenticatedRealms = entitlementCoreWrapper.getAuthenticatedRealms(token);
        }
        if (authenticatedRealms != null) {
            requestAuthnRealms.addAll(authenticatedRealms);
        }
        if (debug.messageEnabled()) {
            debug.message("At AuthenticateToRealmCondition.getConditionDecision(): requestAuthnRealms, from " + "ssoToken = " + requestAuthnRealms);
        }
    }
    boolean allowed = true;
    Map<String, Set<String>> advices = new HashMap<String, Set<String>>();
    Set<String> adviceMessages = new HashSet<String>(1);
    if (!requestAuthnRealms.contains(authenticateToRealm)) {
        allowed = false;
        adviceMessages.add(authenticateToRealm);
        advices.put(AUTHENTICATE_TO_REALM_CONDITION_ADVICE, adviceMessages);
        if (debug.messageEnabled()) {
            debug.message("At AuthenticateToRealmCondition.getConditionDecision():authenticateToRealm not " + "satisfied = " + authenticateToRealm);
        }
    }
    if (debug.messageEnabled()) {
        debug.message("At AuthenticateToRealmCondition.getConditionDecision():authenticateToRealm = " + authenticateToRealm + "," + "requestAuthnRealms = " + requestAuthnRealms + ", " + " allowed = " + allowed);
    }
    return new ConditionDecision(allowed, advices);
}
Also used : CaseInsensitiveHashSet(com.sun.identity.common.CaseInsensitiveHashSet) SSOToken(com.iplanet.sso.SSOToken) CaseInsensitiveHashSet(com.sun.identity.common.CaseInsensitiveHashSet) Set(java.util.Set) HashSet(java.util.HashSet) HashMap(java.util.HashMap) ConditionDecision(com.sun.identity.entitlement.ConditionDecision) CaseInsensitiveHashSet(com.sun.identity.common.CaseInsensitiveHashSet) HashSet(java.util.HashSet)

Example 17 with CaseInsensitiveHashSet

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

the class FilesRepo method search.

/*
     * (non-Javadoc)
     *
     * @see com.sun.identity.idm.IdRepo#search(com.iplanet.sso.SSOToken,
     *      com.sun.identity.idm.IdType, java.lang.String, int, int,
     *      java.util.Set, boolean, int, java.util.Map, boolean)
     */
public RepoSearchResults search(SSOToken token, IdType type, String pattern, int maxTime, int maxResults, Set returnAttrs, boolean returnAllAttrs, int filterOp, Map avPairs, boolean recursive) throws IdRepoException, SSOException {
    if (initializationException != null) {
        debug.error("FilesRepo.search: throwing initialization exception");
        throw (initializationException);
    }
    if (debug.messageEnabled()) {
        debug.message("FilesRepo:search pattern=" + pattern + " type=" + type + " returnAttrs=" + returnAttrs + " filter= " + filterOp + " matchAttrs= " + avPairs);
    }
    // Directory to start the search
    File dir = new File(new File(directory), type.getName());
    String[] files = dir.list(new FileRepoFileFilter(pattern));
    if (files.length == 0) {
        return new RepoSearchResults(Collections.EMPTY_SET, RepoSearchResults.SUCCESS, Collections.EMPTY_MAP, type);
    }
    // Check if attribute mapping has to be done
    Set results = new HashSet();
    if (avPairs != null && !avPairs.isEmpty()) {
        for (int i = 0; i < files.length; i++) {
            // Check if the attributes match
            Map allAttrs = getAttributes(token, type, files[i]);
            Set attrNames = new CaseInsensitiveHashSet();
            attrNames.addAll(allAttrs.keySet());
            boolean addResult = (filterOp == IdRepo.AND_MOD);
            for (Iterator items = avPairs.keySet().iterator(); items.hasNext(); ) {
                String attrName = (String) items.next();
                Set attrValue = (Set) avPairs.get(attrName);
                if ((attrValue == null) || attrValue.isEmpty() || attrValue.contains("*")) {
                    // Check if the attribute is present
                    if (attrNames.contains(attrName)) {
                        if (filterOp == IdRepo.OR_MOD) {
                            addResult = true;
                            break;
                        }
                    } else if (filterOp == IdRepo.AND_MOD) {
                        addResult = false;
                        break;
                    }
                } else {
                    // Check if the values are present
                    Set matchValues = (Set) allAttrs.get(attrName);
                    if (matchValues != null && containsAttrValue(matchValues, attrValue)) {
                        if (filterOp == IdRepo.OR_MOD) {
                            addResult = true;
                            break;
                        }
                    } else if (filterOp == IdRepo.AND_MOD) {
                        addResult = false;
                        break;
                    }
                }
            }
            if (addResult) {
                results.add(files[i]);
            }
        }
    } else {
        results.addAll(Arrays.asList(files));
    }
    // Build RepoSearchResults
    Map resultsWithAttrs = new HashMap();
    for (Iterator items = results.iterator(); items.hasNext(); ) {
        String item = (String) items.next();
        if (returnAllAttrs || returnAttrs == null) {
            resultsWithAttrs.put(item, getAttributes(token, type, item));
        } else if (returnAttrs.isEmpty()) {
            resultsWithAttrs.put(item, Collections.EMPTY_MAP);
        } else {
            resultsWithAttrs.put(item, getAttributes(token, type, item, returnAttrs));
        }
    }
    if (debug.messageEnabled()) {
        debug.message("FilesRepo:search results: " + results);
    }
    return (new RepoSearchResults(results, RepoSearchResults.SUCCESS, resultsWithAttrs, type));
}
Also used : CaseInsensitiveHashSet(com.sun.identity.common.CaseInsensitiveHashSet) HashSet(java.util.HashSet) Set(java.util.Set) HashMap(java.util.HashMap) CaseInsensitiveHashMap(com.sun.identity.common.CaseInsensitiveHashMap) CaseInsensitiveHashSet(com.sun.identity.common.CaseInsensitiveHashSet) Iterator(java.util.Iterator) RepoSearchResults(com.sun.identity.idm.RepoSearchResults) File(java.io.File) HashMap(java.util.HashMap) CaseInsensitiveHashMap(com.sun.identity.common.CaseInsensitiveHashMap) Map(java.util.Map) CaseInsensitiveHashSet(com.sun.identity.common.CaseInsensitiveHashSet) HashSet(java.util.HashSet)

Example 18 with CaseInsensitiveHashSet

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

the class FilesRepo method create.

/*
     * (non-Javadoc)
     *
     * @see com.sun.identity.idm.IdRepo#create(com.iplanet.sso.SSOToken,
     *      com.sun.identity.idm.IdType, java.lang.String, java.util.Map)
     */
public String create(SSOToken token, IdType type, String name, Map attrMap) throws IdRepoException, SSOException {
    if (initializationException != null) {
        debug.error("FilesRepo: throwing initialization exception");
        throw (initializationException);
    }
    if (supportedOps.keySet().contains(type)) {
        // Check if identity exists
        File file = constructFile(directory, type, name);
        if (!file.exists()) {
            // If type is user, add the configured object classes
            CaseInsensitiveHashMap nAttrs = new CaseInsensitiveHashMap(attrMap);
            Set ocs = (Set) nAttrs.get(OC);
            if (ocs == null) {
                nAttrs.put(OC, userOCs);
            } else {
                CaseInsensitiveHashSet ocv = new CaseInsensitiveHashSet(ocs);
                ocv.addAll(userOCs);
            }
            // Create the identity
            attrMap = processAttributes(nAttrs, hashAttributes, encryptAttributes);
            writeFile(file, attrMap);
            // %%% Send notification (must be via a different thread)
            if (repoListener != null) {
                repoListener.objectChanged(name, type, AMEvent.OBJECT_ADDED, repoListener.getConfigMap());
            }
        } else {
            // throw exception
            throw IdRepoDuplicateObjectException.nameAlreadyExists(file.getAbsolutePath());
        }
    } else {
        Object[] args = { NAME, IdOperation.SERVICE.getName(), type.getName() };
        throw new IdRepoUnsupportedOpException(IdRepoBundle.BUNDLE_NAME, IdRepoErrorCode.PLUGIN_OPERATION_NOT_SUPPORTED, args);
    }
    return (name);
}
Also used : CaseInsensitiveHashSet(com.sun.identity.common.CaseInsensitiveHashSet) IdRepoUnsupportedOpException(com.sun.identity.idm.IdRepoUnsupportedOpException) CaseInsensitiveHashSet(com.sun.identity.common.CaseInsensitiveHashSet) HashSet(java.util.HashSet) Set(java.util.Set) File(java.io.File) CaseInsensitiveHashMap(com.sun.identity.common.CaseInsensitiveHashMap)

Example 19 with CaseInsensitiveHashSet

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

the class AgentsRepo method getAgentPattern.

private Set getAgentPattern(SSOToken token, IdType type, ServiceConfig aConfig, String pattern, Map avPairs) throws IdRepoException {
    if (debug.messageEnabled()) {
        debug.message("AgentsRepo.getAgentPattern() called: pattern : " + pattern + "\navPairs : " + avPairs);
    }
    if (aConfig == null) {
        return (Collections.EMPTY_SET);
    }
    Set agentRes;
    // Get AgentType
    String agentType = null;
    if (avPairs != null && !avPairs.isEmpty()) {
        Set set = (Set) avPairs.get(IdConstants.AGENT_TYPE);
        if (set != null && !set.isEmpty()) {
            agentType = set.iterator().next().toString();
            avPairs.remove(IdConstants.AGENT_TYPE);
        }
    }
    if (debug.messageEnabled()) {
        debug.message("AgentsRepo.getAgentPattern() agentType : " + agentType);
    }
    // Search for agents matching the pattern and agenttype
    try {
        if (agentType != null) {
            agentRes = aConfig.getSubConfigNames(pattern, agentType);
        } else {
            agentRes = aConfig.getSubConfigNames(pattern);
        }
        if (debug.messageEnabled()) {
            debug.message("AgentsRepo.getAgentPattern() agentRes : " + agentRes);
        }
        // Check if there are agents and if more attributes are present
        if (agentRes == null || agentRes.isEmpty() || avPairs == null || avPairs.isEmpty()) {
            return (agentRes == null ? Collections.EMPTY_SET : agentRes);
        }
        /* if there are agents matching the pattern and agenttype and
             * if avPairs is not empty, search for other attributes in the
             * avPairs and add that Agent if search results are positive.
             * ie., if avPairs matches with the attributes in store.
            */
        Set agents = new HashSet(2);
        for (Iterator itr = agentRes.iterator(); itr.hasNext(); ) {
            String name = (String) itr.next();
            Map attrMap = getAttributes(token, type, name);
            if (attrMap == null || attrMap.isEmpty()) {
                continue;
            }
            for (Iterator it = avPairs.keySet().iterator(); it.hasNext(); ) {
                String attr = (String) it.next();
                /* 'attrValues' are values from avPairs sent by client.
                      * 'presentValues' are from Directory Server.
                      * The element in attrValues is compared with the
                      * values from DS, and then the agent name is added to
                      * resultant set to be returned if matches.
                     */
                Set attrValues = (Set) avPairs.get(attr);
                Set presentSet = (Set) attrMap.get(attr);
                if (presentSet != null && !presentSet.isEmpty()) {
                    Set presentValues = new CaseInsensitiveHashSet(presentSet);
                    for (Iterator i = attrValues.iterator(); i.hasNext(); ) {
                        String avName = (String) i.next();
                        if ((presentValues != null) && (presentValues.contains(avName))) {
                            agents.add(name);
                            break;
                        }
                    }
                }
            }
        }
        return (agents);
    } catch (SSOException sse) {
        debug.error("AgentsRepo.getAgentPattern(): Error occurred while " + "checking AgentName sent for pattern " + pattern, sse);
        throw new IdRepoException(sse.getMessage());
    } catch (SMSException sme) {
        debug.error("AgentsRepo.getAgentPattern(): Error occurred while " + "checking AgentName sent for pattern " + pattern, sme);
        throw new IdRepoException(sme.getMessage());
    }
}
Also used : CaseInsensitiveHashSet(com.sun.identity.common.CaseInsensitiveHashSet) NotificationSet(com.iplanet.services.comm.share.NotificationSet) Set(java.util.Set) CaseInsensitiveHashSet(com.sun.identity.common.CaseInsensitiveHashSet) HashSet(java.util.HashSet) SMSException(com.sun.identity.sm.SMSException) Iterator(java.util.Iterator) IdRepoException(com.sun.identity.idm.IdRepoException) SSOException(com.iplanet.sso.SSOException) Map(java.util.Map) HashMap(java.util.HashMap) CaseInsensitiveHashMap(com.sun.identity.common.CaseInsensitiveHashMap) CaseInsensitiveHashSet(com.sun.identity.common.CaseInsensitiveHashSet) HashSet(java.util.HashSet)

Example 20 with CaseInsensitiveHashSet

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

the class SpecialRepo method isSpecialUser.

private boolean isSpecialUser(IdType type, String name) throws SSOException {
    boolean isSpecUser = false;
    if (type.equals(IdType.USER)) {
        if ((specialUsers == null) || specialUsers.isEmpty()) {
            try {
                ServiceConfig userConfig = getUserConfig();
                Set userSet = new CaseInsensitiveHashSet();
                userSet.addAll(userConfig.getSubConfigNames());
                specialUsers = userSet;
            } catch (SMSException smse) {
                isSpecUser = false;
            }
        }
        if ((specialUsers != null) && specialUsers.contains(name)) {
            isSpecUser = true;
        }
    }
    return isSpecUser;
}
Also used : CaseInsensitiveHashSet(com.sun.identity.common.CaseInsensitiveHashSet) Set(java.util.Set) CaseInsensitiveHashSet(com.sun.identity.common.CaseInsensitiveHashSet) HashSet(java.util.HashSet) ServiceConfig(com.sun.identity.sm.ServiceConfig) SMSException(com.sun.identity.sm.SMSException)

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