diff options
Diffstat (limited to 'adapters/mso-adapter-utils')
3 files changed, 22 insertions, 44 deletions
diff --git a/adapters/mso-adapter-utils/src/main/java/org/onap/so/cloud/authentication/AuthenticationMethodFactory.java b/adapters/mso-adapter-utils/src/main/java/org/onap/so/cloud/authentication/AuthenticationMethodFactory.java index fa5c57f447..ab0239057a 100644 --- a/adapters/mso-adapter-utils/src/main/java/org/onap/so/cloud/authentication/AuthenticationMethodFactory.java +++ b/adapters/mso-adapter-utils/src/main/java/org/onap/so/cloud/authentication/AuthenticationMethodFactory.java @@ -90,22 +90,31 @@ public final class AuthenticationMethodFactory { return v3Auth; } - public final com.woorea.openstack.keystone.v3.model.Authentication getAuthenticationForV3( - CloudIdentity cloudIdentity) { + public final com.woorea.openstack.keystone.v3.model.Authentication getAuthenticationForV3ByName( + CloudIdentity cloudIdentity, String name) { 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.setName(name); + 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; } + } diff --git a/adapters/mso-adapter-utils/src/main/java/org/onap/so/openstack/utils/MsoCommonUtils.java b/adapters/mso-adapter-utils/src/main/java/org/onap/so/openstack/utils/MsoCommonUtils.java index 50ebcc66ee..6800428a62 100644 --- a/adapters/mso-adapter-utils/src/main/java/org/onap/so/openstack/utils/MsoCommonUtils.java +++ b/adapters/mso-adapter-utils/src/main/java/org/onap/so/openstack/utils/MsoCommonUtils.java @@ -97,7 +97,7 @@ public class MsoCommonUtils { * openstack-java-sdk classname of the OpenStackRequest<T> parameter). */ - protected <T> T executeAndRecordOpenstackRequest(OpenStackRequest<T> request) { + public <T> T executeAndRecordOpenstackRequest(OpenStackRequest<T> request) { return executeAndRecordOpenstackRequest(request, true); } @@ -174,7 +174,7 @@ public class MsoCommonUtils { * Convert an Openstack Exception on a Keystone call to an MsoException. This method supports both * OpenstackResponseException and OpenStackConnectException. */ - protected MsoException keystoneErrorToMsoException(OpenStackBaseException e, String context) { + public MsoException keystoneErrorToMsoException(OpenStackBaseException e, String context) { MsoException me = null; if (e instanceof OpenStackResponseException) { @@ -455,15 +455,16 @@ public class MsoCommonUtils { */ protected KeystoneAuthHolder getKeystoneAuthHolder(String cloudSiteId, String tenantId, String serviceName) throws MsoException { - CloudSite cloudSite = - cloudConfig.getCloudSite(cloudSiteId).orElseThrow(() -> new MsoCloudSiteNotFound(cloudSiteId)); - String cloudId = cloudSite.getId(); - String region = cloudSite.getRegionId(); - CloudIdentity cloudIdentity = cloudSite.getIdentityService(); - MsoTenantUtils tenantUtils = - tenantUtilsFactory.getTenantUtilsByServerType(cloudIdentity.getIdentityServerType()); - String keystoneUrl = tenantUtils.getKeystoneUrl(cloudId, cloudIdentity); + 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 { diff --git a/adapters/mso-adapter-utils/src/main/java/org/onap/so/openstack/utils/MsoKeystoneV3Utils.java b/adapters/mso-adapter-utils/src/main/java/org/onap/so/openstack/utils/MsoKeystoneV3Utils.java index 072ab5a8d0..63bc235363 100644 --- a/adapters/mso-adapter-utils/src/main/java/org/onap/so/openstack/utils/MsoKeystoneV3Utils.java +++ b/adapters/mso-adapter-utils/src/main/java/org/onap/so/openstack/utils/MsoKeystoneV3Utils.java @@ -21,29 +21,15 @@ package org.onap.so.openstack.utils; import java.util.Map; -import org.onap.so.cloud.authentication.AuthenticationMethodFactory; import org.onap.so.db.catalog.beans.CloudIdentity; -import org.onap.so.db.catalog.beans.CloudSite; import org.onap.so.openstack.beans.MsoTenant; import org.onap.so.openstack.exceptions.MsoCloudSiteNotFound; import org.onap.so.openstack.exceptions.MsoException; -import org.onap.so.utils.CryptoUtils; -import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; -import com.woorea.openstack.keystone.v3.model.Token; -import com.woorea.openstack.base.client.OpenStackConnectException; -import com.woorea.openstack.base.client.OpenStackResponseException; -import com.woorea.openstack.keystone.v3.Keystone; -import com.woorea.openstack.keystone.v3.api.TokensResource.Authenticate; -import com.woorea.openstack.keystone.v3.model.Authentication; -import com.woorea.openstack.keystone.v3.model.Authentication.Identity; @Component public class MsoKeystoneV3Utils extends MsoTenantUtils { - @Autowired - private AuthenticationMethodFactory authenticationMethodFactory; - @Override public String createTenant(String tenantName, String cloudSiteId, Map<String, String> metadata, boolean backout) throws MsoException { @@ -71,22 +57,4 @@ public class MsoKeystoneV3Utils extends MsoTenantUtils { return cloudIdentity.getIdentityUrl(); } - public Token getKeystoneToken(CloudSite cloudSite) throws MsoException { - try { - CloudIdentity cloudIdentity = cloudSite.getIdentityService(); - - Keystone keystone = new Keystone(cloudIdentity.getIdentityUrl()); - - Authentication auth = authenticationMethodFactory.getAuthenticationForV3(cloudIdentity); - - Authenticate authenticate = keystone.tokens().authenticate(auth); - return executeAndRecordOpenstackRequest(authenticate); - - } catch (OpenStackResponseException e) { - throw keystoneErrorToMsoException(e, "TokenAuth"); - } catch (OpenStackConnectException e) { - throw keystoneErrorToMsoException(e, "TokenAuth"); - } - } - } |