Search in sources :

Example 61 with StorageOSUser

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

the class OrderService method getUserOrderCount.

/**
 * Gets the number of orders within a time range for current user
 *
 * @brief Get number of orders created by current user
 * @param startTimeStr
 * @param endTimeStr
 * @return  number of orders
 * @throws DatabaseException when a DB error occurs
 */
@GET
@Path("/my-order-count")
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
public OrderCount getUserOrderCount(@DefaultValue("") @QueryParam(SearchConstants.START_TIME_PARAM) String startTimeStr, @DefaultValue("") @QueryParam(SearchConstants.END_TIME_PARAM) String endTimeStr) 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);
    }
    log.info("start={} end={}", startTimeInMS, endTimeInMS);
    long count = orderManager.getOrderCount(user, startTimeInMS, endTimeInMS);
    log.info("count={}", count);
    OrderCount resp = new OrderCount();
    resp.put(user.getName(), count);
    return resp;
}
Also used : StorageOSUser(com.emc.storageos.security.authentication.StorageOSUser) OrderCount(com.emc.vipr.model.catalog.OrderCount) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Example 62 with StorageOSUser

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

the class ExecutionWindowService method createExecutionWindow.

/**
 * Creates a new execution window
 *
 * @param createParam
 *            the parameter to create a new execution window
 * @prereq none
 * @brief Create Execution Window
 * @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 ExecutionWindowRestRep createExecutionWindow(ExecutionWindowCreateParam createParam) {
    StorageOSUser user = getUserFromContext();
    verifyAuthorizedInTenantOrg(createParam.getTenant(), user);
    validateParam(createParam, null, user.getTenantId());
    ExecutionWindow executionWindow = createNewObject(createParam);
    executionWindowManager.createExecutionWindow(executionWindow);
    auditOpSuccess(OperationTypeEnum.CREATE_EXECUTION_WINDOW, executionWindow.auditParameters());
    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) POST(javax.ws.rs.POST) Consumes(javax.ws.rs.Consumes) Produces(javax.ws.rs.Produces) CheckPermission(com.emc.storageos.security.authorization.CheckPermission)

Example 63 with StorageOSUser

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

the class ExecutionWindowService method getExecutionWindows.

/**
 * Gets the list of execution windows
 *
 * @param tenantId the URN of a tenant
 * @brief List Execution Windows
 * @return a list of execution windows
 * @throws DatabaseException when a DB error occurs
 */
@GET
@Path("")
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
public ExecutionWindowList getExecutionWindows(@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<ExecutionWindow> executionWindows = executionWindowManager.getExecutionWindows(uri(tenantId));
    ExecutionWindowList list = new ExecutionWindowList();
    for (ExecutionWindow executionWindow : executionWindows) {
        NamedRelatedResourceRep resourceRep = toNamedRelatedResource(ResourceTypeEnum.EXECUTION_WINDOW, executionWindow.getId(), executionWindow.getLabel());
        list.getExecutionWindows().add(resourceRep);
    }
    return list;
}
Also used : ExecutionWindow(com.emc.storageos.db.client.model.uimodels.ExecutionWindow) StorageOSUser(com.emc.storageos.security.authentication.StorageOSUser) ExecutionWindowList(com.emc.vipr.model.catalog.ExecutionWindowList) NamedRelatedResourceRep(com.emc.storageos.model.NamedRelatedResourceRep) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Example 64 with StorageOSUser

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

the class UserPreferenceService method update.

