Search in sources :

Example 1 with TenantCreateParam

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

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

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

the class ApiTest method authnProviderAddDomainTest.

// quick test to see if the added domain of AP server is converted to all lowercase
public void authnProviderAddDomainTest() throws Exception {
    AuthnCreateParam param = new AuthnCreateParam();
    param.setLabel("domain test AP server");
    param.setDescription("AP server configuration created by ApiTest.java");
    param.setDisable(false);
    param.getDomains().add("asd.locl");
    param.setManagerDn("CN=Manager,DC=root,DC=com");
    param.setManagerPassword("secret");
    param.setSearchBase("OU=People,DC=root,DC=com");
    param.setSearchFilter("mail=%u");
    param.setServerUrls(new HashSet<String>());
    param.getServerUrls().add("ldaps:\\" + LDAP_SERVER1_IP);
    param.setMode("ldap");
    AuthnProviderRestRep resp = rSys.path("/vdc/admin/authnproviders").post(AuthnProviderRestRep.class, param);
    Assert.assertNotNull(resp);
    // update the AP server by adding a domain name with mixed case
    AuthnUpdateParam updateParam = new AuthnUpdateParam();
    Set<String> toAddSet = new HashSet<String>();
    toAddSet.add("sAnItY2.local");
    updateParam.getDomainChanges().setAdd(toAddSet);
    ClientResponse response = rSys.path("/vdc/admin/authnproviders/" + resp.getId()).put(ClientResponse.class, updateParam);
    Assert.assertEquals(200, response.getStatus());
    // verify the added domain name is converted to lower case
    response = rSys.path("/vdc/admin/authnproviders/" + resp.getId()).get(ClientResponse.class);
    AuthnProviderRestRep responseRestRep = response.getEntity(AuthnProviderRestRep.class);
    Assert.assertFalse(responseRestRep.getDomains().contains("sAnItY2.local"));
    Assert.assertTrue(responseRestRep.getDomains().contains("sanity2.local"));
    // use the added domain to create a subtenant, verify it's successful
    TenantCreateParam tenantParam = new TenantCreateParam();
    tenantParam.setLabel("sub2");
    tenantParam.setDescription("My sub tenant 2");
    UserMappingParam tenantMapping1 = new UserMappingParam();
    tenantMapping1.setDomain("sAnItY2.local");
    UserMappingAttributeParam attriParam = new UserMappingAttributeParam("department", Collections.singletonList("ASD"));
    tenantMapping1.getAttributes().add(attriParam);
    tenantParam.getUserMappings().add(tenantMapping1);
    response = rSys.path("/tenants/" + rootTenantId + "/subtenants").post(ClientResponse.class, tenantParam);
    Assert.assertEquals(200, response.getStatus());
}
Also used : ClientResponse(com.sun.jersey.api.client.ClientResponse) AuthnUpdateParam(com.emc.storageos.model.auth.AuthnUpdateParam) UserMappingAttributeParam(com.emc.storageos.model.tenant.UserMappingAttributeParam) UserMappingParam(com.emc.storageos.model.tenant.UserMappingParam) AuthnCreateParam(com.emc.storageos.model.auth.AuthnCreateParam) AuthnProviderRestRep(com.emc.storageos.model.auth.AuthnProviderRestRep) HashSet(java.util.HashSet) TenantCreateParam(com.emc.storageos.model.tenant.TenantCreateParam)

Example 4 with TenantCreateParam

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

the class KeystoneUtilsTest method testPrepareTenantParam.

@Test
public void testPrepareTenantParam() {
    String expectedTenantName = CinderConstants.TENANT_NAME_PREFIX + " " + TENANT_NAME;
    TenantCreateParam param = new TenantCreateParam(expectedTenantName, userMappings);
    KeystoneUtils spyKeystoneUtils = spy(_keystoneUtils);
    doReturn(userMappings).when(spyKeystoneUtils).prepareUserMappings(TENANT_OS_ID);
    doReturn(TENANT_DESCRIPTION).when(spyKeystoneUtils).getProperTenantDescription(TENANT_DESCRIPTION);
    TenantCreateParam createdParams = spyKeystoneUtils.prepareTenantParam(keystoneTenant);
    assertEquals(param.getUserMappings(), createdParams.getUserMappings());
    assertEquals(TENANT_DESCRIPTION, createdParams.getDescription());
    assertEquals(param.getLabel(), createdParams.getLabel());
}
Also used : KeystoneUtils(com.emc.storageos.keystone.restapi.utils.KeystoneUtils) TenantCreateParam(com.emc.storageos.model.tenant.TenantCreateParam) Test(org.junit.Test)

Example 5 with TenantCreateParam

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

the class KeystoneUtils method prepareTenantParam.

/**
 * Prepares TenantCreateParam class filled with information from given Tenant.
 *
 * @param tenant OpenStack Tenant.
 * @return TenantCreateParam.
 */
public TenantCreateParam prepareTenantParam(KeystoneTenant tenant) {
    TenantCreateParam param = new TenantCreateParam(CinderConstants.TENANT_NAME_PREFIX + " " + tenant.getName(), prepareUserMappings(tenant.getId()));
    param.setDescription(getProperTenantDescription(tenant.getDescription()));
    return param;
}
Also used : TenantCreateParam(com.emc.storageos.model.tenant.TenantCreateParam)

Aggregations

TenantCreateParam (com.emc.storageos.model.tenant.TenantCreateParam)10 TenantOrgRestRep (com.emc.storageos.model.tenant.TenantOrgRestRep)5 UserMappingParam (com.emc.storageos.model.tenant.UserMappingParam)5 UserMappingAttributeParam (com.emc.storageos.model.tenant.UserMappingAttributeParam)4 AuthnUpdateParam (com.emc.storageos.model.auth.AuthnUpdateParam)2 ProjectParam (com.emc.storageos.model.project.ProjectParam)2 TenantResponse (com.emc.storageos.model.tenant.TenantResponse)2 ClientResponse (com.sun.jersey.api.client.ClientResponse)2 Test (org.junit.Test)2 KeystoneUtils (com.emc.storageos.keystone.restapi.utils.KeystoneUtils)1 AuthnCreateParam (com.emc.storageos.model.auth.AuthnCreateParam)1 AuthnProviderRestRep (com.emc.storageos.model.auth.AuthnProviderRestRep)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 ProjectElement (com.emc.storageos.model.project.ProjectElement)1 TenantOrgList (com.emc.storageos.model.tenant.TenantOrgList)1 TenantUpdateParam (com.emc.storageos.model.tenant.TenantUpdateParam)1 UserMappingChanges (com.emc.storageos.model.tenant.UserMappingChanges)1 UserInfo (com.emc.storageos.model.user.UserInfo)1