Search in sources :

Example 1 with TenantOrgRestRep

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

the class AuthnConfigurationService method createTenantAndProjectForOpenstackTenant.

public void createTenantAndProjectForOpenstackTenant(OSTenant tenant) {
    TenantCreateParam param = prepareTenantMappingForOpenstack(tenant);
    // Create a tenant.
    TenantOrgRestRep tenantOrgRestRep = _tenantsService.createSubTenant(_permissionsHelper.getRootTenant().getId(), param);
    // Create a project.
    ProjectParam projectParam = new ProjectParam(tenant.getName() + CinderConstants.PROJECT_NAME_SUFFIX);
    ProjectElement projectElement = _tenantsService.createProject(tenantOrgRestRep.getId(), projectParam);
    _keystoneUtils.tagProjectWithOpenstackId(projectElement.getId(), tenant.getOsId(), tenantOrgRestRep.getId().toString());
}
Also used : ProjectParam(com.emc.storageos.model.project.ProjectParam) ProjectElement(com.emc.storageos.model.project.ProjectElement) TenantOrgRestRep(com.emc.storageos.model.tenant.TenantOrgRestRep) TenantCreateParam(com.emc.storageos.model.tenant.TenantCreateParam)

Example 2 with TenantOrgRestRep

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

the class ApiTest method createTenant.

private TenantOrgRestRep createTenant(String label, String domain, String attrKey, String attrValue) throws Exception {
    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);
    TenantCreateParam tenantParam = new TenantCreateParam();
    tenantParam.setLabel(label);
    tenantParam.setDescription("description for " + label);
    tenantParam.setUserMappings(new ArrayList<UserMappingParam>());
    UserMappingParam tenant2UserMapping = new UserMappingParam();
    tenant2UserMapping.setDomain(domain);
    UserMappingAttributeParam tenant2Attr = new UserMappingAttributeParam();
    tenant2Attr.setKey(attrKey);
    tenant2Attr.setValues(Collections.singletonList(attrValue));
    tenant2UserMapping.setAttributes(Collections.singletonList(tenant2Attr));
    tenantParam.getUserMappings().add(tenant2UserMapping);
    String subtenant_url = "/tenants/" + rootTenantId + "/subtenants";
    TenantOrgRestRep tenantOrg = rootUser.path(subtenant_url).header(AUTH_TOKEN_HEADER, rootToken).post(TenantOrgRestRep.class, tenantParam);
    return tenantOrg;
}
Also used : UserMappingAttributeParam(com.emc.storageos.model.tenant.UserMappingAttributeParam) UserMappingParam(com.emc.storageos.model.tenant.UserMappingParam) UserInfo(com.emc.storageos.model.user.UserInfo) TenantOrgRestRep(com.emc.storageos.model.tenant.TenantOrgRestRep) TenantCreateParam(com.emc.storageos.model.tenant.TenantCreateParam)

Example 3 with TenantOrgRestRep

use of com.emc.storageos.model.tenant.TenantOrgRestRep 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 4 with TenantOrgRestRep

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

the class DbObjectMapper method map.

public static TenantOrgRestRep map(TenantOrg from) {
    if (from == null) {
        return null;
    }
    TenantOrgRestRep to = new TenantOrgRestRep();
    mapDataObjectFields(from, to);
    if (from.getParentTenant() != null) {
        if (!TenantOrg.isRootTenant(from)) {
            to.setParentTenant(toRelatedResource(ResourceTypeEnum.TENANT, from.getParentTenant().getURI()));
        }
    }
    to.setDescription(from.getDescription());
    if (from.getUserMappings() != null) {
        for (AbstractChangeTrackingSet<String> userMappingSet : from.getUserMappings().values()) {
            for (String existingMapping : userMappingSet) {
                to.getUserMappings().add(BasePermissionsHelper.UserMapping.toParam(BasePermissionsHelper.UserMapping.fromString(existingMapping)));
            }
        }
    }
    if (from.getNamespace() != null && !"null".equals(from.getNamespace())) {
        to.setNamespace(from.getNamespace());
    }
    if (from.getNamespaceStorage() != null) {
        to.setNamespaceStorage(from.getNamespaceStorage());
    }
    return to;
}
Also used : TenantOrgRestRep(com.emc.storageos.model.tenant.TenantOrgRestRep)

Example 5 with TenantOrgRestRep

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

the class VCenters method addNoneTenantOption.

private static void addNoneTenantOption(String id, List<TenantOrgRestRep> vCenterTenantOptions) {
    VcenterRestRep vcenterRestRep = VCenterUtils.getVCenter(uri(id));
    if (vcenterRestRep != null && !vcenterRestRep.getCascadeTenancy()) {
        TenantOrgRestRep noneTenantOption = new TenantOrgRestRep();
        noneTenantOption.setName("None");
        noneTenantOption.setId(NullColumnValueGetter.getNullURI());
        vCenterTenantOptions.add(noneTenantOption);
    }
}
Also used : TenantOrgRestRep(com.emc.storageos.model.tenant.TenantOrgRestRep)

Aggregations

TenantOrgRestRep (com.emc.storageos.model.tenant.TenantOrgRestRep)22 TenantCreateParam (com.emc.storageos.model.tenant.TenantCreateParam)5 URI (java.net.URI)5 ProjectParam (com.emc.storageos.model.project.ProjectParam)4 UserMappingAttributeParam (com.emc.storageos.model.tenant.UserMappingAttributeParam)3 UserMappingParam (com.emc.storageos.model.tenant.UserMappingParam)3 ProjectElement (com.emc.storageos.model.project.ProjectElement)2 TenantResponse (com.emc.storageos.model.tenant.TenantResponse)2 UserInfo (com.emc.storageos.model.user.UserInfo)2 ClientResponse (com.sun.jersey.api.client.ClientResponse)2 UniformInterfaceException (com.sun.jersey.api.client.UniformInterfaceException)2 WebResource (com.sun.jersey.api.client.WebResource)2 ArrayList (java.util.ArrayList)2 JAXBContext (javax.xml.bind.JAXBContext)2 ACLEntry (com.emc.storageos.model.auth.ACLEntry)1 AuthnUpdateParam (com.emc.storageos.model.auth.AuthnUpdateParam)1 RoleAssignmentChanges (com.emc.storageos.model.auth.RoleAssignmentChanges)1 RoleAssignmentEntry (com.emc.storageos.model.auth.RoleAssignmentEntry)1 RoleAssignments (com.emc.storageos.model.auth.RoleAssignments)1 BlockObjectRestRep (com.emc.storageos.model.block.BlockObjectRestRep)1