Search in sources :

Example 36 with StorageOSUser

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

the class CatalogImageService method getCatalogImages.

/**
 * Gets the list of catalog images
 *
 * @param tenantId the URN of a tenant
 * @brief List Catalog Images
 * @return a list of catalog images
 * @throws DatabaseException when a DB error occurs
 */
@GET
@Path("")
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
public CatalogImageList getCatalogImages(@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<CatalogImage> catalogImages = catalogImageManager.getCatalogImages(uri(tenantId));
    CatalogImageList list = new CatalogImageList();
    for (CatalogImage catalogImage : catalogImages) {
        NamedRelatedResourceRep resourceRep = toNamedRelatedResource(ResourceTypeEnum.CATALOG_IMAGE, catalogImage.getId(), catalogImage.getLabel());
        list.getCatalogImages().add(resourceRep);
    }
    return list;
}
Also used : CatalogImageList(com.emc.vipr.model.catalog.CatalogImageList) StorageOSUser(com.emc.storageos.security.authentication.StorageOSUser) CatalogImage(com.emc.storageos.db.client.model.uimodels.CatalogImage) NamedRelatedResourceRep(com.emc.storageos.model.NamedRelatedResourceRep) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Example 37 with StorageOSUser

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

the class CatalogImageService method createCatalogImage.

/**
 * Creates a new catalog image
 *
 * @param createParam
 *            the parameter to create a new catalog image
 * @prereq none
 * @brief Create Catalog Image
 * @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 CatalogImageRestRep createCatalogImage(CatalogImageCreateParam createParam) {
    StorageOSUser user = getUserFromContext();
    verifyAuthorizedInTenantOrg(createParam.getTenant(), user);
    validateParam(createParam.getTenant(), createParam, null);
    CatalogImage catalogImage = createNewObject(createParam.getTenant(), createParam);
    catalogImageManager.createCatalogImage(catalogImage);
    auditOpSuccess(OperationTypeEnum.CREATE_CATALOG_IMAGE, catalogImage.auditParameters());
    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) POST(javax.ws.rs.POST) Consumes(javax.ws.rs.Consumes) Produces(javax.ws.rs.Produces) CheckPermission(com.emc.storageos.security.authorization.CheckPermission)

Example 38 with StorageOSUser

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

the class ExecutionWindowService method updateExecutionWindow.

/**
 * Update execution window
 *
 * @param param Execution Window update parameters
 * @param id the URN the execution window
 * @prereq none
 * @brief Update Execution Window
 * @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 ExecutionWindowRestRep updateExecutionWindow(@PathParam("id") URI id, ExecutionWindowUpdateParam param) {
    ExecutionWindow executionWindow = getExecutionWindowById(id, true);
    StorageOSUser user = getUserFromContext();
    verifyAuthorizedInTenantOrg(uri(executionWindow.getTenant()), user);
    validateParam(param, executionWindow, user.getTenantId());
    updateObject(executionWindow, param);
    executionWindowManager.updateExecutionWindow(executionWindow);
    auditOpSuccess(OperationTypeEnum.UPDATE_EXECUTION_WINDOW, executionWindow.auditParameters());
    executionWindow = executionWindowManager.getExecutionWindowById(executionWindow.getId());
    return map(executionWindow);
}
Also used : ExecutionWindow(com.emc.storageos.db.client.model.uimodels.ExecutionWindow) StorageOSUser(com.emc.storageos.security.authentication.StorageOSUser) 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 39 with StorageOSUser

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

the class ScheduledEventService method cancelScheduledEvent.

/**
 * Cancel a scheduled event which should be in APPROVAL or APPROVED status.
 * @param id    Scheduled Event URI
 * @return      OK if cancellation completed successfully
 */
