use of com.sun.identity.entitlement.RegExResourceName in project OpenAM by OpenRock.
the class ConstraintValidatorImpl method validateResourceNames.
/**
* Verifies a resource against the set of allowed patterns with help from the resource handler.
*
* @param resource
* the resource
* @param patterns
* the allowed patterns
* @param resourceHandler
* the resource handler
*
* @return whether the resource successfully matched against one of the patterns
*/
private boolean validateResourceNames(String resource, Set<String> patterns, ResourceName resourceHandler) {
if (resourceHandler instanceof RegExResourceName) {
return validateResourceNamesUsingRegex(resource, patterns, (RegExResourceName) resourceHandler);
}
for (String pattern : patterns) {
// This approach of swapping the pattern and the resource during comparison has been inherited.
// For now this has been preserved until its purpose becomes more clear.
ResourceMatch match = resourceHandler.compare(pattern, resource, false);
if (match == ResourceMatch.EXACT_MATCH || match == ResourceMatch.SUB_RESOURCE_MATCH) {
return true;
}
match = resourceHandler.compare(resource, pattern, true);
if (match == ResourceMatch.WILDCARD_MATCH) {
return true;
}
}
return false;
}
use of com.sun.identity.entitlement.RegExResourceName in project OpenAM by OpenRock.
the class OpenSSOApplicationPrivilegeManager method isDelegatableResource.
private boolean isDelegatableResource(Application appl, String res) {
Set<String> resources = getDelegatableResourceNames(appl.getName());
if ((resources != null) && !resources.isEmpty()) {
ResourceName resComp = appl.getResourceComparator();
boolean isRegEx = (resComp instanceof RegExResourceName);
for (String r : resources) {
if (!r.endsWith("*")) {
if (!r.endsWith("/")) {
r += "/";
}
r += "*";
}
if (isRegEx) {
ResourceMatch result = resComp.compare(res, r, true);
if (result.equals(ResourceMatch.EXACT_MATCH) || result.equals(ResourceMatch.SUB_RESOURCE_MATCH) || result.equals(ResourceMatch.WILDCARD_MATCH)) {
return true;
}
} else {
ResourceMatch result = resComp.compare(r, res, false);
if (result.equals(ResourceMatch.EXACT_MATCH) || result.equals(ResourceMatch.SUB_RESOURCE_MATCH)) {
return true;
}
result = resComp.compare(res, r, true);
if (result.equals(ResourceMatch.EXACT_MATCH) || result.equals(ResourceMatch.SUB_RESOURCE_MATCH) || result.equals(ResourceMatch.WILDCARD_MATCH)) {
return true;
}
}
}
}
return false;
}
Aggregations