Search in sources :

Example 1 with SMSDataEntry

use of com.sun.identity.sm.SMSDataEntry in project OpenAM by OpenRock.

the class SearchResultIterator method hasNext.

public boolean hasNext() {
    try {
        if (results.hasNext()) {
            if (current == null) {
                if (results.isReference()) {
                    debug.warning("SearchResultIterator: ignoring reference: {}", results.readReference());
                    return hasNext();
                }
                SearchResultEntry entry = results.readEntry();
                String dn = entry.getName().toString();
                if (hasExcludeDNs && excludeDNs.contains(dn)) {
                    return hasNext();
                }
                current = new SMSDataEntry(dn, SMSUtils.convertEntryToAttributesMap(entry));
            }
            return true;
        }
    } catch (LdapException e) {
        ResultCode errorCode = e.getResult().getResultCode();
        if (errorCode.equals(ResultCode.SIZE_LIMIT_EXCEEDED)) {
            debug.message("SearchResultIterator: size limit exceeded");
        } else {
            debug.error("SearchResultIterator.hasNext", e);
        }
    } catch (SearchResultReferenceIOException e) {
        debug.error("SearchResultIterator.hasNext: reference should be already handled", e);
        return hasNext();
    }
    conn.close();
    return false;
}
Also used : SMSDataEntry(com.sun.identity.sm.SMSDataEntry) SearchResultReferenceIOException(org.forgerock.opendj.ldap.SearchResultReferenceIOException) LdapException(org.forgerock.opendj.ldap.LdapException) ResultCode(org.forgerock.opendj.ldap.ResultCode) SearchResultEntry(org.forgerock.opendj.ldap.responses.SearchResultEntry)

Example 2 with SMSDataEntry

use of com.sun.identity.sm.SMSDataEntry in project OpenAM by OpenRock.

the class SearchResultIterator method next.

public SMSDataEntry next() {
    SMSDataEntry tmp = current;
    current = null;
    return tmp;
}
Also used : SMSDataEntry(com.sun.identity.sm.SMSDataEntry)

Example 3 with SMSDataEntry

use of com.sun.identity.sm.SMSDataEntry 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 4 with SMSDataEntry

use of com.sun.identity.sm.SMSDataEntry in project OpenAM by OpenRock.

the class ResourceTypeConfigurationImpl method getResourceTypes.

@Override
public Set<ResourceType> getResourceTypes(final QueryFilter<SmsAttribute> queryFilter, final Subject subject, final String realm) throws EntitlementException {
    final SSOToken token = SubjectUtils.getSSOToken(subject);
    final String dn = getResourceTypeBaseDN(realm);
    final Filter filter = queryFilter.accept(new SmsQueryFilterVisitor(), null);
    final Set<ResourceType> resourceTypes = new HashSet<ResourceType>();
    try {
        if (SMSEntry.checkIfEntryExists(dn, token)) {
            // Interaction with legacy service.
            @SuppressWarnings("unchecked") final Iterator<SMSDataEntry> iterator = (Iterator<SMSDataEntry>) SMSEntry.search(token, dn, filter.toString(), 0, 0, false, false, Collections.emptySet());
            while (iterator.hasNext()) {
                final SMSDataEntry entry = iterator.next();
                final String name = entry.getAttributeValue(CONFIG_NAME);
                // Extract the resource types UUID from the LDAP DN representation.
                final String uuid = LDAPUtils.getName(DN.valueOf(entry.getDN()));
                // Interaction with legacy service.
                @SuppressWarnings("unchecked") final Set<String> actionSet = entry.getAttributeValues(CONFIG_ACTIONS);
                final Map<String, Boolean> actions = getActions(actionSet);
                // Interaction with legacy service.
                @SuppressWarnings("unchecked") final Set<String> resources = entry.getAttributeValues(CONFIG_PATTERNS);
                final String description = entry.getAttributeValue(CONFIG_DESCRIPTION);
                final String createdBy = entry.getAttributeValue(CONFIG_CREATED_BY);
                final String creationDate = entry.getAttributeValue(CONFIG_CREATION_DATE);
                final String modifiedBy = entry.getAttributeValue(CONFIG_LAST_MODIFIED_BY);
                final String modifiedDate = entry.getAttributeValue(CONFIG_LAST_MODIFIED_DATE);
                final ResourceType resourceType = ResourceType.builder().setUUID(uuid).setName(name).setActions(actions).setPatterns(resources).setDescription(description).setCreatedBy(createdBy).setCreationDate(Long.parseLong(creationDate)).setLastModifiedBy(modifiedBy).setLastModifiedDate(Long.parseLong(modifiedDate)).build();
                resourceTypes.add(resourceType);
            }
        }
    } catch (SMSException smsE) {
        throw new EntitlementException(RESOURCE_TYPE_RETRIEVAL_ERROR, realm, smsE);
    }
    return resourceTypes;
}
Also used : SSOToken(com.iplanet.sso.SSOToken) SMSDataEntry(com.sun.identity.sm.SMSDataEntry) SMSException(com.sun.identity.sm.SMSException) ResourceType(org.forgerock.openam.entitlement.ResourceType) EntitlementException(com.sun.identity.entitlement.EntitlementException) Filter(org.forgerock.opendj.ldap.Filter) QueryFilter(org.forgerock.util.query.QueryFilter) Iterator(java.util.Iterator) HashSet(java.util.HashSet)

