Search in sources :

Example 1 with UserMappingParam

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

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

the class ApiTestBase method updateRootTenantAttrs.

/**
 * Update tenant attributes for the root tenant
 */
protected void updateRootTenantAttrs() {
    TenantResponse tenantResp = rSys.path("/tenant").get(TenantResponse.class);
    rootTenantId = tenantResp.getTenant();
    /*
         * PUT the ou=sanity attribute mapping into the root tenant attributes
         */
    TenantUpdateParam tenantUpdate = new TenantUpdateParam();
    tenantUpdate.setUserMappingChanges(new UserMappingChanges());
    tenantUpdate.getUserMappingChanges().setAdd(new ArrayList<UserMappingParam>());
    UserMappingParam rootMapping = new UserMappingParam();
    rootMapping.setDomain("SANITY.local");
    UserMappingAttributeParam rootAttr = new UserMappingAttributeParam();
    rootAttr.setKey("ou");
    rootAttr.setValues(Collections.singletonList(ROOTTENANT_ATTR));
    rootMapping.setAttributes(Collections.singletonList(rootAttr));
    tenantUpdate.getUserMappingChanges().getAdd().add(rootMapping);
    // TODO: FIX: not sure why name is required for update
    tenantUpdate.setLabel(ROOTTENANT_NAME);
    ClientResponse resp = rSys.path("/tenants/" + rootTenantId.toString()).put(ClientResponse.class, tenantUpdate);
    Assert.assertEquals(200, resp.getStatus());
}
Also used : ClientResponse(com.sun.jersey.api.client.ClientResponse) UserMappingAttributeParam(com.emc.storageos.model.tenant.UserMappingAttributeParam) UserMappingChanges(com.emc.storageos.model.tenant.UserMappingChanges) UserMappingParam(com.emc.storageos.model.tenant.UserMappingParam) TenantResponse(com.emc.storageos.model.tenant.TenantResponse) TenantUpdateParam(com.emc.storageos.model.tenant.TenantUpdateParam)

Example 3 with UserMappingParam

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

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

the class UserMappingForm method createUserMappingParam.

public UserMappingParam createUserMappingParam() {
    UserMappingParam userMappingParam = new UserMappingParam();
    userMappingParam.setDomain(domain);
    for (String group : groups.split(LINE_BREAK)) {
        if (!StringUtils.isBlank(group)) {
            userMappingParam.getGroups().add(group.trim());
        }
    }
    List<UserMappingAttributeParam> attributeParams = Lists.newArrayList();
    if (!attributes.isEmpty()) {
        for (AttributeMapping mapping : attributes) {
            if (mapping != null) {
                attributeParams.add(mapping.createAttributeParam());
            }
        }
    }
    userMappingParam.setAttributes(attributeParams);
    return userMappingParam;
}
Also used : UserMappingAttributeParam(com.emc.storageos.model.tenant.UserMappingAttributeParam) UserMappingParam(com.emc.storageos.model.tenant.UserMappingParam)

Example 5 with UserMappingParam

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

the class TenantModificationTest method tenantAdminModifyUserMapping.

@Test
public void tenantAdminModifyUserMapping() throws Exception {
    TenantUpdateParam tenantUpdateParam = new TenantUpdateParam();
    UserMappingChanges changes = new UserMappingChanges();
    List<UserMappingParam> listAdd = new ArrayList<UserMappingParam>();
    UserMappingParam param = new UserMappingParam();
    param.setDomain("Not Exist");
    listAdd.add(param);
    changes.setAdd(listAdd);
    tenantUpdateParam.setUserMappingChanges(changes);
    try {
        tenantAdminClient.tenants().update(rootTenantID, tenantUpdateParam);
        Assert.fail("Tenant admin should has no permission to modify tenant's user mapping");
    } catch (ServiceErrorException see) {
        Assert.assertEquals(see.getCode(), 3000);
        Assert.assertTrue(see.getMessage().contains("Only users with SECURITY_ADMIN role can"));
    }
}
Also used : UserMappingChanges(com.emc.storageos.model.tenant.UserMappingChanges) UserMappingParam(com.emc.storageos.model.tenant.UserMappingParam) ArrayList(java.util.ArrayList) ServiceErrorException(com.emc.vipr.client.exceptions.ServiceErrorException) TenantUpdateParam(com.emc.storageos.model.tenant.TenantUpdateParam) Test(org.junit.Test)

Aggregations

UserMappingParam (com.emc.storageos.model.tenant.UserMappingParam)16 UserMappingAttributeParam (com.emc.storageos.model.tenant.UserMappingAttributeParam)9 TenantCreateParam (com.emc.storageos.model.tenant.TenantCreateParam)5 TenantUpdateParam (com.emc.storageos.model.tenant.TenantUpdateParam)4 UserMappingChanges (com.emc.storageos.model.tenant.UserMappingChanges)4 ArrayList (java.util.ArrayList)4 TenantOrgRestRep (com.emc.storageos.model.tenant.TenantOrgRestRep)3 TenantResponse (com.emc.storageos.model.tenant.TenantResponse)3 ClientResponse (com.sun.jersey.api.client.ClientResponse)3 Test (org.junit.Test)3 AuthnUpdateParam (com.emc.storageos.model.auth.AuthnUpdateParam)2 ServiceErrorException (com.emc.vipr.client.exceptions.ServiceErrorException)2 HashSet (java.util.HashSet)2 NamedURI (com.emc.storageos.db.client.model.NamedURI)1 TenantOrg (com.emc.storageos.db.client.model.TenantOrg)1 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