Search in sources :

Example 1 with Rule

use of org.simbasecurity.core.domain.Rule in project simba-os by cegeka.

the class RuleDatabaseRepositoryTest method canFindAllRulesNotLinkedToAPolicy.

@Test
public void canFindAllRulesNotLinkedToAPolicy() throws Exception {
    ResourceRuleEntity notLinkedRule = new ResourceRuleEntity("hipiejipie");
    notLinkedRule.setResourceName("hipiejipie");
    persistAndRefresh(notLinkedRule);
    Policy anotherPolicy = new PolicyEntity("hipiepolicy");
    anotherPolicy.addRule(notLinkedRule);
    persistAndRefresh(anotherPolicy);
    Collection<Rule> rules = ruleDatabaseRepository.findNotLinked(policy);
    assertTrue(rules.containsAll(Arrays.asList(notLinkedRule)));
}
Also used : Policy(org.simbasecurity.core.domain.Policy) PolicyEntity(org.simbasecurity.core.domain.PolicyEntity) Rule(org.simbasecurity.core.domain.Rule) ResourceRule(org.simbasecurity.core.domain.ResourceRule) URLRule(org.simbasecurity.core.domain.URLRule) ResourceRuleEntity(org.simbasecurity.core.domain.ResourceRuleEntity) Test(org.junit.Test)

Example 2 with Rule

use of org.simbasecurity.core.domain.Rule in project simba-os by cegeka.

the class PolicyManagerService method addRules.

@RequestMapping("addRules")
@ResponseBody
public void addRules(@JsonBody("policy") PolicyDTO policy, @JsonBody("rules") Set<RuleDTO> rules) {
    Policy attachedPolicy = policyRepository.refreshWithOptimisticLocking(policy);
    Collection<Rule> attachedRules = ruleRepository.refreshWithOptimisticLocking(rules);
    attachedPolicy.addRules(attachedRules);
}
Also used : Policy(org.simbasecurity.core.domain.Policy) Rule(org.simbasecurity.core.domain.Rule) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Example 3 with Rule

use of org.simbasecurity.core.domain.Rule in project simba-os by cegeka.

the class PolicyManagerService method removeRule.

@RequestMapping("removeRule")
@ResponseBody
public void removeRule(@JsonBody("policy") PolicyDTO policy, @JsonBody("rule") RuleDTO rule) {
    Policy attachedPolicy = policyRepository.refreshWithOptimisticLocking(policy);
    Rule attachedRule = ruleRepository.refreshWithOptimisticLocking(rule);
    attachedPolicy.removeRule(attachedRule);
}
Also used : Policy(org.simbasecurity.core.domain.Policy) Rule(org.simbasecurity.core.domain.Rule) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Example 4 with Rule

use of org.simbasecurity.core.domain.Rule 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());
}
Also used : URLRuleDTO(org.simbasecurity.core.service.manager.dto.URLRuleDTO) RuleDTO(org.simbasecurity.core.service.manager.dto.RuleDTO) ResourceRuleDTO(org.simbasecurity.core.service.manager.dto.ResourceRuleDTO) ResourceRule(org.simbasecurity.core.domain.ResourceRule) URLRule(org.simbasecurity.core.domain.URLRule) Rule(org.simbasecurity.core.domain.Rule) Test(org.junit.Test)

Aggregations

Rule (org.simbasecurity.core.domain.Rule)4 Policy (org.simbasecurity.core.domain.Policy)3 Test (org.junit.Test)2 ResourceRule (org.simbasecurity.core.domain.ResourceRule)2 URLRule (org.simbasecurity.core.domain.URLRule)2 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)2 ResponseBody (org.springframework.web.bind.annotation.ResponseBody)2 PolicyEntity (org.simbasecurity.core.domain.PolicyEntity)1 ResourceRuleEntity (org.simbasecurity.core.domain.ResourceRuleEntity)1 ResourceRuleDTO (org.simbasecurity.core.service.manager.dto.ResourceRuleDTO)1 RuleDTO (org.simbasecurity.core.service.manager.dto.RuleDTO)1 URLRuleDTO (org.simbasecurity.core.service.manager.dto.URLRuleDTO)1