use of org.simbasecurity.core.service.AuthorizationRequestContext in project simba-os by cegeka.
the class AuthorizationServiceImpl method isURLRuleAllowed.
private PolicyDecision isURLRuleAllowed(String username, String url, URLOperationType operationType) {
AuthorizationRequestContext context = new AuthorizationRequestContext(username);
Collection<URLRule> rules = ruleRepository.findURLRules(username);
PolicyDecision decision = null;
for (URLRule rule : rules) {
if (FilenameUtils.wildcardMatch(url, rule.getResourceName())) {
boolean allowed = rule.getPolicy().applies(context) && rule.isAllowed(operationType);
long newTimestamp = rule.getPolicy().getExpirationTimestamp(context);
decision = determineDecisionBasedOn(decision, allowed, newTimestamp);
}
}
if (decision == null) {
decision = NEVER_ALLOWED;
}
logAuthorizationDecision(username, URL_RESOURCE_LABEL + url + LOG_DELIM + operationType.name() + LOG_DELIM + decision.toString());
return decision;
}
use of org.simbasecurity.core.service.AuthorizationRequestContext in project simba-os by cegeka.
the class ConditionDTOAssemblerTest method testAssembleSingleCondition_Failure.
@Test(expected = IllegalArgumentException.class)
public void testAssembleSingleCondition_Failure() {
@SuppressWarnings("serial") Condition condition = new ConditionEntity() {
@Override
protected boolean conditionApplies(AuthorizationRequestContext context) {
return false;
}
};
ConditionDTOAssembler.assemble(condition);
}
use of org.simbasecurity.core.service.AuthorizationRequestContext in project simba-os by cegeka.
the class AuthorizationServiceImpl method isResourceRuleAllowed.
private PolicyDecision isResourceRuleAllowed(String username, String resourceName, ResourceOperationType operationType) {
AuthorizationRequestContext context = new AuthorizationRequestContext(username);
Collection<ResourceRule> resourceRules = ruleRepository.findResourceRules(username, resourceName);
PolicyDecision decision = null;
for (ResourceRule resourceRule : resourceRules) {
boolean allowed = resourceRule.getPolicy().applies(context) && resourceRule.isAllowed(operationType);
long newTimestamp = resourceRule.getPolicy().getExpirationTimestamp(context);
decision = determineDecisionBasedOn(decision, allowed, newTimestamp);
}
if (decision == null) {
decision = NEVER_ALLOWED;
}
logAuthorizationDecision(username, RESOURCE_LABEL + resourceName + LOG_DELIM + operationType.name() + LOG_DELIM + decision.toString());
return decision;
}
Aggregations