Search in sources :

Example 6 with TPolicy

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

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