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