Search in sources :

Example 1 with Role

use of org.apache.cloudstack.acl.Role 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 Role

use of org.apache.cloudstack.acl.Role in project cloudstack by apache.

the class ListRolesCmd method setupResponse.

private void setupResponse(final List<Role> roles) {
    final ListResponse<RoleResponse> response = new ListResponse<>();
    final List<RoleResponse> roleResponses = new ArrayList<>();
    for (final Role role : roles) {
        if (role == null) {
            continue;
        }
        final RoleResponse roleResponse = new RoleResponse();
        roleResponse.setId(role.getUuid());
        roleResponse.setRoleName(role.getName());
        roleResponse.setRoleType(role.getRoleType());
        roleResponse.setDescription(role.getDescription());
        roleResponse.setObjectName("role");
        roleResponses.add(roleResponse);
    }
    response.setResponses(roleResponses);
    response.setResponseName(getCommandName());
    setResponseObject(response);
}
Also used : Role(org.apache.cloudstack.acl.Role) ListResponse(org.apache.cloudstack.api.response.ListResponse) ArrayList(java.util.ArrayList) RoleResponse(org.apache.cloudstack.api.response.RoleResponse)

Example 3 with Role

use of org.apache.cloudstack.acl.Role in project cloudstack by apache.

the class CreateRoleCmd method execute.

@Override
public void execute() {
    CallContext.current().setEventDetails("Role: " + getRoleName() + ", type:" + getRoleType() + ", description: " + getRoleDescription());
    final Role role = roleService.createRole(getRoleName(), getRoleType(), getRoleDescription());
    if (role == null) {
        throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to create role");
    }
    setupResponse(role);
}
Also used : Role(org.apache.cloudstack.acl.Role) ServerApiException(org.apache.cloudstack.api.ServerApiException)

Example 4 with Role

use of org.apache.cloudstack.acl.Role 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 5 with Role

use of org.apache.cloudstack.acl.Role in project cloudstack by apache.

the class DeleteRoleCmd method execute.

@Override
public void execute() {
    Role role = roleService.findRole(getRoleId());
    if (role == null) {
        throw new ServerApiException(ApiErrorCode.PARAM_ERROR, "Cannot find the role with provided id");
    }
    CallContext.current().setEventDetails("Role id: " + role.getId());
    boolean result = roleService.deleteRole(role);
    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)

Aggregations

Role (org.apache.cloudstack.acl.Role)9 ServerApiException (org.apache.cloudstack.api.ServerApiException)5 ArrayList (java.util.ArrayList)3 RolePermission (org.apache.cloudstack.acl.RolePermission)3 SuccessResponse (org.apache.cloudstack.api.response.SuccessResponse)3 ListResponse (org.apache.cloudstack.api.response.ListResponse)2 AccountResponse (org.apache.cloudstack.api.response.AccountResponse)1 ProjectAccountResponse (org.apache.cloudstack.api.response.ProjectAccountResponse)1 RolePermissionResponse (org.apache.cloudstack.api.response.RolePermissionResponse)1 RoleResponse (org.apache.cloudstack.api.response.RoleResponse)1 UserResponse (org.apache.cloudstack.api.response.UserResponse)1