Search in sources :

Example 6 with TenantResponse

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

the class AuthSvcTests method runProxyTokenExpiryTest.

private void runProxyTokenExpiryTest() throws Exception {
    try {
        String timeToWaitInMinsStr = System.getenv("TIME_TO_WAIT_IN_MINUTES_SET_IN_SECURITY_MODULE_XML");
        int timeToWaitInMinutes = Integer.parseInt(timeToWaitInMinsStr);
    } catch (Exception e) {
        timeToWaitInMinutes = 1;
    }
    WebResource rRoot = createHttpsClient(SYSADMIN, SYSADMIN_PASS_WORD, true).resource(baseAuthServiceURL);
    rRoot.path("/login").get(ClientResponse.class);
    // post authProvider
    updateADConfig();
    // login with a user from ldap
    WebResource rSanityUser = createHttpsClient(ROOTUSER, AD_PASS_WORD, true).resource(baseAuthServiceURL);
    rSanityUser.path("/login").get(ClientResponse.class);
    TenantResponse tenant = rSanityUser.path("/tenant").get(TenantResponse.class);
    // make the user a tenant_admin
    RoleAssignmentChanges changes = new RoleAssignmentChanges();
    RoleAssignmentEntry addTenantAdmin = new RoleAssignmentEntry();
    addTenantAdmin.setSubjectId(ROOTUSER);
    addTenantAdmin.getRoles().add("TENANT_ADMIN");
    changes.setAdd(new ArrayList<RoleAssignmentEntry>());
    changes.getAdd().add(addTenantAdmin);
    rRoot.path("/tenants/" + tenant.getTenant() + "/role-assignments").put(changes);
    // create a proxy token for that user
    ClientResponse resp = rSanityUser.path("/proxytoken").get(ClientResponse.class);
    Assert.assertEquals(200, resp.getStatus());
    String proxyToken = (String) _savedProxyTokens.get(ROOTUSER);
    Assert.assertNotNull(proxyToken);
    // logon with proxyuser
    WebResource rProxy = createHttpsClient(PROXY_USER, PROXY_USER_PWD, true).resource(baseApiServiceURL);
    rProxy.path("/login").get(ClientResponse.class);
    // try to get sanity user's tenant as proxy user with proxy token
    // should get a 200
    resp = rProxy.path("/tenants/" + tenant.getTenant()).header(AUTH_PROXY_TOKEN_HEADER, proxyToken).get(ClientResponse.class);
    Assert.assertEquals(200, resp.getStatus());
    // wait x amount of time for token to expire
    Thread.sleep(timeToWaitInMinutes * 60 * 1000);
    // try to get sanity user's tenant as proxy user with proxy token
    // should get a 200 again
    resp = rProxy.path("/tenants/" + tenant.getTenant()).header(AUTH_PROXY_TOKEN_HEADER, proxyToken).get(ClientResponse.class);
    Assert.assertEquals(200, resp.getStatus());
    // do a put on the authprovider so it is disabled
    AuthnUpdateParam updateParam = new AuthnUpdateParam();
    updateParam.setDisable(true);
    rRoot.path("/vdc/admin/authnproviders/" + _goodADConfig).put(updateParam);
    // wait x amount of time for token to expire
    Thread.sleep(timeToWaitInMinutes * 60 * 1000);
    // try to get the tenant with proxy user using the proxy token
    // should fail with a 401
    resp = rProxy.path("/tenants/" + tenant.getTenant()).header(AUTH_PROXY_TOKEN_HEADER, proxyToken).get(ClientResponse.class);
    Assert.assertEquals(401, resp.getStatus());
}
Also used : AuthnUpdateParam(com.emc.storageos.model.auth.AuthnUpdateParam) RoleAssignmentChanges(com.emc.storageos.model.auth.RoleAssignmentChanges) RoleAssignmentEntry(com.emc.storageos.model.auth.RoleAssignmentEntry) TenantResponse(com.emc.storageos.model.tenant.TenantResponse) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException)

Example 7 with TenantResponse

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

the class ComputeVirtualPoolTest method setup.

// private String _rootToken;
// private URI _rootTenantId;
@Before
public void setup() throws Exception {
    System.out.println("-Running setup");
    List<String> urls = new ArrayList<String>();
    urls.add(_apiServer);
    rSys = createHttpsClient(SYSADMIN, SYSADMIN_PASS_WORD, urls);
    TenantResponse tenantResp = rSys.path("/tenant").get(TenantResponse.class);
    // _rootTenantId = tenantResp.getTenant();
    // _rootToken = (String)_savedTokens.get(SYSADMIN);
    updateADConfig();
    updateRootTenantAttrs();
}
Also used : ArrayList(java.util.ArrayList) TenantResponse(com.emc.storageos.model.tenant.TenantResponse) Before(org.junit.Before)

Example 8 with TenantResponse

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

the class TenantService method getTenant.

/**
 * Get ID for caller's tenant.
 * The caller's ID is determined based on their token presented to the system during session initialization.
 * This is useful as a bootstrapping function to determine the ID to use for API calls such as creating a project or listing projects.
 *
 * @prereq none
 * @brief Show id for caller's tenant
 * @return Tenant Identifier
 */
