Search in sources :

Example 16 with CloudIdentity

use of org.onap.so.db.catalog.beans.CloudIdentity in project so by onap.

the class MsoCommonUtils method getKeystoneAuthHolder.

/**
 * Gets the Keystone Authorization
 *
 * @param cloudSite the cloud site
 * @param tenantId the tenant id
 * @return the Neutron client
 * @throws MsoException the mso exception
 */
protected KeystoneAuthHolder getKeystoneAuthHolder(String cloudSiteId, String tenantId, String serviceName) throws MsoException {
    CloudIdentity cloudIdentity = null;
    try {
        CloudSite cloudSite = cloudConfig.getCloudSite(cloudSiteId).orElseThrow(() -> new MsoCloudSiteNotFound(cloudSiteId));
        String cloudId = cloudSite.getId();
        String region = cloudSite.getRegionId();
        cloudIdentity = cloudSite.getIdentityService();
        MsoTenantUtils tenantUtils = tenantUtilsFactory.getTenantUtilsByServerType(cloudIdentity.getIdentityServerType());
        String keystoneUrl = tenantUtils.getKeystoneUrl(cloudId, cloudIdentity);
        if (ServerType.KEYSTONE.equals(cloudIdentity.getIdentityServerType())) {
            Access access = getKeystone(tenantId, cloudIdentity, keystoneUrl);
            try {
                KeystoneAuthHolder keystoneAuthV2 = new KeystoneAuthHolder();
                keystoneAuthV2.setServiceUrl(KeystoneUtils.findEndpointURL(access.getServiceCatalog(), serviceName, region, "public"));
                keystoneAuthV2.setId(access.getToken().getId());
                return keystoneAuthV2;
            } catch (RuntimeException e) {
                String error = "Openstack did not match an orchestration service for: region=" + region + ",cloud=" + cloudIdentity.getIdentityUrl();
                throw new MsoAdapterException(error, e);
            }
        } else if (ServerType.KEYSTONE_V3.equals(cloudIdentity.getIdentityServerType())) {
            try {
                return keystoneV3Authentication.getToken(cloudSite, tenantId, serviceName);
            } catch (ServiceEndpointNotFoundException e) {
                String error = "cloud did not match an orchestration service for: region=" + region + ",cloud=" + cloudIdentity.getIdentityUrl();
                throw new MsoAdapterException(error, e);
            }
        } else {
            throw new MsoAdapterException("Unknown Keystone Server Type");
        }
    } catch (OpenStackResponseException e) {
        if (e.getStatus() == 401) {
            String error = "Authentication Failure: tenant=" + tenantId + ",cloud=" + cloudIdentity.getId();
            throw new MsoAdapterException(error);
        } else {
            throw keystoneErrorToMsoException(e, TOKEN_AUTH);
        }
    } catch (OpenStackConnectException e) {
        MsoIOException me = new MsoIOException(e.getMessage(), e);
        me.addContext(TOKEN_AUTH);
        throw me;
    } catch (RuntimeException e) {
        throw runtimeExceptionToMsoException(e, TOKEN_AUTH);
    }
}
Also used : MsoCloudSiteNotFound(org.onap.so.openstack.exceptions.MsoCloudSiteNotFound) CloudIdentity(org.onap.so.db.catalog.beans.CloudIdentity) Access(com.woorea.openstack.keystone.model.Access) KeystoneAuthHolder(org.onap.so.cloud.authentication.KeystoneAuthHolder) MsoAdapterException(org.onap.so.openstack.exceptions.MsoAdapterException) ServiceEndpointNotFoundException(org.onap.so.cloud.authentication.ServiceEndpointNotFoundException) OpenStackResponseException(com.woorea.openstack.base.client.OpenStackResponseException) CloudSite(org.onap.so.db.catalog.beans.CloudSite) MsoIOException(org.onap.so.openstack.exceptions.MsoIOException) OpenStackConnectException(com.woorea.openstack.base.client.OpenStackConnectException)

Example 17 with CloudIdentity

