use of org.killbill.billing.security.SecurityApiException in project killbill by killbill.
the class DefaultUserDao method updateRoleDefinition.
@Override
public void updateRoleDefinition(final String role, final List<String> permissions, final String createdBy) throws SecurityApiException {
final DateTime createdDate = clock.getUTCNow();
inTransactionWithExceptionHandling(new TransactionCallback<Void>() {
@Override
public Void inTransaction(final Handle handle, final TransactionStatus status) throws Exception {
final RolesPermissionsSqlDao rolesPermissionsSqlDao = handle.attach(RolesPermissionsSqlDao.class);
final List<RolesPermissionsModelDao> existingPermissions = rolesPermissionsSqlDao.getByRoleName(role);
// A empty list of permissions means we should remove all current permissions
final Iterable<RolesPermissionsModelDao> toBeDeleted = existingPermissions.isEmpty() ? existingPermissions : Iterables.filter(existingPermissions, new Predicate<RolesPermissionsModelDao>() {
@Override
public boolean apply(final RolesPermissionsModelDao input) {
return !permissions.contains(input.getPermission());
}
});
final Iterable<String> toBeAdded = Iterables.filter(permissions, new Predicate<String>() {
@Override
public boolean apply(final String input) {
for (RolesPermissionsModelDao e : existingPermissions) {
if (e.getPermission().equals(input)) {
return false;
}
}
return true;
}
});
for (RolesPermissionsModelDao d : toBeDeleted) {
rolesPermissionsSqlDao.unactiveEvent(d.getRecordId(), createdDate, createdBy);
}
for (final String permission : toBeAdded) {
rolesPermissionsSqlDao.create(new RolesPermissionsModelDao(role, permission, createdDate, createdBy));
}
return null;
}
});
}
Aggregations