Search in sources :

Example 21 with Policy

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

the class PolicyServiceImpl method addRules.

@Override
public void addRules(TPolicy policy, Set<TRule> rules) throws TException {
    simbaExceptionHandlingCaller.call(() -> {
        Policy attachedPolicy = policyRepository.refreshWithOptimisticLocking(policy.getId(), policy.getVersion());
        Set<Rule> attachedRules = rules.stream().map(r -> ruleRepository.refreshWithOptimisticLocking(r.getId(), r.getVersion())).collect(Collectors.toSet());
        audit.log("Rules ''{0}'' added to policy ''{1}''", join(attachedRules, Rule::getName), attachedPolicy.getName());
        attachedPolicy.addRules(attachedRules);
    });
}
Also used : TPolicy(org.simbasecurity.api.service.thrift.TPolicy) Policy(org.simbasecurity.core.domain.Policy) PolicyRepository(org.simbasecurity.core.domain.repository.PolicyRepository) RoleRepository(org.simbasecurity.core.domain.repository.RoleRepository) Autowired(org.springframework.beans.factory.annotation.Autowired) PolicyEntity(org.simbasecurity.core.domain.PolicyEntity) SimbaExceptionHandlingCaller(org.simbasecurity.core.service.errors.SimbaExceptionHandlingCaller) EntityFilterService(org.simbasecurity.core.service.filter.EntityFilterService) StringUtil.join(org.simbasecurity.common.util.StringUtil.join) TPolicy(org.simbasecurity.api.service.thrift.TPolicy) Service(org.springframework.stereotype.Service) DTOValidator(org.simbasecurity.core.service.validation.DTOValidator) RuleRepository(org.simbasecurity.core.domain.repository.RuleRepository) ValidationException(org.owasp.esapi.errors.ValidationException) TRole(org.simbasecurity.api.service.thrift.TRole) Role(org.simbasecurity.core.domain.Role) TException(org.apache.thrift.TException) Set(java.util.Set) TRule(org.simbasecurity.api.service.thrift.TRule) Collectors(java.util.stream.Collectors) Rule(org.simbasecurity.core.domain.Rule) ManagementAudit(org.simbasecurity.core.audit.ManagementAudit) List(java.util.List) Policy(org.simbasecurity.core.domain.Policy) ThriftAssembler(org.simbasecurity.core.service.thrift.ThriftAssembler) PolicyService(org.simbasecurity.api.service.thrift.PolicyService) Transactional(org.springframework.transaction.annotation.Transactional) TRule(org.simbasecurity.api.service.thrift.TRule) Rule(org.simbasecurity.core.domain.Rule)

Example 22 with Policy

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

the class PolicyServiceImpl method deletePolicy.

@Override
public void deletePolicy(TPolicy policy) throws TException {
    simbaExceptionHandlingCaller.call(() -> {
        Policy policyToRemove = policyRepository.lookUp(policy.getId());
        audit.log("Policy ''{0}'' removed", policyToRemove.getName());
        policyRepository.remove(policyToRemove);
    });
}
Also used : TPolicy(org.simbasecurity.api.service.thrift.TPolicy) Policy(org.simbasecurity.core.domain.Policy)

Example 23 with Policy

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

the class PolicyServiceImpl method removeRole.

@Override
public void removeRole(TPolicy policy, TRole role) throws TException {
    simbaExceptionHandlingCaller.call(() -> {
        Policy attachedPolicy = policyRepository.refreshWithOptimisticLocking(policy.getId(), policy.getVersion());
        Role attachedRole = roleRepository.refreshWithOptimisticLocking(role.getId(), role.getVersion());
        audit.log("Role ''{0}'' removed from policy ''{1}''", attachedRole.getName(), attachedPolicy.getName());
        attachedPolicy.removeRole(attachedRole);
    });
}
Also used : TPolicy(org.simbasecurity.api.service.thrift.TPolicy) Policy(org.simbasecurity.core.domain.Policy) TRole(org.simbasecurity.api.service.thrift.TRole) Role(org.simbasecurity.core.domain.Role)

Example 24 with Policy

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

the class RoleServiceImpl method addPolicy.

public void addPolicy(TRole role, TPolicy policy) throws TException {
    simbaExceptionHandlingCaller.call(() -> {
        final Role attachedRole = roleRepository.refreshWithOptimisticLocking(role.getId(), role.getVersion());
        final Policy attachedPolicy = policyRepository.refreshWithOptimisticLocking(policy.getId(), policy.getVersion());
        attachedRole.addPolicy(attachedPolicy);
        managementAudit.log("Policy ''{0}'' added to role ''{1}''", attachedPolicy.getName(), attachedRole.getName());
        roleRepository.persist(attachedRole);
    });
}
Also used : Role(org.simbasecurity.core.domain.Role) Policy(org.simbasecurity.core.domain.Policy)

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