Search in sources :

Example 6 with ProjectParam

use of com.emc.storageos.model.project.ProjectParam in project coprhd-controller by CoprHD.

the class ApiTest method prepareVdcTest.

/**
 * test for API /vdc/prepare-vdc, which will remove all root's tenant roles and project ownerships
 *
 * before calling the API, prepare root to be:
 * 1. Provider Tenant's tenant admin
 * 2. owner of a project of Provider Tenant
 * 3. Tenant Admin of a subtenant
 * 4. owner of a project from subtenant
 */
public void prepareVdcTest() throws Exception {
    ClientResponse resp = null;
    BalancedWebResource rootUser = createHttpsClient(SYSADMIN, SYSADMIN_PASS_WORD, baseUrls);
    UserInfo info = rootUser.path("/user/whoami").get(UserInfo.class);
    String rootTenantId = info.getTenant();
    String rootToken = (String) _savedTokens.get(SYSADMIN);
    BalancedWebResource superSanity = createHttpsClient(SUPERUSER, AD_PASS_WORD, baseUrls);
    superSanity.path("/tenant").get(TenantResponse.class);
    String superSanityToken = (String) _savedTokens.get(SUPERUSER);
    // prepare tenant roles and project ownership
    // also assign TenantAdmin to superuser, so it can be used to verify afterwards
    boolean bRootHasProviderTenantAdmin = true;
    if (info.getHomeTenantRoles().isEmpty()) {
        bRootHasProviderTenantAdmin = false;
        resp = assignTenantRole(rootTenantId, SYSADMIN, "TENANT_ADMIN");
        Assert.assertEquals(200, resp.getStatus());
        resp = assignTenantRole(rootTenantId, SUPERUSER, "TENANT_ADMIN");
        Assert.assertEquals(200, resp.getStatus());
    }
    // create a project of Provider Tenant by root, root will be its owner.
    ProjectParam paramProj = new ProjectParam("project_" + new Random().nextInt());
    ProjectEntry rootProject1 = rootUser.path(String.format(_projectsUrlFormat, rootTenantId.toString())).header(AUTH_TOKEN_HEADER, rootToken).post(ProjectEntry.class, paramProj);
    Assert.assertTrue(rootProject1.name.equals(paramProj.getName()));
    Assert.assertTrue(rootProject1.id != null);
    // create a subtenant by root, root will be its TenantAdmin
    String tenantLabel = "tenant_" + new Random().nextInt();
    TenantOrgRestRep subtenant = createTenant(tenantLabel, "sanity.local", "key", tenantLabel);
    resp = assignTenantRole(subtenant.getId().toString(), SUPERUSER, "TENANT_ADMIN");
    Assert.assertEquals(200, resp.getStatus());
    // create a project under the subtenant created above, root will be its owner
    paramProj = new ProjectParam("project_" + new Random().nextInt());
    ProjectEntry rootProject2 = rootUser.path(String.format(_projectsUrlFormat, subtenant.getId().toString())).header(AUTH_TOKEN_HEADER, rootToken).post(ProjectEntry.class, paramProj);
    Assert.assertTrue(rootProject2.name.equals(paramProj.getName()));
    Assert.assertTrue(rootProject2.id != null);
    // call /vdc/prepare-vdc
    ClientResponse response = rootUser.path("/vdc/prepare-vdc").header(AUTH_TOKEN_HEADER, rootToken).post(ClientResponse.class);
    Assert.assertEquals(200, response.getStatus());
    // verify root's tenant roles and project ownership be removed
    resp = rootUser.path("/user/whoami").get(ClientResponse.class);
    String output = resp.getEntity(String.class);
    Assert.assertFalse(output.contains("TENANT_ADMIN"));
    resp = superSanity.path(String.format(_projectUrl, rootProject1.id.toString())).get(ClientResponse.class);
    output = resp.getEntity(String.class);
    Assert.assertFalse(output.contains(SYSADMIN));
    resp = superSanity.path(String.format(_projectUrl, rootProject2.id.toString())).get(ClientResponse.class);
    output = resp.getEntity(String.class);
    Assert.assertFalse(output.contains(SYSADMIN));
    // test done, restore root's tenant role and remove the project
    if (bRootHasProviderTenantAdmin) {
        assignTenantRole(rootTenantId, SYSADMIN, "TENANT_ADMIN");
    }
    if (rootProject1 != null) {
        superSanity.path(String.format(_projectUrl + "/deactivate", rootProject1.id.toString())).header(AUTH_TOKEN_HEADER, superSanityToken).post(ClientResponse.class);
    }
    if (rootProject2 != null) {
        superSanity.path(String.format(_projectUrl + "/deactivate", rootProject2.id.toString())).header(AUTH_TOKEN_HEADER, superSanityToken).post(ClientResponse.class);
    }
    if (subtenant != null) {
        superSanity.path("/tenants/" + subtenant.getId() + "/deactivate").header(AUTH_TOKEN_HEADER, superSanityToken).post();
    }
}
Also used : ClientResponse(com.sun.jersey.api.client.ClientResponse) ProjectParam(com.emc.storageos.model.project.ProjectParam) Random(java.util.Random) UserInfo(com.emc.storageos.model.user.UserInfo) TenantOrgRestRep(com.emc.storageos.model.tenant.TenantOrgRestRep)

