Search in sources :

Example 1 with TPolicy

use of org.simbasecurity.api.service.thrift.TPolicy in project simba-os by cegeka.

the class PolicyServiceImpl method addRoles.

@Override
public void addRoles(TPolicy policy, Set<TRole> roles) throws TException {
    simbaExceptionHandlingCaller.call(() -> {
        Policy attachedPolicy = policyRepository.refreshWithOptimisticLocking(policy.getId(), policy.getVersion());
        Set<Role> attachedRoles = roles.stream().map(r -> roleRepository.refreshWithOptimisticLocking(r.getId(), r.getVersion())).collect(Collectors.toSet());
        audit.log("Roles ''{0}'' added to policy ''{1}''", join(attachedRoles, Role::getName), attachedPolicy.getName());
        attachedPolicy.addRoles(attachedRoles);
    });
}
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) 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)

Example 2 with TPolicy

use of org.simbasecurity.api.service.thrift.TPolicy 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 3 with TPolicy

use of org.simbasecurity.api.service.thrift.TPolicy in project simba-os by cegeka.

the class PolicyServiceImpl method createPolicy.

@Override
public TPolicy createPolicy(String policyName) throws TException {
    return simbaExceptionHandlingCaller.call(() -> {
        try {
            DTOValidator.assertValidString("createRole", policyName);
            if (roleRepository.findByName(policyName) != null) {
                throw new IllegalArgumentException("Policy with name " + policyName + " already exists");
            }
            Policy newPolicy = new PolicyEntity(policyName);
            policyRepository.persist(newPolicy);
            audit.log("Policy ''{0}'' created", policyName);
            return assembler.assemble(newPolicy);
        } catch (ValidationException e) {
            throw new IllegalArgumentException(e);
        }
    });
}
Also used : TPolicy(org.simbasecurity.api.service.thrift.TPolicy) Policy(org.simbasecurity.core.domain.Policy) ValidationException(org.owasp.esapi.errors.ValidationException) PolicyEntity(org.simbasecurity.core.domain.PolicyEntity)

Example 4 with TPolicy

use of org.simbasecurity.api.service.thrift.TPolicy 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 5 with TPolicy

use of org.simbasecurity.api.service.thrift.TPolicy 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)

Aggregations

TPolicy (org.simbasecurity.api.service.thrift.TPolicy)6 Policy (org.simbasecurity.core.domain.Policy)6 ValidationException (org.owasp.esapi.errors.ValidationException)3 TRole (org.simbasecurity.api.service.thrift.TRole)3 TRule (org.simbasecurity.api.service.thrift.TRule)3 PolicyEntity (org.simbasecurity.core.domain.PolicyEntity)3 Role (org.simbasecurity.core.domain.Role)3 Rule (org.simbasecurity.core.domain.Rule)3 List (java.util.List)2 Set (java.util.Set)2 Collectors (java.util.stream.Collectors)2 TException (org.apache.thrift.TException)2 PolicyService (org.simbasecurity.api.service.thrift.PolicyService)2 StringUtil.join (org.simbasecurity.common.util.StringUtil.join)2 ManagementAudit (org.simbasecurity.core.audit.ManagementAudit)2 PolicyRepository (org.simbasecurity.core.domain.repository.PolicyRepository)2 RoleRepository (org.simbasecurity.core.domain.repository.RoleRepository)2 RuleRepository (org.simbasecurity.core.domain.repository.RuleRepository)2 SimbaExceptionHandlingCaller (org.simbasecurity.core.service.errors.SimbaExceptionHandlingCaller)2 EntityFilterService (org.simbasecurity.core.service.filter.EntityFilterService)2