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;
}
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);
}
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;
}
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);
}
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;
}
Aggregations