Search in sources :

Example 16 with Policy

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

the class PolicyServiceImpl method removeRule.

@Override
public void removeRule(TPolicy policy, TRule rule) throws TException {
    simbaExceptionHandlingCaller.call(() -> {
        Policy attachedPolicy = policyRepository.refreshWithOptimisticLocking(policy.getId(), policy.getVersion());
        Rule attachedRule = ruleRepository.refreshWithOptimisticLocking(rule.getId(), rule.getVersion());
        audit.log("Rule ''{0}'' removed from ''{1}''", attachedRule.getName(), attachedPolicy.getName());
        attachedPolicy.removeRule(attachedRule);
    });
}
Also used : TPolicy(org.simbasecurity.api.service.thrift.TPolicy) Policy(org.simbasecurity.core.domain.Policy) TRule(org.simbasecurity.api.service.thrift.TRule) Rule(org.simbasecurity.core.domain.Rule)

Example 17 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 18 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 19 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 20 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)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