use of org.simbasecurity.core.domain.Policy in project simba-os by cegeka.
the class PolicyDTOAssemblerTest method testAssembleMultiplePolicies.
@Test
public void testAssembleMultiplePolicies() {
Policy policy = new PolicyEntity("policy name");
Collection<PolicyDTO> policyDataList = PolicyDTOAssembler.assemble(Arrays.asList(policy));
assertNotNull(policyDataList);
assertEquals(1, policyDataList.size());
}
use of org.simbasecurity.core.domain.Policy 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)));
}
use of org.simbasecurity.core.domain.Policy in project simba-os by cegeka.
the class RuleDatabaseRepositoryTest method setupWithGroups.
private ResourceRule setupWithGroups() {
User user = new UserEntity(USER_VIA_GROUP);
Role role = new RoleEntity("role2");
Group group = new GroupEntity("groupName", "cn");
Policy policy = new PolicyEntity("policy2");
ResourceRule resourceRuleEntity = new ResourceRuleEntity("resrule2");
resourceRuleEntity.setResourceName("resname2");
urlRuleEntityViaGroup = new URLRuleEntity("urlrule2");
persistAndRefresh(user, role, policy, resourceRuleEntity, urlRuleEntityViaGroup);
persistAndRefresh(user, group, role, policy, resourceRuleEntity, urlRuleEntityViaGroup);
policy.addRule(resourceRuleEntity);
policy.addRule(urlRuleEntityViaGroup);
role.addPolicy(policy);
group.addRole(role);
user.addGroup(group);
return resourceRuleEntity;
}
use of org.simbasecurity.core.domain.Policy 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);
}
use of org.simbasecurity.core.domain.Policy in project simba-os by cegeka.
the class PolicyManagerService method createPolicy.
@RequestMapping("create")
@ResponseBody
public PolicyDTO createPolicy(@RequestBody String policyName) throws ValidationException {
DTOValidator.assertValidString("createRole", policyName);
if (roleRepository.findByName(policyName) != null) {
throw new IllegalArgumentException("Policy with name " + policyName + " already exists");
}
Policy newPolicy = PolicyAssembler.createPolicy(policyName);
policyRepository.persist(newPolicy);
return PolicyDTOAssembler.assemble(newPolicy);
}
Aggregations