Search in sources :

Example 11 with Policy

use of org.simbasecurity.core.domain.Policy 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)

Example 12 with Policy

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

the class PolicyManagerService method removeRole.

@RequestMapping("removeRole")
@ResponseBody
public void removeRole(@JsonBody("policy") PolicyDTO policy, @JsonBody("role") RoleDTO role) {
    Policy attachedPolicy = policyRepository.refreshWithOptimisticLocking(policy);
    Role attachedRole = roleRepository.refreshWithOptimisticLocking(role);
    attachedPolicy.removeRole(attachedRole);
}
Also used : Policy(org.simbasecurity.core.domain.Policy) Role(org.simbasecurity.core.domain.Role) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Example 13 with Policy

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

the class RoleManagerService method addPolicy.

@RequestMapping("addPolicy")
@ResponseBody
public void addPolicy(@JsonBody("role") RoleDTO role, @JsonBody("policy") PolicyDTO policy) {
    final Role attachedRole = roleRepository.refreshWithOptimisticLocking(role);
    final Policy attachedPolicy = policyRepository.refreshWithOptimisticLocking(policy);
    attachedRole.addPolicy(attachedPolicy);
    roleRepository.persist(attachedRole);
}
Also used : Role(org.simbasecurity.core.domain.Role) Policy(org.simbasecurity.core.domain.Policy) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Example 14 with Policy

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

the class RoleManagerService method addPolicies.

@RequestMapping("addPolicies")
@ResponseBody
public void addPolicies(@JsonBody("role") RoleDTO role, @JsonBody("policies") List<PolicyDTO> policies) {
    Role attachedRole = roleRepository.refreshWithOptimisticLocking(role);
    Collection<Policy> attachedPolicies = policyRepository.refreshWithOptimisticLocking(policies);
    attachedRole.addPolicies(attachedPolicies);
    roleRepository.persist(attachedRole);
}
Also used : Role(org.simbasecurity.core.domain.Role) 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)14 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)10 ResponseBody (org.springframework.web.bind.annotation.ResponseBody)10 Role (org.simbasecurity.core.domain.Role)6 PolicyEntity (org.simbasecurity.core.domain.PolicyEntity)4 Test (org.junit.Test)3 Rule (org.simbasecurity.core.domain.Rule)3 ResourceRule (org.simbasecurity.core.domain.ResourceRule)2 ResourceRuleEntity (org.simbasecurity.core.domain.ResourceRuleEntity)2 User (org.simbasecurity.core.domain.User)2 PolicyDTO (org.simbasecurity.core.service.manager.dto.PolicyDTO)2 Condition (org.simbasecurity.core.domain.Condition)1 Group (org.simbasecurity.core.domain.Group)1 GroupEntity (org.simbasecurity.core.domain.GroupEntity)1 RoleEntity (org.simbasecurity.core.domain.RoleEntity)1 URLRule (org.simbasecurity.core.domain.URLRule)1 URLRuleEntity (org.simbasecurity.core.domain.URLRuleEntity)1 UserEntity (org.simbasecurity.core.domain.UserEntity)1