Search in sources :

Example 71 with StorageOSUser

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

the class CatalogCategoryService method resetRootCatalogCategory.

/**
 * Get the root catalog category for a tenant
 *
 * @prereq none
 * @brief Get Root Catalog Category
 * @return Root Catalog Category
 */
@POST
@Consumes({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@CheckPermission(roles = { Role.TENANT_ADMIN })
@Path("/reset")
public Response resetRootCatalogCategory(@DefaultValue("") @QueryParam(SearchConstants.TENANT_ID_PARAM) String tenantId) {
    StorageOSUser user = getUserFromContext();
    if (StringUtils.isBlank(tenantId)) {
        tenantId = user.getTenantId();
    }
    verifyAuthorizedInTenantOrg(uri(tenantId), user);
    try {
        catalogCategoryManager.restoreDefaultCatalog(uri(tenantId));
    } catch (IOException e) {
        log.error("Failed to reset catalog", e);
        return Response.serverError().build();
    }
    return Response.ok().build();
}
Also used : StorageOSUser(com.emc.storageos.security.authentication.StorageOSUser) IOException(java.io.IOException) 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 72 with StorageOSUser

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

the class CatalogServiceService method updateCatalogService.

/**
 * Update catalog service
 *
 * @param param Catalog Service update parameters
 * @param id the URN the catalog service
 * @prereq none
 * @brief Update Catalog Service
 * @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 CatalogServiceRestRep updateCatalogService(@PathParam("id") URI id, CatalogServiceUpdateParam param) {
    CatalogService catalogService = getCatalogServiceById(id, true);
    List<CatalogServiceField> catalogServiceFields = catalogServiceManager.getCatalogServiceFields(id);
    StorageOSUser user = getUserFromContext();
    CatalogCategory parentCatalogCategory = catalogCategoryManager.getCatalogCategoryById(param.getCatalogCategory());
    verifyAuthorizedInTenantOrg(uri(parentCatalogCategory.getTenant()), user);
    validateParam(param, catalogService);
    updateObject(catalogService, param, parentCatalogCategory);
    List<CatalogServiceField> updatedCatalogServiceFields = updateObjectList(catalogService, catalogServiceFields, param.getCatalogServiceFields());
    catalogServiceManager.updateCatalogService(catalogService, updatedCatalogServiceFields);
    auditOpSuccess(OperationTypeEnum.UPDATE_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) CatalogService(com.emc.storageos.db.client.model.uimodels.CatalogService) CatalogCategory(com.emc.storageos.db.client.model.uimodels.CatalogCategory) 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 73 with StorageOSUser

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

the class OrderService method getOtherSearchResults.

/**
 * parameter: 'orderStatus' The status for the order
 * parameter: 'startTime' Start time to search for orders
 * parameter: 'endTime' End time to search for orders
 *
 * @return Return a list of matching orders or an empty list if no match was found.
 */
@Override
protected SearchResults getOtherSearchResults(Map<String, List<String>> parameters, boolean authorized) {
    StorageOSUser user = getUserFromContext();
    String tenantId = user.getTenantId();
    if (parameters.containsKey(SearchConstants.TENANT_ID_PARAM)) {
        tenantId = parameters.get(SearchConstants.TENANT_ID_PARAM).get(0);
    }
    verifyAuthorizedInTenantOrg(uri(tenantId), user);
    if (!parameters.containsKey(SearchConstants.ORDER_STATUS_PARAM) && !parameters.containsKey(SearchConstants.START_TIME_PARAM) && !parameters.containsKey(SearchConstants.END_TIME_PARAM)) {
        throw APIException.badRequests.invalidParameterSearchMissingParameter(getResourceClass().getName(), SearchConstants.ORDER_STATUS_PARAM + " or " + SearchConstants.START_TIME_PARAM + " or " + SearchConstants.END_TIME_PARAM);
    }
    if (parameters.containsKey(SearchConstants.ORDER_STATUS_PARAM) && (parameters.containsKey(SearchConstants.START_TIME_PARAM) || parameters.containsKey(SearchConstants.END_TIME_PARAM))) {
        throw APIException.badRequests.parameterForSearchCouldNotBeCombinedWithAnyOtherParameter(getResourceClass().getName(), SearchConstants.ORDER_STATUS_PARAM, SearchConstants.START_TIME_PARAM + " or " + SearchConstants.END_TIME_PARAM);
    }
    List<Order> orders = Lists.newArrayList();
    if (parameters.containsKey(SearchConstants.ORDER_STATUS_PARAM)) {
        String orderStatus = parameters.get(SearchConstants.ORDER_STATUS_PARAM).get(0);
        ArgValidator.checkFieldNotEmpty(orderStatus, SearchConstants.ORDER_STATUS_PARAM);
        orders = orderManager.findOrdersByStatus(uri(tenantId), OrderStatus.valueOf(orderStatus));
    } else if (parameters.containsKey(SearchConstants.START_TIME_PARAM) || parameters.containsKey(SearchConstants.END_TIME_PARAM)) {
        Date startTime = null;
        if (parameters.containsKey(SearchConstants.START_TIME_PARAM)) {
            startTime = TimeUtils.getDateTimestamp(parameters.get(SearchConstants.START_TIME_PARAM).get(0));
        }
        Date endTime = null;
        if (parameters.containsKey(SearchConstants.END_TIME_PARAM)) {
            endTime = TimeUtils.getDateTimestamp(parameters.get(SearchConstants.END_TIME_PARAM).get(0));
        }
        if (startTime == null && endTime == null) {
            throw APIException.badRequests.invalidParameterSearchMissingParameter(getResourceClass().getName(), SearchConstants.ORDER_STATUS_PARAM + " or " + SearchConstants.START_TIME_PARAM + " or " + SearchConstants.END_TIME_PARAM);
        }
        if (startTime.after(endTime)) {
            throw APIException.badRequests.endTimeBeforeStartTime(startTime.toString(), endTime.toString());
        }
        int maxCount = -1;
        List<String> c = parameters.get(SearchConstants.ORDER_MAX_COUNT);
        if (c != null) {
            String maxCountParam = parameters.get(SearchConstants.ORDER_MAX_COUNT).get(0);
            maxCount = Integer.parseInt(maxCountParam);
        }
        orders = orderManager.findOrdersByTimeRange(uri(tenantId), startTime, endTime, maxCount);
    }
    ResRepFilter<SearchResultResourceRep> resRepFilter = (ResRepFilter<SearchResultResourceRep>) getPermissionFilter(getUserFromContext(), _permissionsHelper);
    List<SearchResultResourceRep> searchResultResourceReps = Lists.newArrayList();
    for (Order order : orders) {
        RestLinkRep selfLink = new RestLinkRep("self", RestLinkFactory.newLink(getResourceType(), order.getId()));
        SearchResultResourceRep searchResultResourceRep = new SearchResultResourceRep();
        searchResultResourceRep.setId(order.getId());
        searchResultResourceRep.setLink(selfLink);
        if (authorized || resRepFilter.isAccessible(searchResultResourceRep)) {
            searchResultResourceReps.add(searchResultResourceRep);
        }
    }
    SearchResults result = new SearchResults();
    result.setResource(searchResultResourceReps);
    return result;
}
Also used : Order(com.emc.storageos.db.client.model.uimodels.Order) StorageOSUser(com.emc.storageos.security.authentication.StorageOSUser) SearchResultResourceRep(com.emc.storageos.model.search.SearchResultResourceRep) RestLinkRep(com.emc.storageos.model.RestLinkRep) OrderMapper.toExecutionLogList(com.emc.sa.api.mapper.OrderMapper.toExecutionLogList) NamedElementQueryResultList(com.emc.storageos.db.client.constraint.NamedElementQueryResultList) ArrayList(java.util.ArrayList) OrderMapper.toOrderLogList(com.emc.sa.api.mapper.OrderMapper.toOrderLogList) OrderLogList(com.emc.vipr.model.catalog.OrderLogList) OrderList(com.emc.vipr.model.catalog.OrderList) List(java.util.List) ExecutionLogList(com.emc.vipr.model.catalog.ExecutionLogList) URIUtil.asString(com.emc.storageos.db.client.URIUtil.asString) ResRepFilter(com.emc.storageos.api.service.impl.response.ResRepFilter) SearchResults(com.emc.storageos.model.search.SearchResults) Date(java.util.Date)

Example 74 with StorageOSUser

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

the class OrderService method getOrderExecutionState.

/**
 * Gets the order execution
 *
 * @param orderId the URN of an order
 * @brief Get Order Execution
 * @return an order execution
 * @throws DatabaseException when a DB error occurs
 */
@GET
@Path("/{id}/execution")
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
public ExecutionStateRestRep getOrderExecutionState(@PathParam("id") String orderId) throws DatabaseException {
    Order order = queryResource(uri(orderId));
    StorageOSUser user = getUserFromContext();
    verifyAuthorizedInTenantOrg(uri(order.getTenant()), user);
    ExecutionState executionState = orderManager.getOrderExecutionState(order.getExecutionStateId());
    return map(executionState);
}
Also used : Order(com.emc.storageos.db.client.model.uimodels.Order) ExecutionState(com.emc.storageos.db.client.model.uimodels.ExecutionState) StorageOSUser(com.emc.storageos.security.authentication.StorageOSUser) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Example 75 with StorageOSUser

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

the class OrderService method getOrder.

@GET
@Path("/{id}")
@Consumes({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
public OrderRestRep getOrder(@PathParam("id") String id) {
    Order order = queryResource(uri(id));
    StorageOSUser user = getUserFromContext();
    verifyAuthorizedInTenantOrg(uri(order.getTenant()), user);
    List<OrderParameter> orderParameters = orderManager.getOrderParameters(order.getId());
    return map(order, orderParameters);
}
Also used : Order(com.emc.storageos.db.client.model.uimodels.Order) OrderParameter(com.emc.storageos.db.client.model.uimodels.OrderParameter) StorageOSUser(com.emc.storageos.security.authentication.StorageOSUser) Path(javax.ws.rs.Path) Consumes(javax.ws.rs.Consumes) GET(javax.ws.rs.GET)

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