use of org.simbasecurity.core.domain.URLRule 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.domain.URLRule in project simba-os by cegeka.
the class RuleDatabaseRepository method findURLRules.
@SuppressWarnings("unchecked")
public Collection<URLRule> findURLRules(String username) {
Query query1 = entityManager.createQuery(QUERY_URL_RULES_FOR_USER).setParameter(USERNAME, username);
Collection<URLRule> result = query1.getResultList();
Query query = entityManager.createQuery(QUERY_URL_RULES_FOR_GROUPUSER).setParameter(USERNAME, username);
result.addAll(query.getResultList());
return result;
}
use of org.simbasecurity.core.domain.URLRule in project simba-os by cegeka.
the class RuleDTOAssemblerTest method testAssembleSingleRule_UrlRule.
@Test
public void testAssembleSingleRule_UrlRule() {
URLRule urlRule = createUrlRule();
URLRuleDTO ruleData = (URLRuleDTO) RuleDTOAssembler.assemble(urlRule);
assertNotNull(ruleData);
assertEquals(urlRule.getName(), ruleData.getName());
assertEquals(urlRule.getResourceName(), ruleData.getResourceName());
assertEquals(true, ruleData.isGetAllowed());
assertEquals(true, ruleData.isPostAllowed());
assertEquals(0, ruleData.getId());
assertEquals(0, ruleData.getVersion());
}
use of org.simbasecurity.core.domain.URLRule in project simba-os by cegeka.
the class RuleDTOAssemblerTest method testAssembleMultipleRules.
@Test
public void testAssembleMultipleRules() {
Rule resourceRule = createResourceRule();
Rule urlRule = createUrlRule();
Collection<RuleDTO> ruleDataList = RuleDTOAssembler.assemble(Arrays.asList(resourceRule, urlRule));
assertNotNull(ruleDataList);
assertEquals(2, ruleDataList.size());
}
Aggregations