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