use of com.emc.storageos.model.auth.AuthnProviderList in project coprhd-controller by CoprHD.
the class AuthnConfigurationService method listProviders.
/**
* List authentication providers in the zone.
*
* @brief List authentication providers
* @return List of authentication providers
*/
@GET
// no id, just "/"
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
public AuthnProviderList listProviders() {
// TODO: if you need to copy/paste this code, please modify the AbstractPermissionFilter class instead and
// related CheckPermission annotation code to support "TENANT_ADMIN_IN_ANY_TENANT" permission.
StorageOSUser user = getUserFromContext();
if (!_permissionsHelper.userHasGivenRoleInAnyTenant(user, Role.SECURITY_ADMIN, Role.TENANT_ADMIN)) {
throw APIException.forbidden.insufficientPermissionsForUser(user.getName());
}
NamedElementQueryResultList providers = new NamedElementQueryResultList();
List<URI> uris = _dbClient.queryByType(AuthnProvider.class, true);
List<AuthnProvider> configs = _dbClient.queryObject(AuthnProvider.class, uris);
List<NamedElementQueryResultList.NamedElement> elements = new ArrayList<NamedElementQueryResultList.NamedElement>(configs.size());
for (AuthnProvider p : configs) {
elements.add(NamedElementQueryResultList.NamedElement.createElement(p.getId(), p.getLabel()));
}
providers.setResult(elements.iterator());
AuthnProviderList list = new AuthnProviderList();
list.getProviders().addAll(map(ResourceTypeEnum.AUTHN_PROVIDER, providers));
return list;
}
use of com.emc.storageos.model.auth.AuthnProviderList in project coprhd-controller by CoprHD.
the class ApiTest method adConfigListTests.
private void adConfigListTests() {
AuthnProviderList resp = rSys.path("/vdc/admin/authnproviders").get(AuthnProviderList.class);
int sz = resp.getProviders().size();
// Add one more, then one with no name field. The new total should be sz + 2.
AuthnCreateParam param = new AuthnCreateParam();
param.setLabel("ad apitest config one");
param.setDescription("ad configuration created by ApiTest.java");
param.setDisable(false);
param.getDomains().add("sanity3.local");
param.setGroupAttribute("CN");
param.setGroupWhitelistValues(new HashSet<String>());
param.getGroupWhitelistValues().add("*Admins*");
param.getGroupWhitelistValues().add("*Test*");
param.getGroupWhitelistValues().add("*Users*");
param.setManagerDn("CN=Administrator,CN=Users,DC=sanity,DC=local");
param.setManagerPassword(AD_PASS_WORD);
param.setSearchBase("CN=Users,DC=sanity,DC=local");
param.setSearchFilter("userPrincipalName=%u");
param.setServerUrls(new HashSet<String>());
param.getServerUrls().add("ldap:\\" + AD_SERVER1_IP);
param.getServerUrls().add("ldap:\\" + AD_SERVER1_HOST);
param.setMode("ad");
ClientResponse resp2 = rSys.path("/vdc/admin/authnproviders").post(ClientResponse.class, param);
Assert.assertEquals(200, resp2.getStatus());
param.setLabel("ad apitest config two");
param.getDomains().remove("sanity3.local");
param.getDomains().add("another.com");
AuthnProviderRestRep authnResp = rSys.path("/vdc/admin/authnproviders").post(AuthnProviderRestRep.class, param);
Assert.assertNotNull(authnResp);
resp = rSys.path("/vdc/admin/authnproviders").get(AuthnProviderList.class);
int sz2 = resp.getProviders().size();
Assert.assertEquals(sz2, sz + 2);
// update test
AuthnUpdateParam updateParam = new AuthnUpdateParam();
updateParam.setLabel("ad apitest config two");
updateParam.getDomainChanges().setRemove(new HashSet<String>());
updateParam.getDomainChanges().getRemove().add("another.com");
updateParam.getGroupWhitelistValueChanges().setRemove(new HashSet<String>());
updateParam.getGroupWhitelistValueChanges().getRemove().add("*Admins*");
updateParam.getGroupWhitelistValueChanges().getRemove().add("*Test*");
updateParam.getGroupWhitelistValueChanges().getRemove().add("*Users*");
updateParam.getServerUrlChanges().setRemove(new HashSet<String>());
updateParam.getServerUrlChanges().getRemove().add("ldap:\\" + AD_SERVER1_HOST);
AuthnProviderRestRep authnResp2 = rSys.path("/vdc/admin/authnproviders/" + authnResp.getId().toString() + "/").put(AuthnProviderRestRep.class, updateParam);
Assert.assertNotNull(authnResp2);
Assert.assertEquals(0, authnResp2.getDomains().size());
Assert.assertEquals(0, authnResp2.getGroupWhitelistValues().size());
Assert.assertEquals(1, authnResp2.getServerUrls().size());
}
Aggregations