use of org.onap.so.db.catalog.beans.CloudIdentity in project so by onap.

the class AuthenticationMethodFactory method getAuthenticationForV3.

public final com.woorea.openstack.keystone.v3.model.Authentication getAuthenticationForV3(CloudIdentity cloudIdentity, String tenantId) {
    Identity identity = new Identity();
    Password password = new Password();
    User user = new User();
    Domain userDomain = new Domain();
    Scope scope = new Scope();
    Project project = new Project();
    Project.Domain projectDomain = new Project.Domain();
    userDomain.setName(cloudIdentity.getUserDomainName());
    projectDomain.setName(cloudIdentity.getProjectDomainName());
    user.setName(cloudIdentity.getMsoId());
    user.setPassword(CryptoUtils.decryptCloudConfigPassword(cloudIdentity.getMsoPass()));
    user.setDomain(userDomain);
    password.setUser(user);
    project.setDomain(projectDomain);
    project.setId(tenantId);
    scope.setProject(project);
    identity.setPassword(password);
    identity.setMethods(Collections.singletonList("password"));
    com.woorea.openstack.keystone.v3.model.Authentication v3Auth = new com.woorea.openstack.keystone.v3.model.Authentication();
    v3Auth.setIdentity(identity);
    v3Auth.setScope(scope);
    return v3Auth;
}
Also used : User(com.woorea.openstack.keystone.v3.model.Authentication.Identity.Password.User) Project(com.woorea.openstack.keystone.v3.model.Authentication.Scope.Project) Scope(com.woorea.openstack.keystone.v3.model.Authentication.Scope) RackspaceAuthentication(org.onap.so.cloud.authentication.models.RackspaceAuthentication) Authentication(com.woorea.openstack.keystone.model.Authentication) CloudIdentity(org.onap.so.db.catalog.beans.CloudIdentity) Identity(com.woorea.openstack.keystone.v3.model.Authentication.Identity) Domain(com.woorea.openstack.keystone.v3.model.Authentication.Identity.Password.User.Domain) UsernamePassword(com.woorea.openstack.keystone.model.authentication.UsernamePassword) Password(com.woorea.openstack.keystone.v3.model.Authentication.Identity.Password)

Example 18 with CloudIdentity

use of org.onap.so.db.catalog.beans.CloudIdentity in project so by onap.

the class KeystoneV3Authentication method getToken.

public KeystoneAuthHolder getToken(CloudSite cloudSite, String tenantId, String type) throws MsoException {
    String cloudId = cloudSite.getId();
    String region = cloudSite.getRegionId();
    CloudIdentity cloudIdentity = cloudSite.getIdentityService();
    MsoTenantUtils tenantUtils = tenantUtilsFactory.getTenantUtilsByServerType(cloudIdentity.getIdentityServerType());
    String keystoneUrl = tenantUtils.getKeystoneUrl(cloudId, cloudIdentity);
    Keystone keystoneTenantClient = new Keystone(keystoneUrl);
    Authentication v3Credentials = authenticationMethodFactory.getAuthenticationForV3(cloudIdentity, tenantId);
    OpenStackRequest<Token> v3Request = keystoneTenantClient.tokens().authenticate(v3Credentials);
    return makeRequest(v3Request, type, region);
}
Also used : Keystone(com.woorea.openstack.keystone.v3.Keystone) Authentication(com.woorea.openstack.keystone.v3.model.Authentication) CloudIdentity(org.onap.so.db.catalog.beans.CloudIdentity) MsoTenantUtils(org.onap.so.openstack.utils.MsoTenantUtils) Token(com.woorea.openstack.keystone.v3.model.Token)

Example 19 with CloudIdentity

use of org.onap.so.db.catalog.beans.CloudIdentity in project so by onap.

the class CloudSiteCatalogUtilsTest method testGetIdentityUrlFromCloudSiteNoCloudIdProvidedTest.

