Search in sources :

Example 1 with ResourceSearchIndexes

use of com.sun.identity.entitlement.ResourceSearchIndexes in project OpenAM by OpenRock.

the class DelegationResourceNameSplitter method getIndexes.

@Override
public ResourceSearchIndexes getIndexes(String resource, String realm) {
    Matcher match = PATTERN.matcher(resource);
    if (!match.matches()) {
        return super.getIndexes(resource, realm);
    }
    String rootSuffix = SMSEntry.getRootSuffix();
    String dn = match.group(2);
    if (dn.trim().length() == 0) {
        dn = rootSuffix;
    }
    String prefix = match.group(1);
    String suffix = match.group(3);
    if (LDAPUtils.isDN(dn)) {
        DN rootDN = DN.valueOf(rootSuffix);
        DN dnObject = DN.valueOf(dn);
        if (rootDN.equals(dnObject)) {
            return super.getIndexes(resource, realm);
        } else {
            ResourceSearchIndexes indexes = null;
            StringBuilder buff = new StringBuilder();
            boolean start = false;
            List<RDN> rdns = new ArrayList<>();
            for (RDN rdn : dnObject) {
                rdns.add(rdn);
            }
            for (int i = rdns.size() - 1; i >= 0; --i) {
                if (buff.length() > 0) {
                    buff.insert(0, ",");
                }
                buff.insert(0, rdns.get(i).toString());
                if (!start) {
                    start = rootDN.equals(DN.valueOf(buff.toString()));
                    if (start) {
                        indexes = super.getIndexes(prefix + buff.toString() + suffix, realm);
                    }
                } else {
                    ResourceSearchIndexes idx = super.getIndexes(prefix + buff.toString() + suffix, realm);
                    indexes.addAll(idx);
                }
            }
            return indexes;
        }
    } else {
        return super.getIndexes(resource, realm);
    }
}
Also used : Matcher(java.util.regex.Matcher) ArrayList(java.util.ArrayList) RDN(org.forgerock.opendj.ldap.RDN) DN(org.forgerock.opendj.ldap.DN) ResourceSearchIndexes(com.sun.identity.entitlement.ResourceSearchIndexes) RDN(org.forgerock.opendj.ldap.RDN)

Example 2 with ResourceSearchIndexes

use of com.sun.identity.entitlement.ResourceSearchIndexes in project OpenAM by OpenRock.

the class ResourceNameSplitTest method testHost.

@Test
public boolean testHost() throws Exception {
    ResourceNameSplitter splitter = new ResourceNameSplitter();
    Map<String, Set<String>> map = parseResource("resourceNameSplitHost");
    for (String k : map.keySet()) {
        Set<String> set = map.get(k);
        ResourceSearchIndexes comp = splitter.getIndexes(k, null);
        Set<String> results = comp.getHostIndexes();
        if (!results.equals(set)) {
            String msg = "ResourceNameSplitTest.testHost: " + k + " failed.";
            UnittestLog.logError(msg);
            throw new Exception(msg);
        }
    }
    return true;
}
Also used : HashSet(java.util.HashSet) Set(java.util.Set) ResourceSearchIndexes(com.sun.identity.entitlement.ResourceSearchIndexes) Test(org.testng.annotations.Test)

Example 3 with ResourceSearchIndexes

use of com.sun.identity.entitlement.ResourceSearchIndexes in project OpenAM by OpenRock.

the class PolicyIndexTest method storeAndRetrieve.

@Test
public void storeAndRetrieve() throws SSOException, PolicyException, EntitlementException, Exception {
    SSOToken adminToken = (SSOToken) AccessController.doPrivileged(AdminTokenAction.getInstance());
    PolicyManager pm = new PolicyManager(adminToken, "/");
    Set<String> hostIndexes = new HashSet<String>();
    Set<String> pathIndexes = new HashSet<String>();
    Set<String> parentPathIndexes = new HashSet<String>();
    hostIndexes.add("http://www.sun.com");
    pathIndexes.add("/private");
    parentPathIndexes.add("/");
    ResourceSearchIndexes indexes = new ResourceSearchIndexes(hostIndexes, pathIndexes, parentPathIndexes);
    PrivilegeIndexStore pis = PrivilegeIndexStore.getInstance(SubjectUtils.createSubject(adminToken), "/");
    for (Iterator<IPrivilege> i = pis.search("/", indexes, Collections.EMPTY_SET, false); i.hasNext(); ) {
        IPrivilege eval = i.next();
        if (!(eval instanceof Privilege)) {
            throw new Exception("incorrect deserialized policy, wrong type");
        }
        Privilege p = (Privilege) eval;
        if (!p.getEntitlement().getResourceName().equals(URL_RESOURCE)) {
            throw new Exception("incorrect deserialized policy");
        }
    }
}
Also used : SSOToken(com.iplanet.sso.SSOToken) PrivilegeIndexStore(com.sun.identity.entitlement.PrivilegeIndexStore) IPrivilege(com.sun.identity.entitlement.IPrivilege) ResourceSearchIndexes(com.sun.identity.entitlement.ResourceSearchIndexes) IPrivilege(com.sun.identity.entitlement.IPrivilege) Privilege(com.sun.identity.entitlement.Privilege) EntitlementException(com.sun.identity.entitlement.EntitlementException) SSOException(com.iplanet.sso.SSOException) HashSet(java.util.HashSet) Test(org.testng.annotations.Test)

