use of org.simbasecurity.core.domain.PolicyEntity 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.PolicyEntity 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.PolicyEntity 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.PolicyEntity in project simba-os by cegeka.
the class PolicyServiceImpl method createPolicy.
@Override
public TPolicy createPolicy(String policyName) throws TException {
return simbaExceptionHandlingCaller.call(() -> {
try {
DTOValidator.assertValidString("createRole", policyName);
if (roleRepository.findByName(policyName) != null) {
throw new IllegalArgumentException("Policy with name " + policyName + " already exists");
}
Policy newPolicy = new PolicyEntity(policyName);
policyRepository.persist(newPolicy);
audit.log("Policy ''{0}'' created", policyName);
return assembler.assemble(newPolicy);
} catch (ValidationException e) {
throw new IllegalArgumentException(e);
}
});
}
use of org.simbasecurity.core.domain.PolicyEntity in project simba-os by cegeka.
the class PolicyDTOAssemblerTest method testAssembleSinglePolicy.
@Test
public void testAssembleSinglePolicy() {
Policy policy = new PolicyEntity("policy name");
PolicyDTO policyData = PolicyDTOAssembler.assemble(policy);
assertNotNull(policyData);
assertEquals(0, policyData.getId());
assertEquals(policy.getName(), policyData.getName());
assertEquals(0, policyData.getId());
assertEquals(0, policyData.getVersion());
}
Aggregations