Search in sources :

Example 1 with NamedElementQueryResultList

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;
}
Also used : Set(java.util.Set) HashSet(java.util.HashSet) AbstractChangeTrackingSet(com.emc.storageos.db.client.model.AbstractChangeTrackingSet) StringSet(com.emc.storageos.db.client.model.StringSet) ArrayList(java.util.ArrayList) NamedURI(com.emc.storageos.db.client.model.NamedURI) URI(java.net.URI) StorageOSUser(com.emc.storageos.security.authentication.StorageOSUser) TenantOrg(com.emc.storageos.db.client.model.TenantOrg) TenantOrgList(com.emc.storageos.model.tenant.TenantOrgList) NamedElementQueryResultList(com.emc.storageos.db.client.constraint.NamedElementQueryResultList) HashSet(java.util.HashSet) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Example 2 with NamedElementQueryResultList

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;
}
Also used : Set(java.util.Set) HashSet(java.util.HashSet) AbstractChangeTrackingSet(com.emc.storageos.db.client.model.AbstractChangeTrackingSet) StringSet(com.emc.storageos.db.client.model.StringSet) ArrayList(java.util.ArrayList) NamedURI(com.emc.storageos.db.client.model.NamedURI) URI(java.net.URI) Project(com.emc.storageos.db.client.model.Project) StorageOSUser(com.emc.storageos.security.authentication.StorageOSUser) ProjectList(com.emc.storageos.model.project.ProjectList) TenantOrg(com.emc.storageos.db.client.model.TenantOrg) NamedElementQueryResultList(com.emc.storageos.db.client.constraint.NamedElementQueryResultList) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Example 3 with NamedElementQueryResultList

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;
}
Also used : Set(java.util.Set) HashSet(java.util.HashSet) AbstractChangeTrackingSet(com.emc.storageos.db.client.model.AbstractChangeTrackingSet) StringSet(com.emc.storageos.db.client.model.StringSet) ArrayList(java.util.ArrayList) NamedURI(com.emc.storageos.db.client.model.NamedURI) URI(java.net.URI) SchedulePolicyList(com.emc.storageos.model.schedulepolicy.SchedulePolicyList) StorageOSUser(com.emc.storageos.security.authentication.StorageOSUser) TenantOrg(com.emc.storageos.db.client.model.TenantOrg) NamedElementQueryResultList(com.emc.storageos.db.client.constraint.NamedElementQueryResultList) SchedulePolicy(com.emc.storageos.db.client.model.SchedulePolicy) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET) CheckPermission(com.emc.storageos.security.authorization.CheckPermission)

Example 4 with NamedElementQueryResultList

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);
        }
    }
}
Also used : TenantOrg(com.emc.storageos.db.client.model.TenantOrg) TenantOrgList(com.emc.storageos.model.tenant.TenantOrgList) NamedElementQueryResultList(com.emc.storageos.db.client.constraint.NamedElementQueryResultList)

Example 5 with NamedElementQueryResultList

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;
}
Also used : StorageOSUser(com.emc.storageos.security.authentication.StorageOSUser) NamedElementQueryResultList(com.emc.storageos.db.client.constraint.NamedElementQueryResultList) AuthnProviderList(com.emc.storageos.model.auth.AuthnProviderList) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Aggregations

NamedElementQueryResultList (com.emc.storageos.db.client.constraint.NamedElementQueryResultList)18 URI (java.net.URI)11 ArrayList (java.util.ArrayList)6 NamedURI (com.emc.storageos.db.client.model.NamedURI)5 AlternateIdConstraint (com.emc.storageos.db.client.constraint.AlternateIdConstraint)4 AlternateIdConstraintImpl (com.emc.storageos.db.client.constraint.impl.AlternateIdConstraintImpl)4 DataObjectType (com.emc.storageos.db.client.impl.DataObjectType)4 TenantOrg (com.emc.storageos.db.client.model.TenantOrg)4 UserPreferences (com.emc.storageos.db.client.model.UserPreferences)4 StorageOSUser (com.emc.storageos.security.authentication.StorageOSUser)4 HashSet (java.util.HashSet)4 GET (javax.ws.rs.GET)4 Produces (javax.ws.rs.Produces)4 AbstractChangeTrackingSet (com.emc.storageos.db.client.model.AbstractChangeTrackingSet)3 StringSet (com.emc.storageos.db.client.model.StringSet)3 Set (java.util.Set)3 Path (javax.ws.rs.Path)3 NamedElement (com.emc.storageos.db.client.constraint.NamedElementQueryResultList.NamedElement)2 TimeSeriesConstraint (com.emc.storageos.db.client.constraint.TimeSeriesConstraint)2 Order (com.emc.storageos.db.client.model.uimodels.Order)2