Search in sources :

Example 31 with StorageOSUser

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

the class OrderService method downloadOrders.

/**
 * Get log data from the specified virtual machines that are filtered, merged,
 * and sorted based on the passed request parameters and streams the log
 * messages back to the client as JSON formatted strings.
 *
 * @brief Show logs from all or specified virtual machine
 * @param startTimeStr The start datetime of the desired time window. Value is
 *            inclusive.
 *            Allowed values: "yyyy-MM-dd_HH:mm:ss" formatted date or
 *            datetime in ms.
 *            Default: Set to yesterday same time
 * @param endTimeStr The end datetime of the desired time window. Value is
 *            inclusive.
 *            Allowed values: "yyyy-MM-dd_HH:mm:ss" formatted date or
 *            datetime in ms.
 * @param tenantIDsStr a list of tenant IDs separated by ','
 * @param orderIDsStr a list of order IDs separated by ','
 * @prereq one of tenantIDsStr and orderIDsStr should be empty
 * @return A reference to the StreamingOutput to which the log data is
 *         written.
 * @throws WebApplicationException When an invalid request is made.
 */
@GET
@CheckPermission(roles = { Role.SYSTEM_ADMIN, Role.SYSTEM_MONITOR, Role.SECURITY_ADMIN })
@Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML, MediaType.TEXT_PLAIN })
@Path("/download")
public Response downloadOrders(@DefaultValue("") @QueryParam(SearchConstants.START_TIME_PARAM) String startTimeStr, @DefaultValue("") @QueryParam(SearchConstants.END_TIME_PARAM) String endTimeStr, @DefaultValue("") @QueryParam(SearchConstants.TENANT_IDS_PARAM) String tenantIDsStr, @DefaultValue("") @QueryParam(SearchConstants.ORDER_STATUS_PARAM2) String orderStatusStr, @DefaultValue("") @QueryParam(SearchConstants.ORDER_IDS) String orderIDsStr) throws Exception {
    if (tenantIDsStr.isEmpty() && orderIDsStr.isEmpty()) {
        InvalidParameterException cause = new InvalidParameterException("Both tenant and order IDs are empty");
        throw APIException.badRequests.invalidParameterWithCause(SearchConstants.TENANT_ID_PARAM, tenantIDsStr, cause);
    }
    final long startTimeInMS = getTime(startTimeStr, 0);
    final long endTimeInMS = getTime(endTimeStr, System.currentTimeMillis());
    if (startTimeInMS > endTimeInMS) {
        throw APIException.badRequests.endTimeBeforeStartTime(startTimeStr, endTimeStr);
    }
    OrderStatus orderStatus = getOrderStatus(orderStatusStr, false);
    if (isJobRunning()) {
        throw APIException.badRequests.cannotExecuteOperationWhilePendingTask("Deleting/Downloading orders");
    }
    final List<URI> tids = toIDs(SearchConstants.TENANT_IDS_PARAM, tenantIDsStr);
    StorageOSUser user = getUserFromContext();
    URI tid = URI.create(user.getTenantId());
    URI uid = URI.create(user.getName());
    final OrderJobStatus status = new OrderJobStatus(OrderServiceJob.JobType.DOWNLOAD_ORDER, startTimeInMS, endTimeInMS, tids, tid, uid, orderStatus);
    List<URI> orderIDs = toIDs(SearchConstants.ORDER_IDS, orderIDsStr);
    status.setTotal(orderIDs.size());
    if (!orderIDs.isEmpty()) {
        status.setStartTime(0);
        status.setEndTime(0);
    }
    try {
        saveJobInfo(status);
    } catch (Exception e) {
        log.error("Failed to save job info e=", e);
        throw APIException.internalServerErrors.getLockFailed();
    }
    StreamingOutput out = new StreamingOutput() {

        @Override
        public void write(OutputStream outputStream) {
            exportOrders(tids, orderIDsStr, startTimeInMS, endTimeInMS, outputStream, status);
        }
    };
    return Response.ok(out).build();
}
Also used : InvalidParameterException(java.security.InvalidParameterException) OrderStatus(com.emc.storageos.db.client.model.uimodels.OrderStatus) StorageOSUser(com.emc.storageos.security.authentication.StorageOSUser) OutputStream(java.io.OutputStream) StreamingOutput(javax.ws.rs.core.StreamingOutput) OrderJobStatus(com.emc.sa.api.utils.OrderJobStatus) URI(java.net.URI) InvalidParameterException(java.security.InvalidParameterException) WebApplicationException(javax.ws.rs.WebApplicationException) URISyntaxException(java.net.URISyntaxException) APIException(com.emc.storageos.svcs.errorhandling.resources.APIException) DatabaseException(com.emc.storageos.db.exceptions.DatabaseException) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET) CheckPermission(com.emc.storageos.security.authorization.CheckPermission)

