Search in sources :

Example 1 with Policy

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());
}
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 Policy

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)));
}
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 Policy

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;
}
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 Policy

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);
}
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 5 with Policy

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);
}
Also used : Policy(org.simbasecurity.core.domain.Policy) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Aggregations

Policy (org.simbasecurity.core.domain.Policy)24 Role (org.simbasecurity.core.domain.Role)12 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)10 ResponseBody (org.springframework.web.bind.annotation.ResponseBody)10 PolicyEntity (org.simbasecurity.core.domain.PolicyEntity)7 TPolicy (org.simbasecurity.api.service.thrift.TPolicy)6 Rule (org.simbasecurity.core.domain.Rule)6 List (java.util.List)4 Set (java.util.Set)4 TException (org.apache.thrift.TException)4 ValidationException (org.owasp.esapi.errors.ValidationException)4 User (org.simbasecurity.core.domain.User)4 PolicyRepository (org.simbasecurity.core.domain.repository.PolicyRepository)4 SimbaExceptionHandlingCaller (org.simbasecurity.core.service.errors.SimbaExceptionHandlingCaller)4 ThriftAssembler (org.simbasecurity.core.service.thrift.ThriftAssembler)4 Autowired (org.springframework.beans.factory.annotation.Autowired)4 Service (org.springframework.stereotype.Service)4 Transactional (org.springframework.transaction.annotation.Transactional)4 Collectors (java.util.stream.Collectors)3 Test (org.junit.Test)3