Search in sources :

Example 41 with StorageOSUser

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

the class ScheduledEventService method getScheduledEvent.

/**
 * Get a scheduled event via its URI
 * @param id    target schedule event URI
 * @return      ScheduledEventRestRep
 */
@GET
@Path("/{id}")
@Consumes({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
public ScheduledEventRestRep getScheduledEvent(@PathParam("id") String id) {
    ScheduledEvent scheduledEvent = queryResource(uri(id));
    StorageOSUser user = getUserFromContext();
    verifyAuthorizedInTenantOrg(uri(scheduledEvent.getTenant()), user);
    try {
        log.info("Fetched 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 map(scheduledEvent);
}
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 42 with StorageOSUser

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

the class UserPreferenceService method get.

@GET
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@Path("")
public UserPreferencesRestRep get(@DefaultValue("") @QueryParam(SearchConstants.USER_NAME_PARAM) String username) {
    StorageOSUser user = getUserFromContext();
    if (StringUtils.isBlank(username)) {
        username = user.getUserName();
    }
    verifyAuthorized(username, user);
    UserPreferences userPreferences = userPreferenceManager.getPreferences(username);
    return map(userPreferences);
}
Also used : UserPreferences(com.emc.storageos.db.client.model.UserPreferences) StorageOSUser(com.emc.storageos.security.authentication.StorageOSUser) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Example 43 with StorageOSUser

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

the class OrderService method deleteOrders.

/**
 * @brief delete orders (that can be deleted) under given tenants within a time range
 * @param startTimeStr the start time of the range (exclusive)
 * @param endTimeStr the end time of the range (inclusive)
 * @param tenantIDsStr A list of tenant IDs separated by ','
 * @param statusStr Order status
 * @return OK if a background job is submitted successfully
 */
@DELETE
@Path("")
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@CheckPermission(roles = { Role.TENANT_ADMIN })
public Response deleteOrders(@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 statusStr) {
    long startTimeInMS = getTime(startTimeStr, 0);
    long endTimeInMS = getTime(endTimeStr, System.currentTimeMillis());
    if (startTimeInMS > endTimeInMS) {
        throw APIException.badRequests.endTimeBeforeStartTime(startTimeStr, endTimeStr);
    }
    if (tenantIDsStr.isEmpty()) {
        throw APIException.badRequests.invalidParameterWithCause(SearchConstants.TENANT_IDS_PARAM, tenantIDsStr, new InvalidParameterException("tenant IDs should not be empty"));
    }
    OrderStatus orderStatus = getOrderStatus(statusStr, true);
    if (isJobRunning()) {
        throw APIException.badRequests.cannotExecuteOperationWhilePendingTask("Deleting/Downloading orders");
    }
    List<URI> tids = toIDs(SearchConstants.TENANT_IDS_PARAM, tenantIDsStr);
    StorageOSUser user = getUserFromContext();
    URI tid = URI.create(user.getTenantId());
    URI uid = URI.create(user.getName());
    OrderJobStatus status = new OrderJobStatus(OrderServiceJob.JobType.DELETE_ORDER, startTimeInMS, endTimeInMS, tids, tid, uid, orderStatus);
    try {
        saveJobInfo(status);
    } catch (Exception e) {
        log.error("Failed to save job info e=", e);
        throw APIException.internalServerErrors.getLockFailed();
    }
    OrderServiceJob job = new OrderServiceJob(OrderServiceJob.JobType.DELETE_ORDER);
    try {
        queue.put(job);
    } catch (Exception e) {
        String errMsg = String.format("Failed to put the job into the queue %s", ORDER_SERVICE_QUEUE_NAME);
        log.error("{} e=", errMsg, e);
        APIException.internalServerErrors.genericApisvcError(errMsg, e);
    }
    String auditLogMsg = genDeletingOrdersMessage(startTimeStr, endTimeStr);
    auditOpSuccess(OperationTypeEnum.DELETE_ORDER, auditLogMsg);
    return Response.status(Response.Status.ACCEPTED).build();
}
Also used : InvalidParameterException(java.security.InvalidParameterException) OrderStatus(com.emc.storageos.db.client.model.uimodels.OrderStatus) StorageOSUser(com.emc.storageos.security.authentication.StorageOSUser) URIUtil.asString(com.emc.storageos.db.client.URIUtil.asString) 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) OrderServiceJob(com.emc.sa.api.utils.OrderServiceJob) Path(javax.ws.rs.Path) DELETE(javax.ws.rs.DELETE) Produces(javax.ws.rs.Produces) CheckPermission(com.emc.storageos.security.authorization.CheckPermission)

Example 44 with StorageOSUser

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

the class OrderService method getOrderCount.

/**
 * @brief Get number of orders under given tenants within a time range
 * @param startTimeStr start time
 * @param endTimeStr   end time
 * @return  number of orders within the time range of each tenant
 * @throws DatabaseException when a DB error occurs
 */
@GET
@Path("/count")
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@CheckPermission(roles = { Role.TENANT_ADMIN })
public OrderCount getOrderCount(@DefaultValue("") @QueryParam(SearchConstants.START_TIME_PARAM) String startTimeStr, @DefaultValue("") @QueryParam(SearchConstants.END_TIME_PARAM) String endTimeStr, @DefaultValue("") @QueryParam(SearchConstants.TENANT_IDS_PARAM) String tenantIDs) throws DatabaseException {
    StorageOSUser user = getUserFromContext();
    log.info("user={}", user.getName());
    long startTimeInMS = getTime(startTimeStr, 0);
    long endTimeInMS = getTime(endTimeStr, System.currentTimeMillis());
    if (startTimeInMS > endTimeInMS) {
        throw APIException.badRequests.endTimeBeforeStartTime(startTimeStr, endTimeStr);
    }
    List<URI> tids = toIDs(SearchConstants.TENANT_IDS_PARAM, tenantIDs);
    Map<String, Long> countMap = orderManager.getOrderCount(tids, startTimeInMS, endTimeInMS);
    OrderCount resp = new OrderCount(countMap);
    return resp;
}
Also used : StorageOSUser(com.emc.storageos.security.authentication.StorageOSUser) OrderCount(com.emc.vipr.model.catalog.OrderCount) URIUtil.asString(com.emc.storageos.db.client.URIUtil.asString) URI(java.net.URI) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET) CheckPermission(com.emc.storageos.security.authorization.CheckPermission)

Example 45 with StorageOSUser

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

the class OrderService method createOrder.

@POST
@Path("")
@Consumes({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
public OrderRestRep createOrder(OrderCreateParam createParam) {
    StorageOSUser user = getUserFromContext();
    URI tenantId = createParam.getTenantId();
    if (tenantId != null) {
        verifyAuthorizedInTenantOrg(tenantId, user);
    } else {
        tenantId = uri(user.getTenantId());
    }
    Order order = createNewOrder(user, tenantId, createParam);
    orderManager.processOrder(order);
    order = orderManager.getOrderById(order.getId());
    List<OrderParameter> orderParameters = orderManager.getOrderParameters(order.getId());
    auditOpSuccess(OperationTypeEnum.CREATE_ORDER, order.auditParameters());
    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) URI(java.net.URI) Path(javax.ws.rs.Path) POST(javax.ws.rs.POST) Consumes(javax.ws.rs.Consumes) Produces(javax.ws.rs.Produces)

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