Example 32 with StorageOSUser

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

the class OrderService method getOrders.

/**
 * Gets the list of orders
 * @param tenantId the URN of a tenant
 * @brief List Orders
 * @return a list of orders
 * @throws DatabaseException when a DB error occurs
 */
@GET
@Path("/all")
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
public OrderList getOrders(@DefaultValue("") @QueryParam(SearchConstants.TENANT_ID_PARAM) String tenantId) throws DatabaseException {
    StorageOSUser user = getUserFromContext();
    if (StringUtils.isBlank(tenantId)) {
        tenantId = user.getTenantId();
    }
    verifyAuthorizedInTenantOrg(uri(tenantId), getUserFromContext());
    List<Order> orders = orderManager.getOrders(uri(tenantId));
    return toOrderList(orders);
}
Also used : Order(com.emc.storageos.db.client.model.uimodels.Order) StorageOSUser(com.emc.storageos.security.authentication.StorageOSUser) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Example 33 with StorageOSUser

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

the class OrderService method getOrderLogs.

/**
 * Gets the order logs
 *
 * @param orderId the URN of an order
 * @brief List Order Logs
 * @return a list of order logs
 * @throws DatabaseException when a DB error occurs
 */
@GET
@Path("/{id}/logs")
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
public OrderLogList getOrderLogs(@PathParam("id") String orderId) throws DatabaseException {
    Order order = queryResource(uri(orderId));
    StorageOSUser user = getUserFromContext();
    verifyAuthorizedInTenantOrg(uri(order.getTenant()), user);
    List<ExecutionLog> executionLogs = orderManager.getOrderExecutionLogs(order);
    return toOrderLogList(executionLogs);
}
Also used : Order(com.emc.storageos.db.client.model.uimodels.Order) ExecutionLog(com.emc.storageos.db.client.model.uimodels.ExecutionLog) StorageOSUser(com.emc.storageos.security.authentication.StorageOSUser) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Example 34 with StorageOSUser

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

the class AssetOptionService method createAssetOptionsContext.

private AssetOptionsContext createAssetOptionsContext(AssetOptionsRequest request) {
    StorageOSUser user = getUserFromContext();
    AssetOptionsContext context = assetOptionsManager.createDefaultContext(user);
    // Override the tenant if specified in the request
    URI tenantId = request.getTenantId();
    if (tenantId != null) {
        verifyAuthorizedInTenantOrg(tenantId, user);
        context.setTenant(tenantId);
    }
    return context;
}
Also used : StorageOSUser(com.emc.storageos.security.authentication.StorageOSUser) AssetOptionsContext(com.emc.sa.asset.AssetOptionsContext) URI(java.net.URI)

Example 35 with StorageOSUser

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

the class CatalogImageService method updateCatalogImage.

/**
 * Update catalog image
 *
 * @param param Catalog Image update parameters
 * @param id the URN the catalog image
 * @prereq none
 * @brief Update Catalog Image
 * @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 CatalogImageRestRep updateCatalogImage(@PathParam("id") URI id, CatalogImageUpdateParam param) {
    CatalogImage catalogImage = getCatalogImageById(id, true);
    StorageOSUser user = getUserFromContext();
    verifyAuthorizedInTenantOrg(uri(catalogImage.getTenant()), user);
    validateParam(uri(catalogImage.getTenant()), param, catalogImage);
    updateObject(catalogImage, param);
    catalogImageManager.updateCatalogImage(catalogImage);
    auditOpSuccess(OperationTypeEnum.UPDATE_CATALOG_IMAGE, catalogImage.auditParameters());
    catalogImage = catalogImageManager.getCatalogImageById(catalogImage.getId());
    return map(catalogImage);
}
Also used : StorageOSUser(com.emc.storageos.security.authentication.StorageOSUser) CatalogImage(com.emc.storageos.db.client.model.uimodels.CatalogImage) 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)

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