Example 7 with ProjectParam

use of com.emc.storageos.model.project.ProjectParam in project coprhd-controller by CoprHD.

the class ApiTest method projectSetup.

private void projectSetup() {
    ProjectParam paramProj = new ProjectParam("resourcetestproject");
    ProjectElement project1 = rSTAdminGr1.path(String.format(_projectsUrlFormat, subtenant1Id.toString())).post(ProjectElement.class, paramProj);
    _testProject = project1.getId();
    ACLEntry entry = new ACLEntry();
    entry.setSubjectId(SUBTENANT1_READER);
    entry.setAces(new ArrayList<String>());
    entry.getAces().add("backup");
    ACLEntry entry2 = new ACLEntry();
    entry2.setGroup(SUBTENANT1_USERS_GROUP);
    entry2.setAces(new ArrayList<String>());
    entry2.getAces().add("all");
    ACLAssignmentChanges changes = new ACLAssignmentChanges();
    changes.setAdd(new ArrayList<ACLEntry>());
    changes.getAdd().add(entry2);
    changes.getAdd().add(entry);
    ClientResponse resp = rSTAdmin1.path(String.format(_projectAclUrl, _testProject.toString())).post(ClientResponse.class, changes);
    Assert.assertEquals(200, resp.getStatus());
}
Also used : ClientResponse(com.sun.jersey.api.client.ClientResponse) ProjectParam(com.emc.storageos.model.project.ProjectParam) ACLAssignmentChanges(com.emc.storageos.model.auth.ACLAssignmentChanges) ProjectElement(com.emc.storageos.model.project.ProjectElement) ACLEntry(com.emc.storageos.model.auth.ACLEntry)

Example 8 with ProjectParam

use of com.emc.storageos.model.project.ProjectParam in project coprhd-controller by CoprHD.

the class Projects method save.

