Search in sources :

Example 11 with CloudIdentity

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

the class AuthenticationMethodTest method testCustomRackspaceAuth.

@Test
public void testCustomRackspaceAuth() {
    CloudIdentity ci = new CloudIdentity();
    ci.setIdentityAuthenticationType(AuthenticationType.RACKSPACE_APIKEY);
    ci.setMsoPass("FD205490A48D48475607C36B9AD902BF");
    ci.setMsoId("test");
    Authentication auth = authenticationMethodFactory.getAuthenticationFor(ci);
    assertTrue(RackspaceAuthentication.class.equals(auth.getClass()));
}
Also used : RackspaceAuthentication(org.onap.so.cloud.authentication.models.RackspaceAuthentication) Authentication(com.woorea.openstack.keystone.model.Authentication) CloudIdentity(org.onap.so.db.catalog.beans.CloudIdentity) RackspaceAuthentication(org.onap.so.cloud.authentication.models.RackspaceAuthentication) Test(org.junit.Test)

Example 12 with CloudIdentity

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

the class AuthenticationMethodTest method getAuthenticationForV3Test.

@Test
public void getAuthenticationForV3Test() throws JsonParseException, JsonMappingException, IOException {
    CloudIdentity identity = new CloudIdentity();
    identity.setMsoId("my-username");
    identity.setMsoPass(CryptoUtils.encryptCloudConfigPassword("my-password"));
    identity.setProjectDomainName("test-domain");
    identity.setUserDomainName("user-domain");
    ObjectMapper mapper = new ObjectMapper();
    com.woorea.openstack.keystone.v3.model.Authentication expected = mapper.readValue(new String(Files.readAllBytes(Paths.get("src/test/resources/__files/KeystoneV3Payload.json"))), com.woorea.openstack.keystone.v3.model.Authentication.class);
    com.woorea.openstack.keystone.v3.model.Authentication actual = authenticationMethodFactory.getAuthenticationForV3(identity, "project-x");
    assertThat(actual, sameBeanAs(expected));
}
Also used : CloudIdentity(org.onap.so.db.catalog.beans.CloudIdentity) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Test(org.junit.Test)

Example 13 with CloudIdentity

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

the class BaseTest method init.

@Before
public void init() throws IOException {
    CloudIdentity identity = getCloudIdentity();
    CloudSite cloudSite = getCloudSite(identity);
    mockCloud(identity, cloudSite);
}
Also used : CloudIdentity(org.onap.so.db.catalog.beans.CloudIdentity) CloudSite(org.onap.so.db.catalog.beans.CloudSite) Before(org.junit.Before)

Example 14 with CloudIdentity

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

the class MsoNeutronUtils method getNeutronClient.

// -------------------------------------------------------------------
// PRIVATE UTILITY FUNCTIONS FOR USE WITHIN THIS CLASS
/**
 * Get a Neutron (Quantum) client for the Openstack Network service. This requires a 'member'-level userId +
 * password, which will be retrieved from properties based on the specified cloud Id. The tenant in which to operate
 * must also be provided.
 * <p>
 * On successful authentication, the Quantum object will be cached for the tenantID + cloudId so that it can be
 * reused without reauthenticating with Openstack every time.
 *
 * @param cloudSite - a cloud site definition
 * @param tenantId - Openstack tenant ID
 * @return an authenticated Quantum object
 */
