Search in sources :

Example 6 with Policy

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

the class PolicyManagerService method addRoles.

@RequestMapping("addRoles")
@ResponseBody
public void addRoles(@JsonBody("policy") PolicyDTO policy, @JsonBody("roles") Set<RoleDTO> roles) {
    Policy attachedPolicy = policyRepository.refreshWithOptimisticLocking(policy);
    Collection<Role> attachedRoles = roleRepository.refreshWithOptimisticLocking(roles);
    attachedPolicy.addRoles(attachedRoles);
}
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 7 with Policy

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

the class RoleManagerService method removePolicy.

@RequestMapping("removePolicy")
@ResponseBody
public void removePolicy(@JsonBody("role") RoleDTO role, @JsonBody("policy") PolicyDTO policy) {
    Role attachedRole = roleRepository.refreshWithOptimisticLocking(role);
    Policy attachedPolicy = policyRepository.refreshWithOptimisticLocking(policy);
    attachedRole.removePolicy(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 8 with Policy

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

the class ConditionManagerService method addOrUpdate.

@RequestMapping("addOrUpdate")
@ResponseBody
public ConditionDTO addOrUpdate(@RequestBody ConditionWithPoliciesAndExcludedUsersDTO conditionWithPoliciesAndExcludedUsersDTO) {
    final Condition attachedCondition = findOrCreate(conditionWithPoliciesAndExcludedUsersDTO.getCondition());
    final Collection<User> attachedUsers = userRepository.refreshWithOptimisticLocking(conditionWithPoliciesAndExcludedUsersDTO.getExcludedUsers());
    attachedCondition.setExemptedUsers(new HashSet<>(attachedUsers));
    final Collection<Policy> attachedPolicies = policyRepository.refreshWithOptimisticLocking(conditionWithPoliciesAndExcludedUsersDTO.getPolicies());
    conditionRepository.updatePolicies(attachedCondition, attachedPolicies);
    conditionRepository.flush();
    return assemble(attachedCondition);
}
Also used : Condition(org.simbasecurity.core.domain.Condition) Policy(org.simbasecurity.core.domain.Policy) User(org.simbasecurity.core.domain.User) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Example 9 with Policy

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

the class PolicyManagerService method removeRule.

@RequestMapping("removeRule")
@ResponseBody
public void removeRule(@JsonBody("policy") PolicyDTO policy, @JsonBody("rule") RuleDTO rule) {
    Policy attachedPolicy = policyRepository.refreshWithOptimisticLocking(policy);
    Rule attachedRule = ruleRepository.refreshWithOptimisticLocking(rule);
    attachedPolicy.removeRule(attachedRule);
}
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 10 with Policy

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

the class PolicyManagerService method deletePolicy.

@RequestMapping("delete")
@ResponseBody
public void deletePolicy(@JsonBody("policy") PolicyDTO policy) throws ValidationException {
    DTOValidator.assertValid(policy);
    Policy policyToRemove = policyRepository.lookUp(policy);
    policyRepository.remove(policyToRemove);
}
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)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