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);
});
}
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);
});
}
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);
}
});
}
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);
});
}
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);
});
}
Aggregations