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());
}
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();
}
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());
}
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();
}
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");
}
Aggregations