use of com.emc.storageos.db.client.constraint.NamedElementQueryResultList in project coprhd-controller by CoprHD.
the class TenantsService method listSubTenants.
/**
* List subtenants
*
* @param id the URN of a ViPR Tenant
* @prereq none
* @brief List subtenants
* @return List of subtenants
*/
@GET
@Path("/{id}/subtenants")
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
public TenantOrgList listSubTenants(@PathParam("id") URI id) {
StorageOSUser user = getUserFromContext();
TenantOrg tenant = getTenantById(id, false);
TenantOrgList list = new TenantOrgList();
if (!TenantOrg.isRootTenant(tenant)) {
// no subtenants if not root tenant
throw APIException.methodNotAllowed.notSupportedForSubtenants();
}
NamedElementQueryResultList subtenants = new NamedElementQueryResultList();
if (_permissionsHelper.userHasGivenRole(user, tenant.getId(), Role.SYSTEM_MONITOR, Role.TENANT_ADMIN, Role.SECURITY_ADMIN, Role.SYSTEM_ADMIN)) {
_dbClient.queryByConstraint(ContainmentConstraint.Factory.getTenantOrgSubTenantConstraint(tenant.getId()), subtenants);
} else {
// we will most likely not need indexing for tenants
// given the number of tenants is not going to be that many
Set<String> roles = new HashSet<String>();
roles.add(Role.TENANT_ADMIN.toString());
Map<URI, Set<String>> allTenantPermissions = _permissionsHelper.getAllPermissionsForUser(user, tenant.getId(), roles, true);
if (!allTenantPermissions.keySet().isEmpty()) {
List<TenantOrg> tenants = _dbClient.queryObjectField(TenantOrg.class, "label", new ArrayList<URI>(allTenantPermissions.keySet()));
List<NamedElementQueryResultList.NamedElement> elements = new ArrayList<NamedElementQueryResultList.NamedElement>(tenants.size());
for (TenantOrg t : tenants) {
elements.add(NamedElementQueryResultList.NamedElement.createElement(t.getId(), t.getLabel()));
}
subtenants.setResult(elements.iterator());
} else {
throw APIException.forbidden.insufficientPermissionsForUser(user.getName());
}
}
for (NamedElementQueryResultList.NamedElement el : subtenants) {
list.getSubtenants().add(toNamedRelatedResource(ResourceTypeEnum.TENANT, el.getId(), el.getName()));
}
return list;
}
use of com.emc.storageos.db.client.constraint.NamedElementQueryResultList in project coprhd-controller by CoprHD.
the class TenantsService method listProjects.
/**
* List projects the user is authorized to see
*
* @param id the URN of a ViPR Tenant/Subtenant
* @prereq none
* @brief List projects
* @return List of projects
*/
@GET
@Path("/{id}/projects")
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
public ProjectList listProjects(@PathParam("id") URI id) {
TenantOrg tenant = getTenantById(id, false);
StorageOSUser user = getUserFromContext();
NamedElementQueryResultList projects = new NamedElementQueryResultList();
if (_permissionsHelper.userHasGivenRole(user, tenant.getId(), Role.SYSTEM_MONITOR, Role.TENANT_ADMIN, Role.SECURITY_ADMIN)) {
// list all
_dbClient.queryByConstraint(ContainmentConstraint.Factory.getTenantOrgProjectConstraint(tenant.getId()), projects);
} else {
// list only projects that the user has access to
if (!id.equals(URI.create(user.getTenantId()))) {
throw APIException.forbidden.insufficientPermissionsForUser(user.getName());
}
Map<URI, Set<String>> allMyProjects = _permissionsHelper.getAllPermissionsForUser(user, tenant.getId(), null, false);
if (!allMyProjects.keySet().isEmpty()) {
List<Project> project_list = _dbClient.queryObjectField(Project.class, "label", new ArrayList<URI>(allMyProjects.keySet()));
List<NamedElementQueryResultList.NamedElement> elements = new ArrayList<NamedElementQueryResultList.NamedElement>(project_list.size());
for (Project p : project_list) {
elements.add(NamedElementQueryResultList.NamedElement.createElement(p.getId(), p.getLabel()));
}
projects.setResult(elements.iterator());
} else {
// empty list
projects.setResult(new ArrayList<NamedElementQueryResultList.NamedElement>().iterator());
}
}
ProjectList list = new ProjectList();
for (NamedElementQueryResultList.NamedElement el : projects) {
list.getProjects().add(toNamedRelatedResource(ResourceTypeEnum.PROJECT, el.getId(), el.getName()));
}
return list;
}
use of com.emc.storageos.db.client.constraint.NamedElementQueryResultList in project coprhd-controller by CoprHD.
the class TenantsService method getSchedulePolicies.
/**
* Gets the policyIds, policyNames and self links for all schedule policies.
*
* @param id the URN of a CoprHD Tenant/Subtenant
* @brief List schedule policies
* @return policyList - A SchedulePolicyList reference specifying the policyIds, name and self links for
* the schedule policies.
*/
@GET
@Path("/{id}/schedule-policies")
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@CheckPermission(roles = { Role.TENANT_ADMIN, Role.PROJECT_ADMIN })
public SchedulePolicyList getSchedulePolicies(@PathParam("id") URI id) {
TenantOrg tenant = getTenantById(id, false);
StorageOSUser user = getUserFromContext();
NamedElementQueryResultList schedulePolicies = new NamedElementQueryResultList();
if (_permissionsHelper.userHasGivenRole(user, tenant.getId(), Role.SYSTEM_MONITOR, Role.TENANT_ADMIN, Role.SECURITY_ADMIN)) {
// list all schedule policies
_dbClient.queryByConstraint(ContainmentConstraint.Factory.getTenantOrgSchedulePolicyConstraint(tenant.getId()), schedulePolicies);
} else {
// list only schedule policies that the user has access to
if (!id.equals(URI.create(user.getTenantId()))) {
throw APIException.forbidden.insufficientPermissionsForUser(user.getName());
}
Map<URI, Set<String>> allMySchedulePolicies = _permissionsHelper.getAllPermissionsForUser(user, tenant.getId(), null, false);
if (!allMySchedulePolicies.keySet().isEmpty()) {
List<SchedulePolicy> policyList = _dbClient.queryObjectField(SchedulePolicy.class, "label", new ArrayList<URI>(allMySchedulePolicies.keySet()));
List<NamedElementQueryResultList.NamedElement> elements = new ArrayList<NamedElementQueryResultList.NamedElement>(policyList.size());
for (SchedulePolicy policy : policyList) {
elements.add(NamedElementQueryResultList.NamedElement.createElement(policy.getId(), policy.getLabel()));
}
schedulePolicies.setResult(elements.iterator());
} else {
// empty list
schedulePolicies.setResult(new ArrayList<NamedElementQueryResultList.NamedElement>().iterator());
}
}
SchedulePolicyList policyList = new SchedulePolicyList();
for (NamedElementQueryResultList.NamedElement el : schedulePolicies) {
policyList.getSchdulePolicies().add(toNamedRelatedResource(ResourceTypeEnum.SCHEDULE_POLICY, el.getId(), el.getName()));
}
return policyList;
}
use of com.emc.storageos.db.client.constraint.NamedElementQueryResultList in project coprhd-controller by CoprHD.
the class ResourceService method checkForDuplicateNamespace.
/**
* Check if a tenant with the same namespace exists
* @param namespace namespace of the tenant
*/
public void checkForDuplicateNamespace(String namespace) {
TenantOrgList list = new TenantOrgList();
// Verify with root tenant if current is not root
TenantOrg rootTenant = _permissionsHelper.getRootTenant();
if (rootTenant.getNamespace() != null && rootTenant.getNamespace().equalsIgnoreCase(namespace)) {
throw APIException.badRequests.duplicateNamespace(namespace);
}
NamedElementQueryResultList subtenants = new NamedElementQueryResultList();
_dbClient.queryByConstraint(ContainmentConstraint.Factory.getTenantOrgSubTenantConstraint(rootTenant.getId()), subtenants);
for (NamedElementQueryResultList.NamedElement el : subtenants) {
TenantOrg currTenant = _dbClient.queryObject(TenantOrg.class, el.getId());
if (currTenant.getNamespace() != null && currTenant.getNamespace().equalsIgnoreCase(namespace)) {
throw APIException.badRequests.duplicateNamespace(namespace);
}
}
}
use of com.emc.storageos.db.client.constraint.NamedElementQueryResultList in project coprhd-controller by CoprHD.
the class AuthnConfigurationService method listProviders.
/**
* List authentication providers in the zone.
*
* @brief List authentication providers
* @return List of authentication providers
*/
@GET
// no id, just "/"
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
public AuthnProviderList listProviders() {
// TODO: if you need to copy/paste this code, please modify the AbstractPermissionFilter class instead and
// related CheckPermission annotation code to support "TENANT_ADMIN_IN_ANY_TENANT" permission.
StorageOSUser user = getUserFromContext();
if (!_permissionsHelper.userHasGivenRoleInAnyTenant(user, Role.SECURITY_ADMIN, Role.TENANT_ADMIN)) {
throw APIException.forbidden.insufficientPermissionsForUser(user.getName());
}
NamedElementQueryResultList providers = new NamedElementQueryResultList();
List<URI> uris = _dbClient.queryByType(AuthnProvider.class, true);
List<AuthnProvider> configs = _dbClient.queryObject(AuthnProvider.class, uris);
List<NamedElementQueryResultList.NamedElement> elements = new ArrayList<NamedElementQueryResultList.NamedElement>(configs.size());
for (AuthnProvider p : configs) {
elements.add(NamedElementQueryResultList.NamedElement.createElement(p.getId(), p.getLabel()));
}
providers.setResult(elements.iterator());
AuthnProviderList list = new AuthnProviderList();
list.getProviders().addAll(map(ResourceTypeEnum.AUTHN_PROVIDER, providers));
return list;
}
Aggregations