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);
}
}
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;
}
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");
}
}
}
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());
}
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");
}
Aggregations