Search in sources :

Example 1 with PolicyEntity

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());
}
Also used : Policy(org.simbasecurity.core.domain.Policy) PolicyDTO(org.simbasecurity.core.service.manager.dto.PolicyDTO) PolicyEntity(org.simbasecurity.core.domain.PolicyEntity) Test(org.junit.Test)

Example 2 with PolicyEntity

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)));
}
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 3 with PolicyEntity

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;
}
Also used : Role(org.simbasecurity.core.domain.Role) RoleEntity(org.simbasecurity.core.domain.RoleEntity) Policy(org.simbasecurity.core.domain.Policy) Group(org.simbasecurity.core.domain.Group) User(org.simbasecurity.core.domain.User) GroupEntity(org.simbasecurity.core.domain.GroupEntity) PolicyEntity(org.simbasecurity.core.domain.PolicyEntity) ResourceRule(org.simbasecurity.core.domain.ResourceRule) ResourceRuleEntity(org.simbasecurity.core.domain.ResourceRuleEntity) UserEntity(org.simbasecurity.core.domain.UserEntity) URLRuleEntity(org.simbasecurity.core.domain.URLRuleEntity)

Example 4 with PolicyEntity

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);
        }
    });
}
Also used : TPolicy(org.simbasecurity.api.service.thrift.TPolicy) Policy(org.simbasecurity.core.domain.Policy) ValidationException(org.owasp.esapi.errors.ValidationException) PolicyEntity(org.simbasecurity.core.domain.PolicyEntity)

Example 5 with PolicyEntity

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());
}
Also used : Policy(org.simbasecurity.core.domain.Policy) PolicyDTO(org.simbasecurity.core.service.manager.dto.PolicyDTO) PolicyEntity(org.simbasecurity.core.domain.PolicyEntity) Test(org.junit.Test)

Aggregations

PolicyEntity (org.simbasecurity.core.domain.PolicyEntity)6 Policy (org.simbasecurity.core.domain.Policy)5 Test (org.junit.Test)3 ResourceRuleEntity (org.simbasecurity.core.domain.ResourceRuleEntity)3 ResourceRule (org.simbasecurity.core.domain.ResourceRule)2 RoleEntity (org.simbasecurity.core.domain.RoleEntity)2 URLRuleEntity (org.simbasecurity.core.domain.URLRuleEntity)2 UserEntity (org.simbasecurity.core.domain.UserEntity)2 PolicyDTO (org.simbasecurity.core.service.manager.dto.PolicyDTO)2 Before (org.junit.Before)1 ValidationException (org.owasp.esapi.errors.ValidationException)1 TPolicy (org.simbasecurity.api.service.thrift.TPolicy)1 Group (org.simbasecurity.core.domain.Group)1 GroupEntity (org.simbasecurity.core.domain.GroupEntity)1 Role (org.simbasecurity.core.domain.Role)1 Rule (org.simbasecurity.core.domain.Rule)1 URLRule (org.simbasecurity.core.domain.URLRule)1 User (org.simbasecurity.core.domain.User)1