Search in sources :

Example 6 with ProjectRole

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

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

the class CreateProjectRoleCmd method execute.

// ///////////////////////////////////////////////////
// ///////////// API Implementation///////////////////
// ///////////////////////////////////////////////////
@Override
public void execute() {
    CallContext.current().setEventDetails("Role: " + getProjectRoleName() + ", description: " + getProjectRoleDescription());
    ProjectRole projectRole = projRoleService.createProjectRole(getProjectId(), getProjectRoleName(), getProjectRoleDescription());
    if (projectRole == null) {
        throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to create project role");
    }
    setupProjectRoleResponse(projectRole);
}
Also used : ServerApiException(org.apache.cloudstack.api.ServerApiException) ProjectRole(org.apache.cloudstack.acl.ProjectRole)

Example 8 with ProjectRole

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

the class ListProjectRolesCmd method execute.

// ///////////////////////////////////////////////////
// ///////////// API Implementation///////////////////
// ///////////////////////////////////////////////////
@Override
public void execute() {
    List<ProjectRole> projectRoles;
    if (getProjectId() != null && getProjectRoleId() != null) {
        projectRoles = Collections.singletonList(projRoleService.findProjectRole(getProjectRoleId(), getProjectId()));
    } else if (StringUtils.isNotBlank(getRoleName())) {
        projectRoles = projRoleService.findProjectRolesByName(getProjectId(), getRoleName());
    } else {
        projectRoles = projRoleService.findProjectRoles(getProjectId());
    }
    final ListResponse<ProjectRoleResponse> response = new ListResponse<>();
    final List<ProjectRoleResponse> roleResponses = new ArrayList<>();
    for (ProjectRole role : projectRoles) {
        if (role == null) {
            continue;
        }
        roleResponses.add(setupProjectRoleResponse(role));
    }
    response.setResponses(roleResponses);
    response.setResponseName(getCommandName());
    setResponseObject(response);
}
Also used : ProjectRoleResponse(org.apache.cloudstack.api.response.ProjectRoleResponse) ListResponse(org.apache.cloudstack.api.response.ListResponse) ArrayList(java.util.ArrayList) ProjectRole(org.apache.cloudstack.acl.ProjectRole)

Example 9 with ProjectRole

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

ProjectRole (org.apache.cloudstack.acl.ProjectRole)9 ServerApiException (org.apache.cloudstack.api.ServerApiException)5 ProjectRolePermission (org.apache.cloudstack.acl.ProjectRolePermission)3 ActionEvent (com.cloud.event.ActionEvent)2 InvalidParameterValueException (com.cloud.exception.InvalidParameterValueException)2 Account (com.cloud.user.Account)2 ArrayList (java.util.ArrayList)2 ListResponse (org.apache.cloudstack.api.response.ListResponse)2 SuccessResponse (org.apache.cloudstack.api.response.SuccessResponse)2 DomainVO (com.cloud.domain.DomainVO)1 User (com.cloud.user.User)1 ProjectRolePermissionResponse (org.apache.cloudstack.api.response.ProjectRolePermissionResponse)1 ProjectRoleResponse (org.apache.cloudstack.api.response.ProjectRoleResponse)1