@Test
public void testGetIdentityUrlFromCloudSiteNoCloudIdProvidedTest() throws Exception {
    CloudSite cloudSite = new CloudSite();
    String testCloudSiteId = "testCloudSiteId";
    String testIdentityUrl = "testIdentityUrl";
    cloudSite.setClli(testCloudSiteId);
    CloudIdentity cloudIdentity = new CloudIdentity();
    cloudIdentity.setIdentityUrl(testIdentityUrl);
    cloudSite.setIdentityService(cloudIdentity);
    doReturn(cloudSite).when(catalogDbClient).getCloudSite(testCloudSiteId);
    cloudSiteCatalogUtils.getIdentityUrlFromCloudSite(delegateExecution);
    String actualIdentityUrl = (String) delegateExecution.getVariable("identityUrl");
    assertEquals(null, actualIdentityUrl);
}
Also used : CloudSite(org.onap.so.db.catalog.beans.CloudSite) CloudIdentity(org.onap.so.db.catalog.beans.CloudIdentity) BaseTaskTest(org.onap.so.bpmn.BaseTaskTest) Test(org.junit.Test)

Example 20 with CloudIdentity

use of org.onap.so.db.catalog.beans.CloudIdentity in project so by onap.

the class CloudSiteCatalogUtilsTest method testGetIdentityUrlFromCloudSiteSuccessTest.

@Test
public void testGetIdentityUrlFromCloudSiteSuccessTest() throws Exception {
    CloudSite cloudSite = new CloudSite();
    String testCloudSiteId = "testCloudSiteId";
    String testIdentityUrl = "testIdentityUrl";
    delegateExecution.setVariable("lcpCloudRegionId", testCloudSiteId);
    cloudSite.setClli(testCloudSiteId);
    CloudIdentity cloudIdentity = new CloudIdentity();
    cloudIdentity.setIdentityUrl(testIdentityUrl);
    cloudSite.setIdentityService(cloudIdentity);
    doReturn(cloudSite).when(catalogDbClient).getCloudSite(testCloudSiteId);
    cloudSiteCatalogUtils.getIdentityUrlFromCloudSite(delegateExecution);
    String actualIdentityUrl = (String) delegateExecution.getVariable("identityUrl");
    assertEquals(testIdentityUrl, actualIdentityUrl);
}
Also used : CloudSite(org.onap.so.db.catalog.beans.CloudSite) CloudIdentity(org.onap.so.db.catalog.beans.CloudIdentity) BaseTaskTest(org.onap.so.bpmn.BaseTaskTest) Test(org.junit.Test)

Aggregations

CloudIdentity (org.onap.so.db.catalog.beans.CloudIdentity)26 Test (org.junit.Test)13 CloudSite (org.onap.so.db.catalog.beans.CloudSite)12 Authentication (com.woorea.openstack.keystone.model.Authentication)8 RackspaceAuthentication (org.onap.so.cloud.authentication.models.RackspaceAuthentication)6 OpenStackConnectException (com.woorea.openstack.base.client.OpenStackConnectException)4 OpenStackResponseException (com.woorea.openstack.base.client.OpenStackResponseException)4 UsernamePassword (com.woorea.openstack.keystone.model.authentication.UsernamePassword)4 MsoAdapterException (org.onap.so.openstack.exceptions.MsoAdapterException)4 MsoCloudSiteNotFound (org.onap.so.openstack.exceptions.MsoCloudSiteNotFound)4 Keystone (com.woorea.openstack.keystone.Keystone)3 Access (com.woorea.openstack.keystone.model.Access)3 MsoException (org.onap.so.openstack.exceptions.MsoException)3 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)2 Identity (com.woorea.openstack.keystone.v3.model.Authentication.Identity)2 Password (com.woorea.openstack.keystone.v3.model.Authentication.Identity.Password)2 User (com.woorea.openstack.keystone.v3.model.Authentication.Identity.Password.User)2 Domain (com.woorea.openstack.keystone.v3.model.Authentication.Identity.Password.User.Domain)2 Scope (com.woorea.openstack.keystone.v3.model.Authentication.Scope)2 Project (com.woorea.openstack.keystone.v3.model.Authentication.Scope.Project)2