Example 5 with SMSDataEntry

use of com.sun.identity.sm.SMSDataEntry in project OpenAM by OpenRock.

the class DataStore method searchPrivileges.

private Set<IPrivilege> searchPrivileges(String realm, BufferedIterator iterator, ResourceSearchIndexes indexes, Set<String> subjectIndexes, boolean bSubTree, Set<String> excludeDNs) throws EntitlementException {
    Set<IPrivilege> results = new HashSet<IPrivilege>();
    String filter = getFilter(indexes, subjectIndexes, bSubTree);
    String baseDN = getSearchBaseDN(realm, null);
    if (PolicyConstants.DEBUG.messageEnabled()) {
        PolicyConstants.DEBUG.message("[PolicyEval] DataStore.searchPrivileges");
        PolicyConstants.DEBUG.message("[PolicyEval] search filter: " + filter);
        PolicyConstants.DEBUG.message("[PolicyEval] search DN: " + baseDN);
    }
    if (filter != null) {
        SSOToken token = (SSOToken) AccessController.doPrivileged(AdminTokenAction.getInstance());
        long start = DB_MONITOR_PRIVILEGE.start();
        if (SMSEntry.checkIfEntryExists(baseDN, token)) {
            try {
                Iterator i = SMSEntry.search(token, baseDN, filter, NO_LIMIT, NO_LIMIT, NOT_SORTED, NOT_SORTED, excludeDNs);
                while (i.hasNext()) {
                    SMSDataEntry e = (SMSDataEntry) i.next();
                    Privilege privilege = Privilege.getInstance(new JSONObject(e.getAttributeValue(SERIALIZABLE_INDEX_KEY)));
                    iterator.add(privilege);
                    results.add(privilege);
                }
            } catch (JSONException e) {
                Object[] arg = { baseDN };
                throw new EntitlementException(52, arg, e);
            } catch (SMSException e) {
                Object[] arg = { baseDN };
                throw new EntitlementException(52, arg, e);
            }
        }
        DB_MONITOR_PRIVILEGE.end(start);
    }
    return results;
}
Also used : SSOToken(com.iplanet.sso.SSOToken) SMSDataEntry(com.sun.identity.sm.SMSDataEntry) SMSException(com.sun.identity.sm.SMSException) JSONException(org.json.JSONException) EntitlementException(com.sun.identity.entitlement.EntitlementException) JSONObject(org.json.JSONObject) IPrivilege(com.sun.identity.entitlement.IPrivilege) BufferedIterator(com.sun.identity.shared.BufferedIterator) Iterator(java.util.Iterator) IPrivilege(com.sun.identity.entitlement.IPrivilege) Privilege(com.sun.identity.entitlement.Privilege) ReferralPrivilege(com.sun.identity.entitlement.ReferralPrivilege) HashSet(java.util.HashSet)

Aggregations

SMSDataEntry (com.sun.identity.sm.SMSDataEntry)15 SMSException (com.sun.identity.sm.SMSException)8 HashSet (java.util.HashSet)8 EntitlementException (com.sun.identity.entitlement.EntitlementException)7 SSOToken (com.iplanet.sso.SSOToken)6 Iterator (java.util.Iterator)6 JSONException (org.json.JSONException)6 ReferralPrivilege (com.sun.identity.entitlement.ReferralPrivilege)5 JSONObject (org.json.JSONObject)5 BufferedIterator (com.sun.identity.shared.BufferedIterator)4 IPrivilege (com.sun.identity.entitlement.IPrivilege)3 Privilege (com.sun.identity.entitlement.Privilege)3 ArrayList (java.util.ArrayList)3 Test (org.testng.annotations.Test)2 SSOException (com.iplanet.sso.SSOException)1 SMSObject (com.sun.identity.sm.SMSObject)1 LinkedHashSet (java.util.LinkedHashSet)1 NamingException (javax.naming.NamingException)1 ResourceType (org.forgerock.openam.entitlement.ResourceType)1 IndexRuleTree (org.forgerock.openam.entitlement.utils.indextree.IndexRuleTree)1