use of com.emc.storageos.security.geo.GeoServiceClient in project coprhd-controller by CoprHD.
the class FileVirtualPoolService method queryFilteredBulkResourceReps.
@SuppressWarnings({ "unchecked", "rawtypes" })
@Override
protected FileVirtualPoolBulkRep queryFilteredBulkResourceReps(List<URI> ids) {
if (isSystemOrRestrictedSystemAdmin()) {
return queryBulkResourceReps(ids);
}
if (!ids.iterator().hasNext()) {
return new FileVirtualPoolBulkRep();
}
// get vdc id from the first id; assume all id's are from the same vdc
String shortVdcId = VdcUtil.getVdcId(VirtualArray.class, ids.iterator().next()).toString();
Iterator<VirtualPool> dbIterator;
if (shortVdcId.equals(VdcUtil.getLocalShortVdcId())) {
dbIterator = _dbClient.queryIterativeObjects(getResourceClass(), ids);
} else {
GeoServiceClient geoClient = _geoHelper.getClient(shortVdcId);
try {
dbIterator = geoClient.queryObjects(getResourceClass(), ids);
} catch (Exception ex) {
// TODO: revisit this exception
_log.error("error retrieving bulk virtual pools from vdc " + shortVdcId, ex);
throw APIException.internalServerErrors.genericApisvcError("error retrieving remote virtual pool", ex);
}
}
BulkList.ResourceFilter filter = new BulkList.VirtualPoolFilter(Type.file, getUserFromContext(), _permissionsHelper);
return new FileVirtualPoolBulkRep(BulkList.wrapping(dbIterator, MapFileVirtualPool.getInstance(), filter));
}
use of com.emc.storageos.security.geo.GeoServiceClient in project coprhd-controller by CoprHD.
the class BlockVirtualPoolService method queryFilteredBulkResourceReps.
@SuppressWarnings({ "unchecked", "rawtypes" })
@Override
protected BlockVirtualPoolBulkRep queryFilteredBulkResourceReps(List<URI> ids) {
if (isSystemOrRestrictedSystemAdmin()) {
return queryBulkResourceReps(ids);
}
if (!ids.iterator().hasNext()) {
return new BlockVirtualPoolBulkRep();
}
// get vdc id from the first id; assume all id's are from the same vdc
String shortVdcId = VdcUtil.getVdcId(getResourceClass(), ids.iterator().next()).toString();
Iterator<VirtualPool> dbIterator;
if (shortVdcId.equals(VdcUtil.getLocalShortVdcId())) {
dbIterator = _dbClient.queryIterativeObjects(getResourceClass(), ids);
} else {
GeoServiceClient geoClient = _geoHelper.getClient(shortVdcId);
try {
dbIterator = geoClient.queryObjects(getResourceClass(), ids);
} catch (Exception ex) {
// TODO: revisit this exception
_log.error("error retrieving bulk virtual pools from vdc " + shortVdcId, ex);
throw APIException.internalServerErrors.genericApisvcError("error retrieving remote virtual pool", ex);
}
}
BulkList.ResourceFilter filter = new BulkList.VirtualPoolFilter(Type.block, getUserFromContext(), _permissionsHelper);
return new BlockVirtualPoolBulkRep(BulkList.wrapping(dbIterator, BLOCK_VPOOL_MAPPER, filter));
}
use of com.emc.storageos.security.geo.GeoServiceClient in project coprhd-controller by CoprHD.
the class VirtualArrayService method getVirtualArrayList.
/**
* List VirtualArrays in zone the user is authorized to see
*
* @brief List VirtualArrays in zone
* @return List of VirtualArrays
*/
@GET
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
public VirtualArrayList getVirtualArrayList(@DefaultValue("") @QueryParam(VDC_ID_QUERY_PARAM) String shortVdcId, @DefaultValue("") @QueryParam(TENANT_ID_QUERY_PARAM) String tenantId) {
_geoHelper.verifyVdcId(shortVdcId);
VirtualArrayList list = new VirtualArrayList();
TenantOrg tenant_input = null;
// if input tenant is not empty, but user have no access to it, return empty list.
if (!StringUtils.isEmpty(tenantId)) {
tenant_input = getTenantIfHaveAccess(tenantId);
if (tenant_input == null) {
return list;
}
}
List<VirtualArray> nhObjList = Collections.emptyList();
if (_geoHelper.isLocalVdcId(shortVdcId)) {
_log.debug("retrieving virtual arrays via dbclient");
final List<URI> ids = _dbClient.queryByType(VirtualArray.class, true);
nhObjList = _dbClient.queryObject(VirtualArray.class, ids);
} else {
_log.debug("retrieving virtual arrays via geoclient");
try {
GeoServiceClient geoClient = _geoHelper.getClient(shortVdcId);
final List<URI> ids = Lists.newArrayList(geoClient.queryByType(VirtualArray.class, true));
nhObjList = Lists.newArrayList(geoClient.queryObjects(VirtualArray.class, ids));
} catch (Exception ex) {
// TODO: revisit this exception
_log.error("error retrieving virtual arrays", ex);
throw APIException.internalServerErrors.genericApisvcError("error retrieving virtual arrays", ex);
}
}
StorageOSUser user = getUserFromContext();
// else only return the list, which input tenant has access.
if (_permissionsHelper.userHasGivenRole(user, null, Role.SYSTEM_ADMIN, Role.SYSTEM_MONITOR)) {
for (VirtualArray nh : nhObjList) {
if (tenant_input == null || _permissionsHelper.tenantHasUsageACL(tenant_input.getId(), nh)) {
list.getVirtualArrays().add(toNamedRelatedResource(ResourceTypeEnum.VARRAY, nh.getId(), nh.getLabel()));
}
}
} else {
// otherwise, filter by only authorized to use
URI tenant = null;
if (tenant_input == null) {
tenant = URI.create(user.getTenantId());
} else {
tenant = tenant_input.getId();
}
Set<VirtualArray> varraySet = new HashSet<VirtualArray>();
for (VirtualArray virtualArray : nhObjList) {
if (_permissionsHelper.tenantHasUsageACL(tenant, virtualArray)) {
varraySet.add(virtualArray);
}
}
// if no tenant specified in request, also adding varrays which sub-tenants of the user have access to.
if (tenant_input == null) {
List<URI> subtenants = _permissionsHelper.getSubtenantsWithRoles(user);
for (VirtualArray virtualArray : nhObjList) {
if (_permissionsHelper.tenantHasUsageACL(subtenants, virtualArray)) {
varraySet.add(virtualArray);
}
}
}
for (VirtualArray virtualArray : varraySet) {
list.getVirtualArrays().add(toNamedRelatedResource(ResourceTypeEnum.VARRAY, virtualArray.getId(), virtualArray.getLabel()));
}
}
return list;
}
use of com.emc.storageos.security.geo.GeoServiceClient in project coprhd-controller by CoprHD.
the class VirtualArrayService method queryFilteredBulkResourceReps.
@SuppressWarnings({ "unchecked", "rawtypes" })
@Override
protected VirtualArrayBulkRep queryFilteredBulkResourceReps(List<URI> ids) {
if (isSystemOrRestrictedSystemAdmin()) {
return queryBulkResourceReps(ids);
}
if (!ids.iterator().hasNext()) {
return new VirtualArrayBulkRep();
}
// get vdc id from the first id; assume all id's are from the same vdc
String shortVdcId = VdcUtil.getVdcId(getResourceClass(), ids.iterator().next()).toString();
Iterator<VirtualArray> dbIterator;
if (shortVdcId.equals(VdcUtil.getLocalShortVdcId())) {
dbIterator = _dbClient.queryIterativeObjects(getResourceClass(), ids);
} else {
GeoServiceClient geoClient = _geoHelper.getClient(shortVdcId);
try {
dbIterator = geoClient.queryObjects(getResourceClass(), ids);
} catch (Exception ex) {
// TODO: revisit this exception
_log.error("error retrieving bulk virtual arrays from vdc " + shortVdcId, ex);
throw APIException.internalServerErrors.genericApisvcError("error retrieving remote array", ex);
}
}
BulkList.ResourceFilter filter = new BulkList.VirtualArrayACLFilter(getUserFromContext(), _permissionsHelper);
return new VirtualArrayBulkRep(BulkList.wrapping(dbIterator, MapVirtualArray.getInstance(), filter));
}
use of com.emc.storageos.security.geo.GeoServiceClient in project coprhd-controller by CoprHD.
the class VirtualPoolService method getVirtualPoolList.
protected VirtualPoolList getVirtualPoolList(VirtualPool.Type type, String shortVdcId, String tenantId) {
URIQueryResultList vpoolList = new URIQueryResultList();
VirtualPoolList list = new VirtualPoolList();
TenantOrg tenant_input = null;
// if input tenant is not empty, but user have no access to it, return empty list.
if (!StringUtils.isEmpty(tenantId)) {
tenant_input = getTenantIfHaveAccess(tenantId);
if (tenant_input == null) {
return list;
}
}
StorageOSUser user = getUserFromContext();
List<VirtualPool> vpoolObjects = null;
if (_geoHelper.isLocalVdcId(shortVdcId)) {
_log.debug("retrieving virtual pools via the dbclient");
_dbClient.queryByConstraint(AlternateIdConstraint.Factory.getVpoolTypeVpoolConstraint(type), vpoolList);
List<URI> allowed = new ArrayList<URI>();
for (URI vpool : vpoolList) {
allowed.add(vpool);
}
vpoolObjects = _dbClient.queryObject(VirtualPool.class, allowed);
} else {
_log.debug("retrieving virtual pools via the geoclient");
GeoServiceClient geoClient = _geoHelper.getClient(shortVdcId);
try {
// TODO: query by constraint isn't working on the geosvc
// List<URI> resultList = geoClient.queryByConstraint(AlternateIdConstraint.Factory.getVpoolTypeVpoolConstraint(type),
// URIQueryResultList.class);
Iterator<URI> uriIter = geoClient.queryByType(VirtualPool.class, true);
List<URI> resultList = Lists.newArrayList(uriIter);
Iterator<VirtualPool> iter = geoClient.queryObjects(VirtualPool.class, resultList);
// iter);
vpoolObjects = Lists.newArrayList();
while (iter.hasNext()) {
VirtualPool p = iter.next();
if (type.toString().equals(p.getType())) {
vpoolObjects.add(p);
}
}
} catch (Exception ex) {
// TODO: revisit this exception
_log.error("error retrieving virtual pools from vdc " + shortVdcId, ex);
throw APIException.internalServerErrors.genericApisvcError("error retrieving remote pools", ex);
}
}
// else only return the list, which input tenant has access.
if (_permissionsHelper.userHasGivenRole(user, null, Role.SYSTEM_ADMIN, Role.SYSTEM_MONITOR)) {
for (VirtualPool virtualPool : vpoolObjects) {
if (tenant_input == null || _permissionsHelper.tenantHasUsageACL(tenant_input.getId(), virtualPool)) {
list.getVirtualPool().add(toVirtualPoolResource(virtualPool));
}
}
} else {
// otherwise, filter by only authorized to use
URI tenant = null;
if (tenant_input == null) {
tenant = URI.create(user.getTenantId());
} else {
tenant = tenant_input.getId();
}
Set<VirtualPool> vpoolSet = new HashSet<VirtualPool>();
for (VirtualPool virtualPool : vpoolObjects) {
if (_permissionsHelper.tenantHasUsageACL(tenant, virtualPool)) {
vpoolSet.add(virtualPool);
}
}
// if no tenant specified in request, also adding vpools which sub-tenants of the user have access to.
if (tenant_input == null) {
List<URI> subtenants = _permissionsHelper.getSubtenantsWithRoles(user);
for (VirtualPool virtualPool : vpoolObjects) {
if (_permissionsHelper.tenantHasUsageACL(subtenants, virtualPool)) {
vpoolSet.add(virtualPool);
}
}
}
for (VirtualPool virtualPool : vpoolSet) {
list.getVirtualPool().add(toVirtualPoolResource(virtualPool));
}
}
return list;
}
Aggregations