@PUT
@Consumes({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@Path("")
public UserPreferencesRestRep update(UserPreferencesUpdateParam param) {
    StorageOSUser user = getUserFromContext();
    String username = param.getUsername();
    if (StringUtils.isBlank(username)) {
        username = user.getUserName();
    }
    verifyAuthorized(username, user);
    UserPreferences userPreferences = userPreferenceManager.getPreferences(username);
    validateParam(param, userPreferences);
    updateObject(userPreferences, param);
    userPreferenceManager.updatePreferences(userPreferences);
    auditOpSuccess(OperationTypeEnum.UPDATE_USER_PREFERENCES, userPreferences.auditParameters());
    userPreferences = userPreferenceManager.getPreferences(userPreferences.getUserId());
    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) Consumes(javax.ws.rs.Consumes) Produces(javax.ws.rs.Produces) PUT(javax.ws.rs.PUT)

Example 65 with StorageOSUser

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

the class ApprovalService method getOtherSearchResults.

/**
 * parameter: 'orderId' The id of the order to search for approvals
 * parameter: 'approvalStatus' The status for the approval.
 * parameter: 'tenantId' The id of the tenant (if not the current tenant)
 *
 * @return Return a list of matching approvals 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_ID_PARAM) && !parameters.containsKey(SearchConstants.APPROVAL_STATUS_PARAM)) {
        throw APIException.badRequests.invalidParameterSearchMissingParameter(getResourceClass().getName(), SearchConstants.ORDER_ID_PARAM + " or " + SearchConstants.APPROVAL_STATUS_PARAM);
    }
    if (parameters.containsKey(SearchConstants.ORDER_ID_PARAM) && parameters.containsKey(SearchConstants.APPROVAL_STATUS_PARAM)) {
        throw APIException.badRequests.parameterForSearchCouldNotBeCombinedWithAnyOtherParameter(getResourceClass().getName(), SearchConstants.ORDER_ID_PARAM, SearchConstants.APPROVAL_STATUS_PARAM);
    }
    List<ApprovalRequest> approvals = Lists.newArrayList();
    if (parameters.containsKey(SearchConstants.ORDER_ID_PARAM)) {
        String orderId = parameters.get(SearchConstants.ORDER_ID_PARAM).get(0);
        ArgValidator.checkFieldNotEmpty(orderId, SearchConstants.ORDER_ID_PARAM);
        approvals = approvalManager.findApprovalsByOrderId(uri(orderId));
    } else if (parameters.containsKey(SearchConstants.APPROVAL_STATUS_PARAM)) {
        String approvalStatus = parameters.get(SearchConstants.APPROVAL_STATUS_PARAM).get(0);
        ArgValidator.checkFieldNotEmpty(approvalStatus, SearchConstants.APPROVAL_STATUS_PARAM);
        approvals = approvalManager.findApprovalsByStatus(uri(tenantId), ApprovalStatus.valueOf(approvalStatus));
    }
    ResRepFilter<SearchResultResourceRep> resRepFilter = (ResRepFilter<SearchResultResourceRep>) getPermissionFilter(getUserFromContext(), _permissionsHelper);
    List<SearchResultResourceRep> searchResultResourceReps = Lists.newArrayList();
    for (ApprovalRequest approval : approvals) {
        RestLinkRep selfLink = new RestLinkRep("self", RestLinkFactory.newLink(getResourceType(), approval.getId()));
        SearchResultResourceRep searchResultResourceRep = new SearchResultResourceRep();
        searchResultResourceRep.setId(approval.getId());
        searchResultResourceRep.setLink(selfLink);
        if (authorized || resRepFilter.isAccessible(searchResultResourceRep)) {
            searchResultResourceReps.add(searchResultResourceRep);
        }
    }
    SearchResults result = new SearchResults();
    result.setResource(searchResultResourceReps);
    return result;
}
Also used : StorageOSUser(com.emc.storageos.security.authentication.StorageOSUser) SearchResultResourceRep(com.emc.storageos.model.search.SearchResultResourceRep) ApprovalRequest(com.emc.storageos.db.client.model.uimodels.ApprovalRequest) RestLinkRep(com.emc.storageos.model.RestLinkRep) ResRepFilter(com.emc.storageos.api.service.impl.response.ResRepFilter) SearchResults(com.emc.storageos.model.search.SearchResults)

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