Example 4 with ResourceSearchIndexes

use of com.sun.identity.entitlement.ResourceSearchIndexes in project OpenAM by OpenRock.

the class TreeSearchIndexDelegate method getIndexes.

@Override
public ResourceSearchIndexes getIndexes(String resource, String realm) throws EntitlementException {
    // Create legacy indexes first.
    ResourceSearchIndexes legacyIndexes = legacySearchIndex.getIndexes(resource, realm);
    // Indexes are handled in lower case.
    resource = resource.toLowerCase();
    // Search the index tree for matching path indexes.
    Set<String> pathIndexes = indexTreeService.searchTree(resource, realm);
    return new ResourceSearchIndexes(legacyIndexes.getHostIndexes(), pathIndexes, legacyIndexes.getParentPathIndexes());
}
Also used : ResourceSearchIndexes(com.sun.identity.entitlement.ResourceSearchIndexes)

Example 5 with ResourceSearchIndexes

use of com.sun.identity.entitlement.ResourceSearchIndexes in project OpenAM by OpenRock.

the class TreeSearchIndexTest method parseRetrievedIndexes.

/**
     * Tests that the search index parses retrieved indexes without encoding special characters.
     */
@Test
public void parseRetrievedIndexes() throws Exception {
    // Record that the indexes set should be returned when given the test url.
    Set<String> indexes = new HashSet<String>();
    indexes.add("a-b-*-d-e");
    indexes.add("a-*-c-*-e");
    when(treeService.searchTree("http://www.test.com:80/", "/test-realm")).thenReturn(indexes);
    // Execute the actual evaluation.
    ResourceSearchIndexes result = searchIndex.getIndexes("http://www.test.com:80/", "/test-realm");
    // Verify the test results
    Set<String> parsedIndexes = new HashSet<String>();
    parsedIndexes.add("a-b-*-d-e");
    parsedIndexes.add("a-*-c-*-e");
    assertEquals(asSet("://", "://.com", "://www.test.com", "://.test.com"), result.getHostIndexes());
    assertEquals(parsedIndexes, result.getPathIndexes());
    assertEquals(asSet("/"), result.getParentPathIndexes());
    // Verify the use of the mock object.
    verify(treeService).searchTree("http://www.test.com:80/", "/test-realm");
}
Also used : ResourceSearchIndexes(com.sun.identity.entitlement.ResourceSearchIndexes) HashSet(java.util.HashSet) Test(org.testng.annotations.Test)

Aggregations

ResourceSearchIndexes (com.sun.identity.entitlement.ResourceSearchIndexes)11 HashSet (java.util.HashSet)9 Test (org.testng.annotations.Test)5 IPrivilege (com.sun.identity.entitlement.IPrivilege)3 Privilege (com.sun.identity.entitlement.Privilege)3 Set (java.util.Set)3 SSOToken (com.iplanet.sso.SSOToken)2 ApplicationPrivilege (com.sun.identity.entitlement.ApplicationPrivilege)2 ReferralPrivilege (com.sun.identity.entitlement.ReferralPrivilege)2 SSOException (com.iplanet.sso.SSOException)1 EntitlementException (com.sun.identity.entitlement.EntitlementException)1 EntitlementSubject (com.sun.identity.entitlement.EntitlementSubject)1 OrSubject (com.sun.identity.entitlement.OrSubject)1 PrivilegeIndexStore (com.sun.identity.entitlement.PrivilegeIndexStore)1 SubjectAttributesManager (com.sun.identity.entitlement.SubjectAttributesManager)1 MalformedURLException (java.net.MalformedURLException)1 ArrayList (java.util.ArrayList)1 Matcher (java.util.regex.Matcher)1 Subject (javax.security.auth.Subject)1 DN (org.forgerock.opendj.ldap.DN)1