private Quantum getNeutronClient(CloudSite cloudSite, String tenantId) throws MsoException {
    String cloudId = cloudSite.getId();
    String region = cloudSite.getRegionId();
    // Obtain an MSO token for the tenant from the identity service
    CloudIdentity cloudIdentity = cloudSite.getIdentityService();
    MsoTenantUtils tenantUtils = tenantUtilsFactory.getTenantUtilsByServerType(cloudIdentity.getIdentityServerType());
    final String keystoneUrl = tenantUtils.getKeystoneUrl(cloudId, cloudIdentity);
    String neutronUrl = null;
    String tokenId = null;
    try {
        if (ServerType.KEYSTONE.equals(cloudIdentity.getIdentityServerType())) {
            Keystone keystoneTenantClient = new Keystone(keystoneUrl);
            Access access = null;
            Authentication credentials = authenticationMethodFactory.getAuthenticationFor(cloudIdentity);
            OpenStackRequest<Access> request = keystoneTenantClient.tokens().authenticate(credentials).withTenantId(tenantId);
            access = executeAndRecordOpenstackRequest(request, true);
            try {
                neutronUrl = KeystoneUtils.findEndpointURL(access.getServiceCatalog(), "network", region, "public");
                if (!neutronUrl.endsWith("/")) {
                    neutronUrl += "/v2.0/";
                }
            } catch (RuntimeException e) {
                // This comes back for not found (probably an incorrect region ID)
                String error = "Network service not found: region=" + region + ",cloud=" + cloudIdentity.getId();
                throw new MsoAdapterException(error, e);
            }
            tokenId = access.getToken().getId();
        } else if (ServerType.KEYSTONE_V3.equals(cloudIdentity.getIdentityServerType())) {
            try {
                KeystoneAuthHolder holder = keystoneV3Authentication.getToken(cloudSite, tenantId, "network");
                tokenId = holder.getId();
                neutronUrl = holder.getServiceUrl();
                if (!neutronUrl.endsWith("/")) {
                    neutronUrl += "/v2.0/";
                }
            } catch (ServiceEndpointNotFoundException e) {
                // This comes back for not found (probably an incorrect region ID)
                String error = "Network service not found: region=" + region + ",cloud=" + cloudIdentity.getId();
                throw new MsoAdapterException(error, e);
            }
        }
    } catch (OpenStackResponseException e) {
        if (e.getStatus() == 401) {
            // Authentication error.
            String error = "Authentication Failure: tenant=" + tenantId + ",cloud=" + cloudIdentity.getId();
            throw new MsoAdapterException(error);
        } else {
            MsoException me = keystoneErrorToMsoException(e, "TokenAuth");
            throw me;
        }
    } catch (OpenStackConnectException e) {
        // Connection to Openstack failed
        MsoIOException me = new MsoIOException(e.getMessage(), e);
        me.addContext("TokenAuth");
        throw me;
    } catch (RuntimeException e) {
        // Catch-all
        MsoException me = runtimeExceptionToMsoException(e, "TokenAuth");
        throw me;
    }
    Quantum neutronClient = new Quantum(neutronUrl);
    neutronClient.token(tokenId);
    return neutronClient;
}
Also used : MsoException(org.onap.so.openstack.exceptions.MsoException) CloudIdentity(org.onap.so.db.catalog.beans.CloudIdentity) Access(com.woorea.openstack.keystone.model.Access) KeystoneAuthHolder(org.onap.so.cloud.authentication.KeystoneAuthHolder) Quantum(com.woorea.openstack.quantum.Quantum) MsoAdapterException(org.onap.so.openstack.exceptions.MsoAdapterException) ServiceEndpointNotFoundException(org.onap.so.cloud.authentication.ServiceEndpointNotFoundException) Keystone(com.woorea.openstack.keystone.Keystone) OpenStackResponseException(com.woorea.openstack.base.client.OpenStackResponseException) KeystoneV3Authentication(org.onap.so.cloud.authentication.KeystoneV3Authentication) Authentication(com.woorea.openstack.keystone.model.Authentication) MsoIOException(org.onap.so.openstack.exceptions.MsoIOException) OpenStackConnectException(com.woorea.openstack.base.client.OpenStackConnectException)

Example 15 with CloudIdentity

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

the class BaseRestTestUtils method setUp.

/**
 * Before each test execution, updating IdentityUrl port value to the ramdom wireMockPort Since URL will be used as
 * a rest call and required to be mocked in unit tests
 */
@Before
public void setUp() throws Exception {
    wireMockServer.resetAll();
    mapper = new ObjectMapper();
    CloudIdentity identity = new CloudIdentity();
    identity.setId("DEFAULT");
    identity.setMsoId("m93945");
    identity.setMsoPass("89C9F27833AC49FE4164F3608CADE7BCF40357977607A7E4B899F9A046C0071C75F7347A47308EF9FB6620214264B1");
    identity.setAdminTenant("admin");
    identity.setMemberRole("admin");
    identity.setTenantMetadata(new Boolean(true));
    identity.setIdentityUrl("http://localhost:" + wireMockPort + cloudEndpoint);
    identity.setIdentityAuthenticationType(AuthenticationType.USERNAME_PASSWORD);
    CloudSite cloudSite = new CloudSite();
    cloudSite.setId("MTN13");
    cloudSite.setCloudVersion("3.0");
    cloudSite.setClli("MDT13");
    cloudSite.setRegionId("mtn13");
    cloudSite.setOrchestrator(orchestrator);
    identity.setIdentityServerType(ServerType.KEYSTONE);
    cloudSite.setIdentityService(identity);
    wireMockServer.stubFor(get(urlPathEqualTo("/cloudSite/DEFAULT")).willReturn(aResponse().withBody(getBody(mapper.writeValueAsString(cloudSite), wireMockPort, "")).withHeader(org.apache.http.HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON).withStatus(HttpStatus.SC_OK)));
}
Also used : CloudIdentity(org.onap.so.db.catalog.beans.CloudIdentity) CloudSite(org.onap.so.db.catalog.beans.CloudSite) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Before(org.junit.Before)

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