Search in sources :

Example 1 with IndexRuleTree

use of org.forgerock.openam.entitlement.utils.indextree.IndexRuleTree in project OpenAM by OpenRock.

the class IndexTreeServiceImpl method createAndPopulateTree.

/**
     * Populates a new instance of a index rule tree with policy path indexes retrieved from the associated realm.
     *
     * @param realm
     *         The realm for which policy path indexes are to be read from.
     * @return A newly created tree populated with rules configured against the realm.
     * @throws EntitlementException
     *         When an error occurs reading policy data.
     */
private IndexRuleTree createAndPopulateTree(String realm) throws EntitlementException {
    IndexRuleTree indexTree = null;
    String baseDN = String.format(REALM_DN_TEMPLATE, dnMapper.orgNameToDN(realm));
    SSOToken token = AccessController.doPrivileged(adminAction);
    if (smDAO.checkIfEntryExists(baseDN, token)) {
        indexTree = new SimpleReferenceTree();
        try {
            Set<String> excludes = Collections.emptySet();
            // Carry out search.
            Iterator<SMSDataEntry> i = smDAO.search(token, baseDN, SEARCH_FILTER, 0, 0, false, false, excludes);
            while (i.hasNext()) {
                SMSDataEntry e = i.next();
                // Suppressed warning as unchecked assignment is valid.
                @SuppressWarnings("unchecked") Set<String> policyPathIndexes = e.getAttributeValues(INDEX_PATH_ATT);
                indexTree.addIndexRules(policyPathIndexes);
            }
        } catch (SMSException smsE) {
            throw new EntitlementException(52, new Object[] { baseDN }, smsE);
        }
        if (DEBUG.messageEnabled()) {
            DEBUG.message(String.format("Index rule tree created for '%s'.", realm));
        }
    }
    return indexTree;
}
Also used : EntitlementException(com.sun.identity.entitlement.EntitlementException) SimpleReferenceTree(org.forgerock.openam.entitlement.utils.indextree.SimpleReferenceTree) SSOToken(com.iplanet.sso.SSOToken) SMSDataEntry(com.sun.identity.sm.SMSDataEntry) SMSException(com.sun.identity.sm.SMSException) IndexRuleTree(org.forgerock.openam.entitlement.utils.indextree.IndexRuleTree)

Example 2 with IndexRuleTree

use of org.forgerock.openam.entitlement.utils.indextree.IndexRuleTree in project OpenAM by OpenRock.

the class IndexTreeServiceImpl method update.

/**
     * {@inheritDoc}
     */
public void update(IndexChangeEvent event) {
    EventType type = event.getType();
    if (ModificationEventType.contains(type)) {
        // Modification event received, update the appropriate cached tree.
        ModificationEventType modificationType = (ModificationEventType) type;
        ModificationEvent modification = (ModificationEvent) event;
        String realm = modification.getRealm();
        IndexRuleTree tree = indexTreeCache.get(realm);
        if (tree != null) {
            String pathIndex = modification.getPathIndex();
            switch(modificationType) {
                case ADD:
                    tree.addIndexRule(pathIndex);
                    break;
                case DELETE:
                    tree.removeIndexRule(pathIndex);
                    break;
            }
            if (DEBUG.messageEnabled()) {
                DEBUG.message(String.format("Policy path index '%s' updated for realm '%s'.", pathIndex, realm));
            }
        }
    } else if (type == ErrorEventType.DATA_LOSS) {
        // Error event received, destroy the cache as policy updates may well have been lost, resulting in cached
        // trees becoming inconsistent. This will force all trees to be reloaded with clean data.
        indexTreeCache.clear();
        if (DEBUG.messageEnabled()) {
            DEBUG.message("Potential policy path index loss, cached index trees cleared.");
        }
    }
}
Also used : EventType(org.forgerock.openam.entitlement.indextree.events.EventType) ModificationEventType(org.forgerock.openam.entitlement.indextree.events.ModificationEventType) ErrorEventType(org.forgerock.openam.entitlement.indextree.events.ErrorEventType) ModificationEventType(org.forgerock.openam.entitlement.indextree.events.ModificationEventType) ModificationEvent(org.forgerock.openam.entitlement.indextree.events.ModificationEvent) IndexRuleTree(org.forgerock.openam.entitlement.utils.indextree.IndexRuleTree)

Example 3 with IndexRuleTree

use of org.forgerock.openam.entitlement.utils.indextree.IndexRuleTree in project OpenAM by OpenRock.

the class IndexTreeServiceImpl method searchTree.

/**
     * {@inheritDoc}
     */
public Set<String> searchTree(String resource, String realm) throws EntitlementException {
    IndexRuleTree indexRuleTree = getIndexTree(realm);
    if (indexRuleTree == null) {
        return Collections.emptySet();
    }
    Set<String> results = indexRuleTree.searchTree(resource);
    if (DEBUG.messageEnabled()) {
        DEBUG.message(String.format("Matched index rules (resource:%s, realm:%s): %s", resource, realm, results));
    }
    return results;
}
Also used : IndexRuleTree(org.forgerock.openam.entitlement.utils.indextree.IndexRuleTree)

Example 4 with IndexRuleTree

use of org.forgerock.openam.entitlement.utils.indextree.IndexRuleTree in project OpenAM by OpenRock.

the class IndexTreeServiceImpl method getIndexTree.

/**
     * Retrieves the index rule tree for the given realm.
     *
     * @param realm
     *         The realm.
     * @return An index rule tree.
     * @throws EntitlementException
     *         When an error occurs reading policy data..
     */
private IndexRuleTree getIndexTree(String realm) throws EntitlementException {
    IndexRuleTree indexTree = null;
    // It is important to note here that get() is used on the cache as opposed to contains() followed by a get().
    // This is done to make the retrieval of the tree atomic, whereas contains() follow by get() is not atomic
    // and therefore the result of contains() instantly becomes unreliable when get() is reached.
    indexTree = indexTreeCache.get(realm);
    if (indexTree == null) {
        synchronized (indexTreeCache) {
            // Double checking mechanism used here to help performance within a synchronised block.
            indexTree = indexTreeCache.get(realm);
            if (indexTree == null) {
                // Create a new tree instance for the realm.
                indexTree = createAndPopulateTree(realm);
                if (indexTree != null) {
                    // Valid tree entry create, add to the cache.
                    indexTreeCache.put(realm, indexTree);
                }
            }
        }
    }
    return indexTree;
}
Also used : IndexRuleTree(org.forgerock.openam.entitlement.utils.indextree.IndexRuleTree)

Aggregations

IndexRuleTree (org.forgerock.openam.entitlement.utils.indextree.IndexRuleTree)4 SSOToken (com.iplanet.sso.SSOToken)1 EntitlementException (com.sun.identity.entitlement.EntitlementException)1 SMSDataEntry (com.sun.identity.sm.SMSDataEntry)1 SMSException (com.sun.identity.sm.SMSException)1 ErrorEventType (org.forgerock.openam.entitlement.indextree.events.ErrorEventType)1 EventType (org.forgerock.openam.entitlement.indextree.events.EventType)1 ModificationEvent (org.forgerock.openam.entitlement.indextree.events.ModificationEvent)1 ModificationEventType (org.forgerock.openam.entitlement.indextree.events.ModificationEventType)1 SimpleReferenceTree (org.forgerock.openam.entitlement.utils.indextree.SimpleReferenceTree)1