Search in sources :

Example 1 with ProjectRolePermission

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

the class CreateProjectRolePermissionCmd method execute.

// ///////////////////////////////////////////////////
// ///////////// API Implementation///////////////////
// ///////////////////////////////////////////////////
@Override
public void execute() {
    ProjectRole projectRole = projRoleService.findProjectRole(getProjectRoleId(), getProjectId());
    if (projectRole == null) {
        throw new ServerApiException(ApiErrorCode.PARAM_ERROR, "Invalid project role ID provided");
    }
    CallContext.current().setEventDetails("Project Role ID: " + projectRole.getId() + ", Rule:" + getRule() + ", Permission: " + getPermission() + ", Description: " + getDescription());
    final ProjectRolePermission projectRolePermission = projRoleService.createProjectRolePermission(this);
    if (projectRolePermission == null) {
        throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to create project role permission");
    }
    setupResponse(projectRolePermission, projectRole);
}
Also used : ProjectRolePermission(org.apache.cloudstack.acl.ProjectRolePermission) ServerApiException(org.apache.cloudstack.api.ServerApiException) ProjectRole(org.apache.cloudstack.acl.ProjectRole)

Example 2 with ProjectRolePermission

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

the class DeleteProjectRolePermissionCmd method execute.

// ///////////////////////////////////////////////////
// ///////////// API Implementation///////////////////
// ///////////////////////////////////////////////////
@Override
public void execute() {
    ProjectRolePermission rolePermission = projRoleService.findProjectRolePermission(getProjectRolePermissionId());
    if (rolePermission == null || rolePermission.getProjectId() != getProjectId()) {
        throw new ServerApiException(ApiErrorCode.PARAM_ERROR, "Invalid role permission id provided for the project");
    }
    CallContext.current().setEventDetails("Deleting Project Role permission with id: " + rolePermission.getId());
    boolean result = projRoleService.deleteProjectRolePermission(rolePermission);
    SuccessResponse response = new SuccessResponse();
    response.setSuccess(result);
    setResponseObject(response);
}
Also used : ProjectRolePermission(org.apache.cloudstack.acl.ProjectRolePermission) SuccessResponse(org.apache.cloudstack.api.response.SuccessResponse) ServerApiException(org.apache.cloudstack.api.ServerApiException)

Example 3 with ProjectRolePermission

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

the class UpdateProjectRolePermissionCmd method updateProjectRolePermissionOrder.

private boolean updateProjectRolePermissionOrder(ProjectRole projectRole) {
    final List<ProjectRolePermission> rolePermissionsOrder = new ArrayList<>();
    for (Long rolePermissionId : getProjectRulePermissionOrder()) {
        final ProjectRolePermission rolePermission = projRoleService.findProjectRolePermission(rolePermissionId);
        if (rolePermission == null) {
            throw new ServerApiException(ApiErrorCode.PARAM_ERROR, "Provided project role permission(s) do not exist");
        }
        rolePermissionsOrder.add(rolePermission);
    }
    return projRoleService.updateProjectRolePermission(projectId, projectRole, rolePermissionsOrder);
}
Also used : ProjectRolePermission(org.apache.cloudstack.acl.ProjectRolePermission) ServerApiException(org.apache.cloudstack.api.ServerApiException) ArrayList(java.util.ArrayList)

Example 4 with ProjectRolePermission

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

the class ListProjectRolePermissionsCmd method execute.

// ///////////////////////////////////////////////////
// ///////////// API Implementation///////////////////
// ///////////////////////////////////////////////////
@Override
public void execute() {
    List<ProjectRolePermission> projectRolePermissions = projRoleService.findAllProjectRolePermissions(getProjectId(), getProjectRoleId());
    final ProjectRole projectRole = projRoleService.findProjectRole(getProjectRoleId(), getProjectId());
    final ListResponse<ProjectRolePermissionResponse> response = new ListResponse<>();
    final List<ProjectRolePermissionResponse> rolePermissionResponses = new ArrayList<>();
    for (final ProjectRolePermission rolePermission : projectRolePermissions) {
        ProjectRole role = projectRole;
        if (role == null) {
            role = projRoleService.findProjectRole(rolePermission.getProjectRoleId(), rolePermission.getProjectId());
        }
        rolePermissionResponses.add(setupResponse(role, rolePermission));
    }
    response.setResponses(rolePermissionResponses);
    response.setResponseName(getCommandName());
    setResponseObject(response);
}
Also used : ProjectRolePermission(org.apache.cloudstack.acl.ProjectRolePermission) ListResponse(org.apache.cloudstack.api.response.ListResponse) ArrayList(java.util.ArrayList) ProjectRolePermissionResponse(org.apache.cloudstack.api.response.ProjectRolePermissionResponse) ProjectRole(org.apache.cloudstack.acl.ProjectRole)

Example 5 with ProjectRolePermission

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

the class UpdateProjectRolePermissionCmd method execute.

// ///////////////////////////////////////////////////
// ///////////////// API Implementation //////////////
// ///////////////////////////////////////////////////
@Override
public void execute() {
    ProjectRole projectRole = projRoleService.findProjectRole(getProjectRoleId(), getProjectId());
    boolean result = false;
    if (projectRole == null) {
        throw new ServerApiException(ApiErrorCode.PARAM_ERROR, "Invalid role id provided");
    }
    if (getProjectRulePermissionOrder() != null) {
        if (getProjectRuleId() != null || getProjectRolePermission() != null) {
            throw new ServerApiException(ApiErrorCode.PARAM_ERROR, "Parameters permission and ruleid must be mutually exclusive with ruleorder");
        }
        CallContext.current().setEventDetails("Reordering permissions for role id: " + projectRole.getId());
        result = updateProjectRolePermissionOrder(projectRole);
    } else if (getProjectRuleId() != null || getProjectRolePermission() != null) {
        if (getProjectRulePermissionOrder() != null) {
            throw new ServerApiException(ApiErrorCode.PARAM_ERROR, "Parameters permission and ruleid must be mutually exclusive with ruleorder");
        }
        ProjectRolePermission rolePermission = getValidProjectRolePermission();
        CallContext.current().setEventDetails("Updating project role permission for rule id: " + getProjectRuleId() + " to: " + getProjectRolePermission().toString());
        result = projRoleService.updateProjectRolePermission(projectId, projectRole, rolePermission, getProjectRolePermission());
    }
    SuccessResponse response = new SuccessResponse(getCommandName());
    response.setSuccess(result);
    setResponseObject(response);
}
Also used : ProjectRolePermission(org.apache.cloudstack.acl.ProjectRolePermission) SuccessResponse(org.apache.cloudstack.api.response.SuccessResponse) ServerApiException(org.apache.cloudstack.api.ServerApiException) ProjectRole(org.apache.cloudstack.acl.ProjectRole)

Aggregations

ProjectRolePermission (org.apache.cloudstack.acl.ProjectRolePermission)6 ServerApiException (org.apache.cloudstack.api.ServerApiException)4 ProjectRole (org.apache.cloudstack.acl.ProjectRole)3 ArrayList (java.util.ArrayList)2 SuccessResponse (org.apache.cloudstack.api.response.SuccessResponse)2 ProjectRolePermissionVO (org.apache.cloudstack.acl.ProjectRolePermissionVO)1 ListResponse (org.apache.cloudstack.api.response.ListResponse)1 ProjectRolePermissionResponse (org.apache.cloudstack.api.response.ProjectRolePermissionResponse)1