Search in sources :

Example 51 with StorageOSUser

use of com.emc.storageos.security.authentication.StorageOSUser in project coprhd-controller by CoprHD.

the class CatalogServiceService method createCatalogService.

/**
 * Creates a new catalog service
 *
 * @param createParam
 *            the parameter to create a new catalog service
 * @prereq none
 * @brief Create Catalog Service
 * @return none
 */
@POST
@Consumes({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@CheckPermission(roles = { Role.TENANT_ADMIN }, acls = { ACL.OWN })
@Path("")
public CatalogServiceRestRep createCatalogService(CatalogServiceCreateParam createParam) {
    StorageOSUser user = getUserFromContext();
    CatalogCategory parentCatalogCategory = catalogCategoryManager.getCatalogCategoryById(createParam.getCatalogCategory());
    verifyAuthorizedInTenantOrg(uri(parentCatalogCategory.getTenant()), user);
    validateParam(createParam, null);
    CatalogService catalogService = createNewObject(createParam, parentCatalogCategory);
    List<CatalogServiceField> catalogServiceFields = createNewObjectList(catalogService, createParam.getCatalogServiceFields());
    catalogServiceManager.createCatalogService(catalogService, catalogServiceFields);
    auditOpSuccess(OperationTypeEnum.CREATE_CATALOG_SERVICE, catalogService.auditParameters());
    // Refresh Objects
    catalogService = catalogServiceManager.getCatalogServiceById(catalogService.getId());
    catalogServiceFields = catalogServiceManager.getCatalogServiceFields(catalogService.getId());
    ServiceDescriptor serviceDescriptor = getServiceDescriptor(catalogService);
    return map(catalogService, serviceDescriptor, catalogServiceFields);
}
Also used : CatalogServiceField(com.emc.storageos.db.client.model.uimodels.CatalogServiceField) WorkflowServiceDescriptor(com.emc.sa.catalog.WorkflowServiceDescriptor) ServiceDescriptor(com.emc.sa.descriptor.ServiceDescriptor) StorageOSUser(com.emc.storageos.security.authentication.StorageOSUser) CatalogCategory(com.emc.storageos.db.client.model.uimodels.CatalogCategory) CatalogService(com.emc.storageos.db.client.model.uimodels.CatalogService) Path(javax.ws.rs.Path) POST(javax.ws.rs.POST) Consumes(javax.ws.rs.Consumes) Produces(javax.ws.rs.Produces) CheckPermission(com.emc.storageos.security.authorization.CheckPermission)

Example 52 with StorageOSUser

use of com.emc.storageos.security.authentication.StorageOSUser in project coprhd-controller by CoprHD.

the class ApprovalService method updateApproval.

/**
 * Update approval
 *
 * @param param Approval update parameters
 * @param id the URN the approval
 * @prereq none
 * @brief Update Approval
 * @return No data returned in response body
 */
@PUT
@Consumes({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@Path("/{id}")
@CheckPermission(roles = { Role.TENANT_APPROVER })
public ApprovalRestRep updateApproval(@PathParam("id") URI id, ApprovalUpdateParam param) {
    ApprovalRequest approval = getApprovalById(id, true);
    StorageOSUser user = getUserFromContext();
    verifyAuthorizedInTenantOrg(uri(approval.getTenant()), user);
    Order order = orderManager.getOrderById(approval.getOrderId());
    if (order.getSubmittedByUserId().equals(user.getUserName()) && param.getApprovalStatus().equals(ApprovalStatus.APPROVED.toString())) {
        throw APIException.badRequests.updateApprovalBySameUser(user.getUserName());
    }
    validateParam(param, approval);
    updateObject(approval, param);
    approvalManager.updateApproval(approval, user);
    if (approval.getOrderId() != null) {
        if (order != null) {
            orderManager.processOrder(order);
        }
    }
    auditOpSuccess(OperationTypeEnum.UPDATE_APPROVAL, approval.auditParameters());
    approval = approvalManager.getApprovalById(approval.getId());
    return map(approval);
}
Also used : Order(com.emc.storageos.db.client.model.uimodels.Order) StorageOSUser(com.emc.storageos.security.authentication.StorageOSUser) ApprovalRequest(com.emc.storageos.db.client.model.uimodels.ApprovalRequest) Path(javax.ws.rs.Path) Consumes(javax.ws.rs.Consumes) Produces(javax.ws.rs.Produces) PUT(javax.ws.rs.PUT) CheckPermission(com.emc.storageos.security.authorization.CheckPermission)

Example 53 with StorageOSUser

use of com.emc.storageos.security.authentication.StorageOSUser in project coprhd-controller by CoprHD.

the class CatalogCategoryService method updateCatalogCategory.

/**
 * Update info for catalog category
 *
 * @param catalogCategoryUpdate Catalog Category update parameters
 * @param id the URN of a Catalog Category
 * @prereq none
 * @brief Update Catalog Category
 * @return No data returned in response body
 */
@PUT
@Consumes({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@Path("/{id}")
@CheckPermission(roles = { Role.TENANT_ADMIN }, acls = { ACL.OWN })
public CatalogCategoryRestRep updateCatalogCategory(@PathParam("id") URI id, CatalogCategoryUpdateParam catalogCategoryUpdate) {
    CatalogCategory catalogCategory = getCatalogCategoryById(id, true);
    StorageOSUser user = getUserFromContext();
    verifyAuthorizedInTenantOrg(uri(catalogCategory.getTenant()), user);
    URI parentCategoryId = getTargetParentCategoryId(catalogCategory, catalogCategoryUpdate);
    validateCatalogCategoryParam(parentCategoryId, catalogCategoryUpdate, catalogCategory);
    CatalogCategory parentCatalogCategory = parentCategoryId != null ? queryResource(parentCategoryId) : null;
    updateCatalogCategoryObject(parentCatalogCategory, catalogCategory, catalogCategoryUpdate);
    catalogCategoryManager.updateCatalogCategory(catalogCategory);
    auditOpSuccess(OperationTypeEnum.UPDATE_CATALOG_CATEGORY, catalogCategory.auditParameters());
    catalogCategory = catalogCategoryManager.getCatalogCategoryById(catalogCategory.getId());
    return map(catalogCategory);
}
Also used : StorageOSUser(com.emc.storageos.security.authentication.StorageOSUser) CatalogCategoryMapper.createNewCatalogCategory(com.emc.sa.api.mapper.CatalogCategoryMapper.createNewCatalogCategory) CatalogCategory(com.emc.storageos.db.client.model.uimodels.CatalogCategory) NamedURI(com.emc.storageos.db.client.model.NamedURI) URI(java.net.URI) Path(javax.ws.rs.Path) Consumes(javax.ws.rs.Consumes) Produces(javax.ws.rs.Produces) PUT(javax.ws.rs.PUT) CheckPermission(com.emc.storageos.security.authorization.CheckPermission)

Example 54 with StorageOSUser

use of com.emc.storageos.security.authentication.StorageOSUser in project coprhd-controller by CoprHD.

the class ConfigService method getProperties.

/**
 * Get system configuration properties
 *
 * @brief Get system properties
 * @prereq none
 * @param category - type of properties to return: all, config, ovf, mutated, secrets (require SecurityAdmin role)
 *            or obsolete
 * @return Properties Information if success. Error response, if error./**
 */
@GET
@Path("properties/")
@CheckPermission(roles = { Role.SECURITY_ADMIN, Role.SYSTEM_MONITOR })
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
public PropertyInfoRestRep getProperties(@DefaultValue("all") @QueryParam("category") String category) throws Exception {
    switch(PropCategory.valueOf(category.toUpperCase())) {
        case ALL:
            return getTargetPropsCommon();
        case CONFIG:
            return new PropertyInfoRestRep(getConfigProperties());
        case OVF:
            return new PropertyInfoRestRep(getPropertiesOvf());
        case REDEPLOY:
            Map<String, String> props = getPropertiesOvf();
            props.remove(MODE);
            props.remove(NODE_ID);
            Map<String, String> clusterInfo = new HashMap();
            Set<Map.Entry<String, String>> ovfProps = props.entrySet();
            for (Map.Entry<String, String> ovfProp : ovfProps) {
                String parameter = propertyToParameters.get(ovfProp.getKey());
                if (parameter == null) {
                    continue;
                }
                clusterInfo.put(parameter, ovfProp.getValue());
            }
            // Add ipsec key
            clusterInfo.put(IPSEC_KEY, ipsecConfig.getPreSharedKey());
            // Add version info
            RepositoryInfo info = _coordinator.getTargetInfo(RepositoryInfo.class);
            clusterInfo.put(VERSION, info.getCurrentVersion().toString());
            _log.info("clusterInfo={}", clusterInfo);
            return new PropertyInfoRestRep(clusterInfo);
        case MUTATED:
            return new PropertyInfoRestRep(getMutatedProps());
        case SECRETS:
            StorageOSUser user = getUserFromContext();
            if (!user.getRoles().contains(Role.SECURITY_ADMIN.toString())) {
                throw APIException.forbidden.onlySecurityAdminsCanGetSecrets();
            }
            return getTargetPropsCommon(false);
        case OBSOLETE:
            return new PropertyInfoRestRep(getObsoleteProperties());
        default:
            throw APIException.badRequests.invalidParameter("category", category);
    }
}
Also used : PropertyInfoRestRep(com.emc.storageos.model.property.PropertyInfoRestRep) HashMap(java.util.HashMap) RepositoryInfo(com.emc.storageos.coordinator.client.model.RepositoryInfo) StorageOSUser(com.emc.storageos.security.authentication.StorageOSUser) HashMap(java.util.HashMap) Map(java.util.Map) TreeMap(java.util.TreeMap) CheckPermission(com.emc.storageos.security.authorization.CheckPermission)

Example 55 with StorageOSUser

use of com.emc.storageos.security.authentication.StorageOSUser in project coprhd-controller by CoprHD.

the class AbstractPermissionFilter method filter.

/**
 * ContainerRequestFilter - checks to see if one of the specified
 * permissions exists for the user, if not throws
 * APIException.forbidden.insufficientPermissionsForUser
 *
 * @param request
 * @return ContainerRequest
 */
@Override
public ContainerRequest filter(ContainerRequest request) {
    Principal p = request.getUserPrincipal();
    if (!(p instanceof StorageOSUser)) {
        throw APIException.forbidden.invalidSecurityContext();
    }
    StorageOSUser user = (StorageOSUser) p;
    if (_blockProxies && user.isProxied()) {
        throw APIException.forbidden.insufficientPermissionsForUser(user.getName());
    }
    boolean good = false;
    // Step 1: Roles check - see if the user has one of the allowed roles
    Set<String> tenantRoles = null;
    for (Role role : _roles) {
        if (user.getRoles().contains(role.toString())) {
            good = true;
            break;
        }
        if (_permissionsHelper.isRoleTenantLevel(role.toString())) {
            if (tenantRoles == null) {
                try {
                    URI tenantId = getTenantIdFromURI(getUriInfo());
                    tenantRoles = _permissionsHelper.getTenantRolesForUser(user, tenantId, isIdEmbeddedInURL(tenantId));
                    if (CollectionUtils.isEmpty(tenantRoles)) {
                        tenantRoles = getTenantRolesFromResource(user);
                    }
                } catch (DatabaseException ex) {
                    throw APIException.forbidden.failedReadingTenantRoles(ex);
                }
            }
            if (tenantRoles != null && tenantRoles.contains(role.toString())) {
                good = true;
                break;
            }
        }
    }
    // Step 2: if we are still not good, start checking for acls
    if (!good && _acls.length > 0) {
        // grab all acls from the resource
        Set<String> acls = new HashSet<String>();
        URI projectId = getProjectIdFromURI(getUriInfo());
        if (projectId != null) {
            try {
                acls = _permissionsHelper.getProjectACLsForUser(user, projectId, isIdEmbeddedInURL(projectId));
            } catch (DatabaseException ex) {
                throw APIException.forbidden.failedReadingProjectACLs(ex);
            }
        } else {
            /* other resource acls */
            // these acls are assigned to tenant, so enhanced to check not only user's home tenant,
            // but also need to take into consideration of subtenants, which user has tenant roles.
            acls = getUsageAclsFromURI(user.getTenantId(), getUriInfo());
            for (String subtenantId : _permissionsHelper.getSubtenantsForUser(user)) {
                Set<String> subTenantAcls = getUsageAclsFromURI(subtenantId, getUriInfo());
                if (acls == null) {
                    acls = subTenantAcls;
                } else if (subTenantAcls != null) {
                    acls.addAll(subTenantAcls);
                }
            }
        }
        // see if we got any and we got a hit
        if (acls != null) {
            for (ACL acl : _acls) {
                if (acl.equals(ACL.ANY) && (acls.contains(ACL.OWN.toString()) || acls.contains(ACL.BACKUP.toString()) || acls.contains(ACL.ALL.toString()))) {
                    good = true;
                    break;
                } else if (acls.contains(acl.toString())) {
                    good = true;
                    break;
                }
            }
        }
    }
    // still not good, its not allowed
    if (!good) {
        throw APIException.forbidden.insufficientPermissionsForUser(user.getName());
    }
    return request;
}
Also used : StorageOSUser(com.emc.storageos.security.authentication.StorageOSUser) URI(java.net.URI) DatabaseException(com.emc.storageos.db.exceptions.DatabaseException) Principal(java.security.Principal) HashSet(java.util.HashSet)

Aggregations

StorageOSUser (com.emc.storageos.security.authentication.StorageOSUser)105 Produces (javax.ws.rs.Produces)59 Path (javax.ws.rs.Path)53 URI (java.net.URI)50 GET (javax.ws.rs.GET)36 CheckPermission (com.emc.storageos.security.authorization.CheckPermission)31 Consumes (javax.ws.rs.Consumes)24 POST (javax.ws.rs.POST)15 ArrayList (java.util.ArrayList)13 Order (com.emc.storageos.db.client.model.uimodels.Order)12 APIException (com.emc.storageos.svcs.errorhandling.resources.APIException)12 TenantOrg (com.emc.storageos.db.client.model.TenantOrg)11 NamedURI (com.emc.storageos.db.client.model.NamedURI)10 TaskResourceRep (com.emc.storageos.model.TaskResourceRep)10 PUT (javax.ws.rs.PUT)10 Operation (com.emc.storageos.db.client.model.Operation)9 VirtualPool (com.emc.storageos.db.client.model.VirtualPool)9 HashSet (java.util.HashSet)9 StringSet (com.emc.storageos.db.client.model.StringSet)8 DatabaseException (com.emc.storageos.db.exceptions.DatabaseException)8