@FlashException(keep = true, referrer = { "create", "edit" })
public static void save(ProjectForm project) {
    if (project == null) {
        Logger.error("No project parameters passed");
        badRequest("No project parameters passed");
        return;
    }
    project.validate("project");
    if (Validation.hasErrors()) {
        Common.handleError();
    }
    if (project.isNew()) {
        project.id = stringId(ProjectUtils.create(project.tenantId, new ProjectParam(project.name)));
        saveProjectQuota(project);
        saveProjectACLs(project.id, project.aclEntries);
    } else {
        ProjectRestRep currentProject = ProjectUtils.getProject(project.id);
        if (currentProject != null) {
            saveProjectQuota(project);
            saveProjectACLs(project.id, project.aclEntries);
            ProjectUtils.update(project.id, new ProjectUpdateParam(project.name, project.owner));
        }
    }
    flash.success(MessagesUtils.get("projects.saved", project.name));
    JsonObject jobject = getCookieAsJson(VIPR_START_GUIDE);
    if (jobject != null && jobject.get(GUIDE_COMPLETED_STEP) != null && jobject.get(GUIDE_VISIBLE) != null) {
        if (jobject.get("completedSteps").getAsInt() == 7 && jobject.get("guideVisible").getAsBoolean()) {
            JsonObject dataObject = getCookieAsJson(GUIDE_DATA);
            JsonArray projects = dataObject.getAsJsonArray("projects");
            if (projects == null) {
                projects = new JsonArray();
            }
            boolean addToCookie = true;
            for (Object projectObject : projects) {
                JsonObject projectjson = (JsonObject) projectObject;
                if (projectjson.get("id") != null) {
                    String projectId = projectjson.get("id").getAsString();
                    if (StringUtils.equals(projectId, project.id)) {
                        // update case, don't add in cookie
                        addToCookie = false;
                        break;
                    }
                }
            }
            if (addToCookie) {
                JsonObject projectObject = new JsonObject();
                projectObject.addProperty("id", project.id);
                projectObject.addProperty("name", project.name);
                projects.add(projectObject);
                dataObject.add("projects", projects);
                saveJsonAsCookie("GUIDE_DATA", dataObject);
            }
        }
    }
    if (StringUtils.isNotBlank(project.referrerUrl)) {
        redirect(project.referrerUrl);
    } else {
        list();
    }
}
Also used : JsonArray(com.google.gson.JsonArray) ProjectParam(com.emc.storageos.model.project.ProjectParam) ProjectUpdateParam(com.emc.storageos.model.project.ProjectUpdateParam) JsonObject(com.google.gson.JsonObject) JsonObject(com.google.gson.JsonObject) ProjectRestRep(com.emc.storageos.model.project.ProjectRestRep) FlashException(controllers.util.FlashException)

Example 9 with ProjectParam

use of com.emc.storageos.model.project.ProjectParam in project coprhd-controller by CoprHD.

the class AbstractRequestWrapperFilter method createTenantNProject.

private void createTenantNProject(KeystoneTenant tenant) {
    _internalTenantServiceClient.setServer(_keystoneUtils.getVIP());
    // Create Tenant via internal API call.
    TenantOrgRestRep tenantResp = _internalTenantServiceClient.createTenant(_keystoneUtils.prepareTenantParam(tenant));
    // Create Project via internal API call.
    ProjectParam projectParam = new ProjectParam(tenant.getName() + CinderConstants.PROJECT_NAME_SUFFIX);
    ProjectElement projectResp = _internalTenantServiceClient.createProject(tenantResp.getId(), projectParam);
    _keystoneUtils.tagProjectWithOpenstackId(projectResp.getId(), tenant.getId(), tenantResp.getId().toString());
    // Creates OSTenant representation of Openstack Tenant
    OSTenant osTenant = _keystoneUtils.mapToOsTenant(tenant);
    osTenant.setId(URIUtil.createId(OSTenant.class));
    _dbClient.createObject(osTenant);
}
Also used : ProjectParam(com.emc.storageos.model.project.ProjectParam) ProjectElement(com.emc.storageos.model.project.ProjectElement) TenantOrgRestRep(com.emc.storageos.model.tenant.TenantOrgRestRep)

Example 10 with ProjectParam

use of com.emc.storageos.model.project.ProjectParam in project coprhd-controller by CoprHD.

the class VPlexBlockServiceApiImpl method getVplexProject.

/**
 * Returns the Project assigned to this VPlex for its artifacts.
 * If there is no existing Project, one is created.
 *
 * @param vplexSystem A StorageSystem instance representing a VPlex.
 * @param dbClient A reference to a database client.
 *
 * @return Project instance that was created for holding this VPlex's private volumes/export groups.
 */
