Search in sources :

Example 1 with TRule

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

use of org.simbasecurity.api.service.thrift.TRule 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)2 TRule (org.simbasecurity.api.service.thrift.TRule)2 Policy (org.simbasecurity.core.domain.Policy)2 Rule (org.simbasecurity.core.domain.Rule)2 List (java.util.List)1 Set (java.util.Set)1 Collectors (java.util.stream.Collectors)1 TException (org.apache.thrift.TException)1 ValidationException (org.owasp.esapi.errors.ValidationException)1 PolicyService (org.simbasecurity.api.service.thrift.PolicyService)1 TRole (org.simbasecurity.api.service.thrift.TRole)1 StringUtil.join (org.simbasecurity.common.util.StringUtil.join)1 ManagementAudit (org.simbasecurity.core.audit.ManagementAudit)1 PolicyEntity (org.simbasecurity.core.domain.PolicyEntity)1 Role (org.simbasecurity.core.domain.Role)1 PolicyRepository (org.simbasecurity.core.domain.repository.PolicyRepository)1 RoleRepository (org.simbasecurity.core.domain.repository.RoleRepository)1 RuleRepository (org.simbasecurity.core.domain.repository.RuleRepository)1 SimbaExceptionHandlingCaller (org.simbasecurity.core.service.errors.SimbaExceptionHandlingCaller)1 EntityFilterService (org.simbasecurity.core.service.filter.EntityFilterService)1