Search in sources :

Example 1 with RolePermission

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);
}
Also used : Role(org.apache.cloudstack.acl.Role) SuccessResponse(org.apache.cloudstack.api.response.SuccessResponse) ServerApiException(org.apache.cloudstack.api.ServerApiException) ArrayList(java.util.ArrayList) RolePermission(org.apache.cloudstack.acl.RolePermission)

Example 2 with RolePermission

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);
}
Also used : RolePermissionVO(org.apache.cloudstack.acl.RolePermissionVO) RolePermission(org.apache.cloudstack.acl.RolePermission)

Example 3 with RolePermission

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);
}
Also used : Role(org.apache.cloudstack.acl.Role) ServerApiException(org.apache.cloudstack.api.ServerApiException) RolePermission(org.apache.cloudstack.acl.RolePermission)

Example 4 with RolePermission

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);
}
Also used : SuccessResponse(org.apache.cloudstack.api.response.SuccessResponse) ServerApiException(org.apache.cloudstack.api.ServerApiException) RolePermission(org.apache.cloudstack.acl.RolePermission)

Example 5 with RolePermission

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);
}
Also used : Role(org.apache.cloudstack.acl.Role) ListResponse(org.apache.cloudstack.api.response.ListResponse) RolePermissionResponse(org.apache.cloudstack.api.response.RolePermissionResponse) ArrayList(java.util.ArrayList) RolePermission(org.apache.cloudstack.acl.RolePermission)

Aggregations

RolePermission (org.apache.cloudstack.acl.RolePermission)5 Role (org.apache.cloudstack.acl.Role)3 ServerApiException (org.apache.cloudstack.api.ServerApiException)3 ArrayList (java.util.ArrayList)2 SuccessResponse (org.apache.cloudstack.api.response.SuccessResponse)2 RolePermissionVO (org.apache.cloudstack.acl.RolePermissionVO)1 ListResponse (org.apache.cloudstack.api.response.ListResponse)1 RolePermissionResponse (org.apache.cloudstack.api.response.RolePermissionResponse)1