public static Project getVplexProject(StorageSystem vplexSystem, DbClient dbClient, TenantsService tenantsService) {
    BasePermissionsHelper helper = new BasePermissionsHelper(dbClient);
    TenantOrg rootTenant = helper.getRootTenant();
    PrefixConstraint constraint = PrefixConstraint.Factory.getLabelPrefixConstraint(Project.class, vplexSystem.getNativeGuid());
    URIQueryResultList result = new URIQueryResultList();
    dbClient.queryByConstraint(constraint, result);
    Iterator<URI> iter = result.iterator();
    while (iter.hasNext()) {
        Project project = dbClient.queryObject(Project.class, iter.next());
        if (project == null || project.getInactive() == true) {
            continue;
        }
        if (project.getLabel().equals(vplexSystem.getNativeGuid()) && project.getTenantOrg().getURI().toString().equals(rootTenant.getId().toString())) {
            return project;
        }
    }
    // Create the project
    ProjectParam projectParam = new ProjectParam(vplexSystem.getNativeGuid());
    ProjectElement projectElement = tenantsService.createProject(rootTenant.getId(), projectParam, TenantOrg.PROVIDER_TENANT_ORG, rootTenant.getId().toString());
    URI projectId = projectElement.getId();
    Project project = dbClient.queryObject(Project.class, projectId);
    project.addInternalFlags(DataObject.Flag.INTERNAL_OBJECT);
    dbClient.updateObject(project);
    return project;
}
Also used : Project(com.emc.storageos.db.client.model.Project) ProjectParam(com.emc.storageos.model.project.ProjectParam) PrefixConstraint(com.emc.storageos.db.client.constraint.PrefixConstraint) ContainmentPrefixConstraint(com.emc.storageos.db.client.constraint.ContainmentPrefixConstraint) ProjectElement(com.emc.storageos.model.project.ProjectElement) TenantOrg(com.emc.storageos.db.client.model.TenantOrg) FCTN_STRING_TO_URI(com.emc.storageos.db.client.util.CommonTransformerFunctions.FCTN_STRING_TO_URI) NamedURI(com.emc.storageos.db.client.model.NamedURI) URI(java.net.URI) FCTN_VPLEX_MIRROR_TO_URI(com.emc.storageos.db.client.util.CommonTransformerFunctions.FCTN_VPLEX_MIRROR_TO_URI) BasePermissionsHelper(com.emc.storageos.security.authorization.BasePermissionsHelper) URIQueryResultList(com.emc.storageos.db.client.constraint.URIQueryResultList)

Aggregations

ProjectParam (com.emc.storageos.model.project.ProjectParam)16 ProjectElement (com.emc.storageos.model.project.ProjectElement)8 ClientResponse (com.sun.jersey.api.client.ClientResponse)7 TenantOrgRestRep (com.emc.storageos.model.tenant.TenantOrgRestRep)4 Test (org.junit.Test)3 ACLAssignmentChanges (com.emc.storageos.model.auth.ACLAssignmentChanges)2 ACLEntry (com.emc.storageos.model.auth.ACLEntry)2 RoleAssignmentChanges (com.emc.storageos.model.auth.RoleAssignmentChanges)2 RoleAssignmentEntry (com.emc.storageos.model.auth.RoleAssignmentEntry)2 ProjectUpdateParam (com.emc.storageos.model.project.ProjectUpdateParam)2 TenantCreateParam (com.emc.storageos.model.tenant.TenantCreateParam)2 TenantResponse (com.emc.storageos.model.tenant.TenantResponse)2 UserInfo (com.emc.storageos.model.user.UserInfo)2 VirtualArrayList (com.emc.storageos.model.varray.VirtualArrayList)2 URI (java.net.URI)2 ArrayList (java.util.ArrayList)2 ContainmentPrefixConstraint (com.emc.storageos.db.client.constraint.ContainmentPrefixConstraint)1 PrefixConstraint (com.emc.storageos.db.client.constraint.PrefixConstraint)1 URIQueryResultList (com.emc.storageos.db.client.constraint.URIQueryResultList)1 NamedURI (com.emc.storageos.db.client.model.NamedURI)1