use of org.apache.cloudstack.acl.RolePermission in project cloudstack by apache.
the class UpdateRolePermissionCmd method execute.
@Override
public void execute() {
final Role role = roleService.findRole(getRoleId());
if (role == null) {
throw new ServerApiException(ApiErrorCode.PARAM_ERROR, "Invalid role id provided");
}
CallContext.current().setEventDetails("Reordering permissions for role id: " + role.getId());
final List<RolePermission> rolePermissionsOrder = new ArrayList<>();
for (Long rolePermissionId : getRulePermissionOrder()) {
final RolePermission rolePermission = roleService.findRolePermission(rolePermissionId);
if (rolePermission == null) {
throw new ServerApiException(ApiErrorCode.PARAM_ERROR, "Provided role permission(s) do not exist");
}
rolePermissionsOrder.add(rolePermission);
}
boolean result = roleService.updateRolePermission(role, rolePermissionsOrder);
SuccessResponse response = new SuccessResponse(getCommandName());
response.setSuccess(result);
setResponseObject(response);
}
use of org.apache.cloudstack.acl.RolePermission in project cloudstack by apache.
the class RolePermissionsDaoImpl method persist.
@Override
public RolePermissionVO persist(final RolePermissionVO item) {
item.setSortOrder(0);
final List<RolePermissionVO> permissionsList = findAllByRoleIdSorted(item.getRoleId());
if (permissionsList != null && permissionsList.size() > 0) {
RolePermission lastRule = permissionsList.get(permissionsList.size() - 1);
item.setSortOrder(lastRule.getSortOrder() + 1);
}
return super.persist(item);
}
use of org.apache.cloudstack.acl.RolePermission in project cloudstack by apache.
the class CreateRolePermissionCmd method execute.
@Override
public void execute() {
final Role role = roleService.findRole(getRoleId());
if (role == null) {
throw new ServerApiException(ApiErrorCode.PARAM_ERROR, "Invalid role id provided");
}
CallContext.current().setEventDetails("Role id: " + role.getId() + ", rule:" + getRule() + ", permission: " + getPermission() + ", description: " + getDescription());
final RolePermission rolePermission = roleService.createRolePermission(role, getRule(), getPermission(), getDescription());
if (rolePermission == null) {
throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to create role permission");
}
setupResponse(rolePermission, role);
}
use of org.apache.cloudstack.acl.RolePermission in project cloudstack by apache.
the class DeleteRolePermissionCmd method execute.
@Override
public void execute() {
RolePermission rolePermission = roleService.findRolePermission(getRolePermissionId());
if (rolePermission == null) {
throw new ServerApiException(ApiErrorCode.PARAM_ERROR, "Invalid role permission id provided");
}
CallContext.current().setEventDetails("Role permission id: " + rolePermission.getId());
boolean result = roleService.deleteRolePermission(rolePermission);
SuccessResponse response = new SuccessResponse(getCommandName());
response.setSuccess(result);
setResponseObject(response);
}
use of org.apache.cloudstack.acl.RolePermission in project cloudstack by apache.
the class ListRolePermissionsCmd method setupResponse.
private void setupResponse(final List<RolePermission> rolePermissions, final Long roleId) {
final Role roleProvided = roleService.findRole(roleId);
final ListResponse<RolePermissionResponse> response = new ListResponse<>();
final List<RolePermissionResponse> rolePermissionResponses = new ArrayList<>();
for (final RolePermission rolePermission : rolePermissions) {
final RolePermissionResponse rolePermissionResponse = new RolePermissionResponse();
Role role = roleProvided;
if (role == null) {
role = roleService.findRole(rolePermission.getRoleId());
}
rolePermissionResponse.setRoleId(role.getUuid());
rolePermissionResponse.setRoleName(role.getName());
rolePermissionResponse.setId(rolePermission.getUuid());
rolePermissionResponse.setRule(rolePermission.getRule());
rolePermissionResponse.setRulePermission(rolePermission.getPermission());
rolePermissionResponse.setDescription(rolePermission.getDescription());
rolePermissionResponse.setObjectName("rolepermission");
rolePermissionResponses.add(rolePermissionResponse);
}
response.setResponses(rolePermissionResponses);
response.setResponseName(getCommandName());
setResponseObject(response);
}
Aggregations