Search in sources :

Example 1 with TenantListRestResp

use of com.emc.storageos.keystone.restapi.model.response.TenantListRestResp in project coprhd-controller by CoprHD.

the class KeystoneService method listOpenstackTenants.

/**
 * Get a list of OpenStack Tenants.
 * Uses data from Keystone Authentication Provider to connect Keystone and retrieve Tenants information.
 *
 * @brief Show OpenStack Tenants.
 * @return OpenStack Tenants details.
 * @see TenantListRestResp
 */
@GET
@Path("/tenants")
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@CheckPermission(roles = { Role.SECURITY_ADMIN })
public TenantListRestResp listOpenstackTenants() {
    _log.debug("Keystone Service - listOpenstackTenants");
    StorageOSUser user = getUserFromContext();
    if (!_permissionsHelper.userHasGivenRoleInAnyTenant(user, Role.SECURITY_ADMIN, Role.TENANT_ADMIN)) {
        throw APIException.forbidden.insufficientPermissionsForUser(user.getName());
    }
    AuthnProvider keystoneProvider = _keystoneUtils.getKeystoneProvider();
    // Get OpenStack Tenants only when Keystone Provider exists.
    if (keystoneProvider != null) {
        KeystoneApiClient keystoneApiClient = _keystoneUtils.getKeystoneApi(keystoneProvider.getManagerDN(), keystoneProvider.getServerUrls(), keystoneProvider.getManagerPassword());
        List<KeystoneTenant> OSTenantList = new ArrayList<>(Arrays.asList(keystoneApiClient.getKeystoneTenants().getTenants()));
        TenantListRestResp response = new TenantListRestResp();
        response.setOpenstackTenants(OSTenantList);
        return response;
    }
    throw APIException.internalServerErrors.targetIsNullOrEmpty("Keystone Authentication Provider");
}
Also used : KeystoneTenant(com.emc.storageos.keystone.restapi.model.response.KeystoneTenant) StorageOSUser(com.emc.storageos.security.authentication.StorageOSUser) ArrayList(java.util.ArrayList) KeystoneApiClient(com.emc.storageos.keystone.restapi.KeystoneApiClient) TenantListRestResp(com.emc.storageos.keystone.restapi.model.response.TenantListRestResp) CheckPermission(com.emc.storageos.security.authorization.CheckPermission)

Aggregations

KeystoneApiClient (com.emc.storageos.keystone.restapi.KeystoneApiClient)1 KeystoneTenant (com.emc.storageos.keystone.restapi.model.response.KeystoneTenant)1 TenantListRestResp (com.emc.storageos.keystone.restapi.model.response.TenantListRestResp)1 StorageOSUser (com.emc.storageos.security.authentication.StorageOSUser)1 CheckPermission (com.emc.storageos.security.authorization.CheckPermission)1 ArrayList (java.util.ArrayList)1