@GET
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
public TenantResponse getTenant() {
    StorageOSUser user = getUserFromContext();
    if (user.getTenantId() != null) {
        final TenantResponse resp = new TenantResponse();
        resp.setTenant(URI.create(user.getTenantId()));
        resp.setName(findTenantOrgName(resp.getTenant()));
        resp.setSelfLink(getSelfLink(resp.getTenant()));
        return resp;
    }
    throw APIException.badRequests.noTenantDefinedForUser(user == null ? "unknown" : user.getName());
}
Also used : StorageOSUser(com.emc.storageos.security.authentication.StorageOSUser) TenantResponse(com.emc.storageos.model.tenant.TenantResponse) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Example 9 with TenantResponse

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

the class GeoTest method createSubTenant.

private void createSubTenant() {
    TenantResponse tenantResp = rSys.path("/tenant").get(TenantResponse.class);
    rootTenantId = tenantResp.getTenant();
    /*
         * CREATE subtenant
         */
    String subtenant_url = "/tenants/" + rootTenantId.toString() + "/subtenants";
    TenantCreateParam tenantParam = new TenantCreateParam();
    String subtenant1_label = "subtenant1";
    tenantParam.setLabel(subtenant1_label);
    tenantParam.setDescription("first subtenant");
    tenantParam.setUserMappings(new ArrayList<UserMappingParam>());
    UserMappingParam tenantMapping = new UserMappingParam();
    tenantMapping = new UserMappingParam();
    tenantMapping.setDomain("sanity.LOCAL");
    // Add an attribute scope to the mapping
    UserMappingAttributeParam tenantAttr = new UserMappingAttributeParam();
    Date now = new Date();
    tenantAttr.setKey("departMent" + now);
    tenantAttr.setValues(Collections.singletonList(SUBTENANT1_ATTR));
    tenantMapping.setAttributes(Collections.singletonList(tenantAttr));
    tenantParam.getUserMappings().add(tenantMapping);
    // Add the mappings
    TenantOrgRestRep subtenant1 = rSys.path(subtenant_url).post(TenantOrgRestRep.class, tenantParam);
    Assert.assertTrue(subtenant1.getName().equals(subtenant1_label));
    Assert.assertEquals(1, subtenant1.getUserMappings().size());
    subtenant1Id = subtenant1.getId();
}
Also used : UserMappingAttributeParam(com.emc.storageos.model.tenant.UserMappingAttributeParam) UserMappingParam(com.emc.storageos.model.tenant.UserMappingParam) TenantOrgRestRep(com.emc.storageos.model.tenant.TenantOrgRestRep) TenantResponse(com.emc.storageos.model.tenant.TenantResponse) TenantCreateParam(com.emc.storageos.model.tenant.TenantCreateParam)

Example 10 with TenantResponse

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

the class RoleChangeTest method setup.

@Before
public void setup() throws Exception {
    initLoadBalancer(true);
    String remoteVDCVIPvar = System.getenv("REMOTE_VDC_VIP");
    if (remoteVDCVIPvar == null || remoteVDCVIPvar.equals("")) {
        Assert.fail("Missing remove VDC vip");
    }
    String remoteVDCTemplate = "https://%1$s:4443";
    remoteVDCVIP = String.format(remoteVDCTemplate, remoteVDCVIPvar);
    rootUser = createHttpsClient(SYSADMIN, SYSADMIN_PASS_WORD, baseUrls);
    superSanity = createHttpsClient(SUPERUSER, AD_PASS_WORD, baseUrls);
    TenantResponse tenantResp = superSanity.path("/tenant").get(TenantResponse.class);
    superSanityToken = (String) _savedTokens.get(SUPERUSER);
    rootTenantId = tenantResp.getTenant();
    rootUser.path("/tenant").get(TenantResponse.class);
    rootToken = (String) _savedTokens.get("root");
}
Also used : TenantResponse(com.emc.storageos.model.tenant.TenantResponse) Before(org.junit.Before)

Aggregations

TenantResponse (com.emc.storageos.model.tenant.TenantResponse)12 ClientResponse (com.sun.jersey.api.client.ClientResponse)6 ArrayList (java.util.ArrayList)5 RoleAssignmentChanges (com.emc.storageos.model.auth.RoleAssignmentChanges)3 UserMappingAttributeParam (com.emc.storageos.model.tenant.UserMappingAttributeParam)3 UserMappingParam (com.emc.storageos.model.tenant.UserMappingParam)3 Before (org.junit.Before)3 AuthnUpdateParam (com.emc.storageos.model.auth.AuthnUpdateParam)2 RoleAssignmentEntry (com.emc.storageos.model.auth.RoleAssignmentEntry)2 ProjectParam (com.emc.storageos.model.project.ProjectParam)2 TenantCreateParam (com.emc.storageos.model.tenant.TenantCreateParam)2 TenantOrgList (com.emc.storageos.model.tenant.TenantOrgList)2 TenantOrgRestRep (com.emc.storageos.model.tenant.TenantOrgRestRep)2 TenantUpdateParam (com.emc.storageos.model.tenant.TenantUpdateParam)2 UserMappingChanges (com.emc.storageos.model.tenant.UserMappingChanges)2 VirtualArrayList (com.emc.storageos.model.varray.VirtualArrayList)2 StorageOSUser (com.emc.storageos.security.authentication.StorageOSUser)2 InternalFileServiceClient (com.emc.storageos.api.service.impl.resource.utils.InternalFileServiceClient)1 InternalNetworkClient (com.emc.storageos.api.service.impl.resource.utils.InternalNetworkClient)1 StringSet (com.emc.storageos.db.client.model.StringSet)1