@POST
@Path("/{id}/cancel")
@Consumes({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
public Response cancelScheduledEvent(@PathParam("id") String id) {
    ScheduledEvent scheduledEvent = queryResource(uri(id));
    ArgValidator.checkEntity(scheduledEvent, uri(id), true);
    StorageOSUser user = getUserFromContext();
    verifyAuthorizedInTenantOrg(uri(scheduledEvent.getTenant()), user);
    if (!(scheduledEvent.getEventStatus().equals(ScheduledEventStatus.APPROVAL) || scheduledEvent.getEventStatus().equals(ScheduledEventStatus.APPROVED) || scheduledEvent.getEventStatus().equals(ScheduledEventStatus.REJECTED))) {
        throw APIException.badRequests.unexpectedValueForProperty(ScheduledEvent.EVENT_STATUS, "APPROVAL|APPROVED|REJECTED", scheduledEvent.getEventStatus().name());
    }
    Order order = client.orders().findById(scheduledEvent.getLatestOrderId());
    ArgValidator.checkEntity(order, uri(id), true);
    order.setOrderStatus(OrderStatus.CANCELLED.name());
    client.save(order);
    scheduledEvent.setEventStatus(ScheduledEventStatus.CANCELLED);
    client.save(scheduledEvent);
    try {
        log.info("Cancelled a scheduledEvent {}:{}", scheduledEvent.getId(), ScheduleInfo.deserialize(org.apache.commons.codec.binary.Base64.decodeBase64(scheduledEvent.getScheduleInfo().getBytes(UTF_8))).toString());
    } catch (Exception e) {
        log.error("Failed to parse scheduledEvent.");
    }
    return Response.ok().build();
}
Also used : StorageOSUser(com.emc.storageos.security.authentication.StorageOSUser) APIException(com.emc.storageos.svcs.errorhandling.resources.APIException) BadRequestException(com.emc.storageos.svcs.errorhandling.resources.BadRequestException) DatabaseException(com.emc.storageos.db.exceptions.DatabaseException) ParseException(java.text.ParseException)

Example 40 with StorageOSUser

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

the class ScheduledEventService method createEvent.

/**
 * Create a scheduled event for one or a series of future orders.
 * Also a latest order is created and set to APPROVAL or SCHEDULED status
 * @param createParam   including schedule time info and order parameters
 * @return                ScheduledEventRestRep
 */
@POST
@Path("")
@Consumes({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
public ScheduledEventRestRep createEvent(ScheduledEventCreateParam createParam) {
    StorageOSUser user = getUserFromContext();
    URI tenantId = createParam.getOrderCreateParam().getTenantId();
    if (tenantId != null) {
        verifyAuthorizedInTenantOrg(tenantId, user);
    } else {
        tenantId = uri(user.getTenantId());
    }
    ArgValidator.checkFieldNotNull(createParam.getOrderCreateParam().getCatalogService(), "catalogService");
    CatalogService catalogService = catalogServiceManager.getCatalogServiceById(createParam.getOrderCreateParam().getCatalogService());
    if (catalogService == null) {
        throw APIException.badRequests.orderServiceNotFound(asString(createParam.getOrderCreateParam().getCatalogService()));
    }
    validateParam(createParam.getScheduleInfo());
    validOrderParam(createParam.getScheduleInfo(), createParam.getOrderCreateParam().getParameters());
    validateAutomaticExpirationNumber(createParam.getOrderCreateParam().getAdditionalScheduleInfo());
    ScheduledEvent newObject = null;
    try {
        newObject = createScheduledEvent(user, tenantId, createParam, catalogService);
    } catch (APIException ex) {
        log.error(ex.getMessage(), ex);
        throw ex;
    } catch (Exception e) {
        log.error(e.getMessage(), e);
    }
    return map(newObject);
}
Also used : APIException(com.emc.storageos.svcs.errorhandling.resources.APIException) StorageOSUser(com.emc.storageos.security.authentication.StorageOSUser) NamedURI(com.emc.storageos.db.client.model.NamedURI) URI(java.net.URI) APIException(com.emc.storageos.svcs.errorhandling.resources.APIException) BadRequestException(com.emc.storageos.svcs.errorhandling.resources.BadRequestException) DatabaseException(com.emc.storageos.db.exceptions.DatabaseException) ParseException(java.text.ParseException)

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