diff options
author | Boslet, Cory <cory.boslet@att.com> | 2020-08-25 11:41:22 -0400 |
---|---|---|
committer | Benjamin, Max (mb388a) <mb388a@att.com> | 2020-08-25 11:41:23 -0400 |
commit | 578948caaf6517192db9cac56e7ed17c71f35031 (patch) | |
tree | fc11fb923eb2ba01cdb9bdd2f662b5fbe97589ee /adapters/mso-adapter-utils/src/main/java/org/onap | |
parent | 395ebf29b5541bbbe3864f9638973afec95abe05 (diff) |
updates for keystone V3 auth
Added additional support, refactored, fixed issues.
Issue-ID: SO-3200
Signed-off-by: Benjamin, Max (mb388a) <mb388a@att.com>
Change-Id: I7961453598fabd5f68516ad90e20ff848b1a49ba
Diffstat (limited to 'adapters/mso-adapter-utils/src/main/java/org/onap')
4 files changed, 54 insertions, 1 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 59c6becfbd..fa5c57f447 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 @@ -89,4 +89,23 @@ public final class AuthenticationMethodFactory { v3Auth.setScope(scope); return v3Auth; } + + public final com.woorea.openstack.keystone.v3.model.Authentication getAuthenticationForV3( + CloudIdentity cloudIdentity) { + Identity identity = new Identity(); + Password password = new Password(); + User user = new User(); + Domain userDomain = new Domain(); + userDomain.setName(cloudIdentity.getUserDomainName()); + user.setName(cloudIdentity.getMsoId()); + user.setPassword(CryptoUtils.decryptCloudConfigPassword(cloudIdentity.getMsoPass())); + user.setDomain(userDomain); + password.setUser(user); + 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); + return v3Auth; + } } diff --git a/adapters/mso-adapter-utils/src/main/java/org/onap/so/cloud/authentication/KeystoneV3Authentication.java b/adapters/mso-adapter-utils/src/main/java/org/onap/so/cloud/authentication/KeystoneV3Authentication.java index 16906957a7..3564b8f0a7 100644 --- a/adapters/mso-adapter-utils/src/main/java/org/onap/so/cloud/authentication/KeystoneV3Authentication.java +++ b/adapters/mso-adapter-utils/src/main/java/org/onap/so/cloud/authentication/KeystoneV3Authentication.java @@ -107,7 +107,7 @@ public class KeystoneV3Authentication { return policy; } - protected String findEndpointURL(List<Service> serviceCatalog, String type, String region, String facing) { + public String findEndpointURL(List<Service> serviceCatalog, String type, String region, String facing) { for (Service service : serviceCatalog) { if (type.equals(service.getType())) { for (Service.Endpoint endpoint : service.getEndpoints()) { 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 63bc235363..072ab5a8d0 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,15 +21,29 @@ 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 { @@ -57,4 +71,22 @@ 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"); + } + } + } diff --git a/adapters/mso-adapter-utils/src/main/java/org/onap/so/openstack/utils/NovaClient.java b/adapters/mso-adapter-utils/src/main/java/org/onap/so/openstack/utils/NovaClient.java index c5eeb34157..968e7864b3 100644 --- a/adapters/mso-adapter-utils/src/main/java/org/onap/so/openstack/utils/NovaClient.java +++ b/adapters/mso-adapter-utils/src/main/java/org/onap/so/openstack/utils/NovaClient.java @@ -49,4 +49,6 @@ public class NovaClient extends MsoCommonUtils { novaClient.token(keystone.getId()); return novaClient; } + + } |