aboutsummaryrefslogtreecommitdiffstats
path: root/adapters/mso-adapter-utils/src/main/java/org/openecomp/mso/cloud
diff options
context:
space:
mode:
authorxg353y <xg353y@intl.att.com>2017-04-11 13:30:42 +0200
committerxg353y <xg353y@intl.att.com>2017-04-11 15:34:19 +0200
commitb6b7bef8bdcad15af01ac88a038dd763ce59f68f (patch)
tree399d39da23aaa37701e487df064e3e0c27709ef3 /adapters/mso-adapter-utils/src/main/java/org/openecomp/mso/cloud
parent19340cad94eeaa1b580f7c0c99531de499e8ca14 (diff)
[MSO-8] Update the maven dependency
Update the maven depenency for sdc-distribution-client to cooperate with the sdc changes. Change-Id: I2da936e5c40cb68c7181bb78307192dd5655b5dc Signed-off-by: xg353y <xg353y@intl.att.com>
Diffstat (limited to 'adapters/mso-adapter-utils/src/main/java/org/openecomp/mso/cloud')
-rw-r--r--adapters/mso-adapter-utils/src/main/java/org/openecomp/mso/cloud/CloudConfigIdentityMapper.java29
-rw-r--r--adapters/mso-adapter-utils/src/main/java/org/openecomp/mso/cloud/CloudIdentity.java114
-rw-r--r--adapters/mso-adapter-utils/src/main/java/org/openecomp/mso/cloud/IdentityAuthenticationTypeAbstract.java75
-rw-r--r--adapters/mso-adapter-utils/src/main/java/org/openecomp/mso/cloud/IdentityAuthenticationTypeJsonDeserializer.java44
-rw-r--r--adapters/mso-adapter-utils/src/main/java/org/openecomp/mso/cloud/IdentityAuthenticationTypeJsonSerializer.java38
-rw-r--r--adapters/mso-adapter-utils/src/main/java/org/openecomp/mso/cloud/IdentityServerTypeAbstract.java77
-rw-r--r--adapters/mso-adapter-utils/src/main/java/org/openecomp/mso/cloud/IdentityServerTypeJsonDeserializer.java44
-rw-r--r--adapters/mso-adapter-utils/src/main/java/org/openecomp/mso/cloud/IdentityServerTypeJsonSerializer.java38
-rw-r--r--adapters/mso-adapter-utils/src/main/java/org/openecomp/mso/cloud/authentication/AuthenticationMethodFactory.java79
-rw-r--r--adapters/mso-adapter-utils/src/main/java/org/openecomp/mso/cloud/authentication/AuthenticationWrapper.java58
-rw-r--r--adapters/mso-adapter-utils/src/main/java/org/openecomp/mso/cloud/authentication/models/RackspaceAuthentication.java99
-rw-r--r--adapters/mso-adapter-utils/src/main/java/org/openecomp/mso/cloud/authentication/wrappers/RackspaceAPIKeyWrapper.java55
-rw-r--r--adapters/mso-adapter-utils/src/main/java/org/openecomp/mso/cloud/authentication/wrappers/UsernamePasswordWrapper.java55
13 files changed, 780 insertions, 25 deletions
diff --git a/adapters/mso-adapter-utils/src/main/java/org/openecomp/mso/cloud/CloudConfigIdentityMapper.java b/adapters/mso-adapter-utils/src/main/java/org/openecomp/mso/cloud/CloudConfigIdentityMapper.java
new file mode 100644
index 0000000000..a765f8004e
--- /dev/null
+++ b/adapters/mso-adapter-utils/src/main/java/org/openecomp/mso/cloud/CloudConfigIdentityMapper.java
@@ -0,0 +1,29 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * OPENECOMP - MSO
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+package org.openecomp.mso.cloud;
+
+/**
+ * This interface provides the method signature for mapping registration.
+ * All mappings should be registered by the implementing class.
+ */
+public interface CloudConfigIdentityMapper {
+
+ public void registerAllMappings();
+}
diff --git a/adapters/mso-adapter-utils/src/main/java/org/openecomp/mso/cloud/CloudIdentity.java b/adapters/mso-adapter-utils/src/main/java/org/openecomp/mso/cloud/CloudIdentity.java
index a777e4133c..db6ccde46c 100644
--- a/adapters/mso-adapter-utils/src/main/java/org/openecomp/mso/cloud/CloudIdentity.java
+++ b/adapters/mso-adapter-utils/src/main/java/org/openecomp/mso/cloud/CloudIdentity.java
@@ -1,32 +1,56 @@
-/*-
- * ============LICENSE_START=======================================================
- * OPENECOMP - MSO
- * ================================================================================
- * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
- * ================================================================================
+/*
+ * ============LICENSE_START==========================================
+ * ===================================================================
+ * Copyright (c) 2017 AT&T Intellectual Property. All rights reserved.
+ * ===================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
- * ============LICENSE_END=========================================================
+ * ============LICENSE_END============================================
+ *
+ * ECOMP and OpenECOMP are trademarks
+ * and service marks of AT&T Intellectual Property.
+ *
*/
package org.openecomp.mso.cloud;
+import java.io.IOException;
+import java.net.URISyntaxException;
import java.security.GeneralSecurityException;
+import java.util.Map;
+import java.util.concurrent.ConcurrentHashMap;
import org.codehaus.jackson.annotate.JsonProperty;
+import org.codehaus.jackson.map.JsonSerializer;
+import org.codehaus.jackson.JsonGenerator;
+import org.codehaus.jackson.map.SerializerProvider;
+import org.codehaus.jackson.map.annotate.JsonDeserialize;
+import org.codehaus.jackson.map.annotate.JsonSerialize;
+import org.codehaus.jackson.JsonProcessingException;
+
+import org.openecomp.mso.openstack.exceptions.MsoAdapterException;
import org.openecomp.mso.openstack.exceptions.MsoException;
+import org.openecomp.mso.openstack.utils.MsoCommonUtils;
+import org.openecomp.mso.openstack.utils.MsoKeystoneUtils;
+import org.openecomp.mso.openstack.utils.MsoTenantUtils;
+import org.openecomp.mso.openstack.utils.MsoTenantUtilsFactory;
+import org.openecomp.mso.cloud.authentication.AuthenticationMethodFactory;
+import org.openecomp.mso.cloud.authentication.AuthenticationWrapper;
+import org.openecomp.mso.cloud.authentication.models.RackspaceAuthentication;
+import org.openecomp.mso.cloud.authentication.wrappers.RackspaceAPIKeyWrapper;
+import org.openecomp.mso.cloud.authentication.wrappers.UsernamePasswordWrapper;
import org.openecomp.mso.logger.MessageEnum;
import org.openecomp.mso.logger.MsoLogger;
-import com.woorea.openstack.keystone.model.authentication.RackspaceAuthentication;
+
import com.woorea.openstack.keystone.model.authentication.UsernamePassword;
import org.openecomp.mso.utils.CryptoUtils;
import com.woorea.openstack.keystone.model.Authentication;
@@ -43,11 +67,39 @@ import com.woorea.openstack.keystone.model.Authentication;
*/
public class CloudIdentity {
+ // This block is needed to trigger the class loader so that static initialization
+ // of both inner static classes occur. This is required when the Json Deserializer
+ // gets called and no access to any of these inner classes happened yet.
+ static {
+ IdentityServerType.bootstrap();
+ IdentityAuthenticationType.bootstrap();
+ }
+
private static MsoLogger LOGGER = MsoLogger.getMsoLogger (MsoLogger.Catalog.RA);
-
- public enum IdentityServerType {KEYSTONE};
- public enum IdentityAuthenticationType { USERNAME_PASSWORD, RACKSPACE_APIKEY };
+ public final static class IdentityServerType extends IdentityServerTypeAbstract {
+
+ public static final IdentityServerType KEYSTONE = new IdentityServerType("KEYSTONE", MsoKeystoneUtils.class);
+
+ public IdentityServerType(String serverType, Class<? extends MsoTenantUtils> utilsClass) {
+ super(serverType, utilsClass);
+ }
+
+ public static final void bootstrap() {}
+ }
+
+ public static final class IdentityAuthenticationType extends IdentityAuthenticationTypeAbstract {
+
+ public static final IdentityAuthenticationType USERNAME_PASSWORD = new IdentityAuthenticationType("USERNAME_PASSWORD", UsernamePasswordWrapper.class);
+
+ public static final IdentityAuthenticationType RACKSPACE_APIKEY = new IdentityAuthenticationType("RACKSPACE_APIKEY", RackspaceAPIKeyWrapper.class);
+
+ public IdentityAuthenticationType(String identityType, Class<? extends AuthenticationWrapper> wrapperClass) {
+ super(identityType, wrapperClass);
+ }
+
+ public static final void bootstrap() {}
+ }
@JsonProperty
private String id;
@@ -64,8 +116,12 @@ public class CloudIdentity {
@JsonProperty("tenant_metadata")
private Boolean tenantMetadata;
@JsonProperty("identity_server_type")
+ @JsonSerialize(using=IdentityServerTypeJsonSerializer.class)
+ @JsonDeserialize(using=IdentityServerTypeJsonDeserializer.class)
private IdentityServerType identityServerType;
@JsonProperty("identity_authentication_type")
+ @JsonSerialize(using=IdentityAuthenticationTypeJsonSerializer.class)
+ @JsonDeserialize(using=IdentityAuthenticationTypeJsonDeserializer.class)
private IdentityAuthenticationType identityAuthenticationType;
private static String cloudKey = "aa3871669d893c7fb8abbcda31b88b4f";
@@ -92,26 +148,34 @@ public class CloudIdentity {
public String getKeystoneUrl (String regionId, String msoPropID) throws MsoException {
if (IdentityServerType.KEYSTONE.equals(this.identityServerType)) {
return this.identityUrl;
- }
- else {
- return null;
+ } else {
+ if (this.identityServerType == null) {
+ return null;
+ }
+ MsoTenantUtils tenantUtils = new MsoTenantUtilsFactory(msoPropID).getTenantUtilsByServerType(this.identityServerType.toString());
+ if (tenantUtils != null) {
+ return tenantUtils.getKeystoneUrl(regionId, msoPropID, this);
+ } else {
+ return null;
+ }
}
}
public Authentication getAuthentication () throws MsoException {
- if (IdentityAuthenticationType.RACKSPACE_APIKEY.equals(this.identityAuthenticationType)) {
- return new RackspaceAuthentication (this.getMsoId (),this.getMsoPass ());
- }
- else {
- // Use default case
- return new UsernamePassword (this.getMsoId (),this.getMsoPass ());
+ if (this.getIdentityAuthenticationType() != null) {
+ try {
+ return AuthenticationMethodFactory.getAuthenticationFor(this);
+ } catch (IllegalAccessException | InstantiationException | ClassNotFoundException | IOException | URISyntaxException e) {
+ throw new MsoAdapterException("Could not retrieve authentication for " + this.identityAuthenticationType, e);
+ }
+ } else { // Fallback
+ return new UsernamePassword(this.getMsoId(), this.getMsoPass());
}
-
}
public void setKeystoneUrl (String url) {
if (IdentityServerType.KEYSTONE.equals(this.identityServerType)) {
- this.identityUrl = url;
+ this.identityUrl = url;
}
}
diff --git a/adapters/mso-adapter-utils/src/main/java/org/openecomp/mso/cloud/IdentityAuthenticationTypeAbstract.java b/adapters/mso-adapter-utils/src/main/java/org/openecomp/mso/cloud/IdentityAuthenticationTypeAbstract.java
new file mode 100644
index 0000000000..45a79730ad
--- /dev/null
+++ b/adapters/mso-adapter-utils/src/main/java/org/openecomp/mso/cloud/IdentityAuthenticationTypeAbstract.java
@@ -0,0 +1,75 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * OPENECOMP - MSO
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+package org.openecomp.mso.cloud;
+
+import java.util.Map;
+import java.util.concurrent.ConcurrentHashMap;
+
+import org.openecomp.mso.cloud.authentication.AuthenticationWrapper;
+
+public abstract class IdentityAuthenticationTypeAbstract {
+
+ // This map will prevent duplicates (as if it was an Enum).
+ // Without this, using an instance specific field for the class could allow
+ // different classes bound to the same entry name.
+ private static final Map<String, IdentityAuthenticationTypeAbstract> entries = new ConcurrentHashMap<>();
+
+ private String identityType;
+
+ private Class<? extends AuthenticationWrapper> wrapperClass;
+
+ protected IdentityAuthenticationTypeAbstract(String identityType, Class<? extends AuthenticationWrapper> wrapperClass) {
+ try {
+ this.identityType = identityType;
+ this.wrapperClass = wrapperClass;
+ entries.put(identityType, this);
+ AuthenticationWrapper.register(this.toString(), wrapperClass);
+ } catch (IllegalAccessException | InstantiationException e) {
+ // Do not add the class if an exception occurs as we won't get the class anyway
+ }
+ }
+
+ public static final IdentityAuthenticationTypeAbstract valueOf(String serverType) {
+ return entries.get(serverType);
+ }
+
+ @Override
+ public final String toString() {
+ return this.identityType;
+ }
+
+ public final String name() {
+ return this.identityType;
+ }
+
+ public static final IdentityAuthenticationTypeAbstract[] values() {
+ return (IdentityAuthenticationTypeAbstract[]) entries.values().stream().toArray(IdentityAuthenticationTypeAbstract[]::new);
+ }
+
+ public final Class<? extends AuthenticationWrapper> getWrapperClass() {
+ return this.wrapperClass;
+ }
+
+ @Override
+ public final boolean equals(Object other) {
+ return ((this.identityType != null) && (other != null) && (other instanceof IdentityAuthenticationTypeAbstract) && (this.identityType.equals(other.toString())));
+ }
+
+}
diff --git a/adapters/mso-adapter-utils/src/main/java/org/openecomp/mso/cloud/IdentityAuthenticationTypeJsonDeserializer.java b/adapters/mso-adapter-utils/src/main/java/org/openecomp/mso/cloud/IdentityAuthenticationTypeJsonDeserializer.java
new file mode 100644
index 0000000000..c7b2c14cb8
--- /dev/null
+++ b/adapters/mso-adapter-utils/src/main/java/org/openecomp/mso/cloud/IdentityAuthenticationTypeJsonDeserializer.java
@@ -0,0 +1,44 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * OPENECOMP - MSO
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+package org.openecomp.mso.cloud;
+
+import java.io.IOException;
+
+import org.codehaus.jackson.JsonParser;
+import org.codehaus.jackson.JsonProcessingException;
+import org.codehaus.jackson.JsonToken;
+import org.codehaus.jackson.map.DeserializationContext;
+import org.codehaus.jackson.map.JsonDeserializer;
+import org.openecomp.mso.cloud.CloudIdentity.IdentityServerType;
+
+
+public class IdentityAuthenticationTypeJsonDeserializer extends JsonDeserializer<IdentityAuthenticationTypeAbstract> {
+
+ @Override
+ public IdentityAuthenticationTypeAbstract deserialize(JsonParser jsonParser, DeserializationContext deserializationContext)
+ throws IOException, JsonProcessingException {
+ JsonToken token = jsonParser.getCurrentToken();
+ if (JsonToken.VALUE_STRING.equals(token)) {
+ return IdentityAuthenticationTypeAbstract.valueOf(jsonParser.getText());
+ } else {
+ return null;
+ }
+ }
+}
diff --git a/adapters/mso-adapter-utils/src/main/java/org/openecomp/mso/cloud/IdentityAuthenticationTypeJsonSerializer.java b/adapters/mso-adapter-utils/src/main/java/org/openecomp/mso/cloud/IdentityAuthenticationTypeJsonSerializer.java
new file mode 100644
index 0000000000..06d877d4fa
--- /dev/null
+++ b/adapters/mso-adapter-utils/src/main/java/org/openecomp/mso/cloud/IdentityAuthenticationTypeJsonSerializer.java
@@ -0,0 +1,38 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * OPENECOMP - MSO
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+package org.openecomp.mso.cloud;
+
+import java.io.IOException;
+
+import org.codehaus.jackson.JsonGenerator;
+import org.codehaus.jackson.JsonProcessingException;
+import org.codehaus.jackson.map.JsonSerializer;
+import org.codehaus.jackson.map.SerializerProvider;
+import org.openecomp.mso.cloud.CloudIdentity.IdentityServerType;
+
+
+public class IdentityAuthenticationTypeJsonSerializer extends JsonSerializer<IdentityAuthenticationTypeAbstract> {
+
+ @Override
+ public void serialize(IdentityAuthenticationTypeAbstract tmpObj, JsonGenerator jsonGenerator, SerializerProvider serializerProvider)
+ throws IOException, JsonProcessingException {
+ jsonGenerator.writeObject(tmpObj.toString());
+ }
+}
diff --git a/adapters/mso-adapter-utils/src/main/java/org/openecomp/mso/cloud/IdentityServerTypeAbstract.java b/adapters/mso-adapter-utils/src/main/java/org/openecomp/mso/cloud/IdentityServerTypeAbstract.java
new file mode 100644
index 0000000000..38f1f87ddc
--- /dev/null
+++ b/adapters/mso-adapter-utils/src/main/java/org/openecomp/mso/cloud/IdentityServerTypeAbstract.java
@@ -0,0 +1,77 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * OPENECOMP - MSO
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+package org.openecomp.mso.cloud;
+
+import java.util.Map;
+import java.util.concurrent.ConcurrentHashMap;
+
+import org.openecomp.mso.openstack.utils.MsoTenantUtils;
+
+
+public abstract class IdentityServerTypeAbstract {
+
+ // This map will prevent duplicates (as if it was an Enum).
+ // Without this, using an instance specific field for the class could allow
+ // different classes bound to the same entry name.
+ private static final Map<String, IdentityServerTypeAbstract> entries = new ConcurrentHashMap<>();
+
+ private String serverType;
+
+ private Class<? extends MsoTenantUtils> utilsClass;
+
+ protected IdentityServerTypeAbstract(String serverType, Class<? extends MsoTenantUtils> utilsClass) {
+ if ((serverType == null) || (serverType.isEmpty())) {
+ throw new IllegalArgumentException("Server Type name cannot be null or empty, provided value was " + serverType);
+ }
+ if (entries.containsKey(serverType)) {
+ throw new IllegalArgumentException("Duplicate Server Type entry for registration: " + serverType);
+ }
+ this.serverType = serverType;
+ this.utilsClass = utilsClass;
+ entries.put(serverType, this);
+ }
+
+ public static final IdentityServerTypeAbstract valueOf(String serverType) {
+ return entries.get(serverType);
+ }
+
+ @Override
+ public final String toString() {
+ return this.serverType;
+ }
+
+ public final String name() {
+ return this.serverType;
+ }
+
+ public static final IdentityServerTypeAbstract[] values() {
+ return (IdentityServerTypeAbstract[]) entries.values().stream().toArray(IdentityServerTypeAbstract[]::new);
+ }
+
+ public final Class<? extends MsoTenantUtils> getMsoTenantUtilsClass() {
+ return this.utilsClass;
+ }
+
+ @Override
+ public final boolean equals(Object other) {
+ return ((this.serverType != null) && (other != null) && (other instanceof IdentityServerTypeAbstract) && (this.serverType.equals(other.toString())));
+ }
+
+}
diff --git a/adapters/mso-adapter-utils/src/main/java/org/openecomp/mso/cloud/IdentityServerTypeJsonDeserializer.java b/adapters/mso-adapter-utils/src/main/java/org/openecomp/mso/cloud/IdentityServerTypeJsonDeserializer.java
new file mode 100644
index 0000000000..8b9da1a3f4
--- /dev/null
+++ b/adapters/mso-adapter-utils/src/main/java/org/openecomp/mso/cloud/IdentityServerTypeJsonDeserializer.java
@@ -0,0 +1,44 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * OPENECOMP - MSO
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+package org.openecomp.mso.cloud;
+
+import java.io.IOException;
+
+import org.codehaus.jackson.JsonParser;
+import org.codehaus.jackson.JsonProcessingException;
+import org.codehaus.jackson.JsonToken;
+import org.codehaus.jackson.map.DeserializationContext;
+import org.codehaus.jackson.map.JsonDeserializer;
+import org.openecomp.mso.cloud.CloudIdentity.IdentityServerType;
+
+
+public class IdentityServerTypeJsonDeserializer extends JsonDeserializer<IdentityServerTypeAbstract> {
+
+ @Override
+ public IdentityServerTypeAbstract deserialize(JsonParser jsonParser, DeserializationContext deserializationContext)
+ throws IOException, JsonProcessingException {
+ JsonToken token = jsonParser.getCurrentToken();
+ if (JsonToken.VALUE_STRING.equals(token)) {
+ return IdentityServerTypeAbstract.valueOf(jsonParser.getText());
+ } else {
+ return null;
+ }
+ }
+}
diff --git a/adapters/mso-adapter-utils/src/main/java/org/openecomp/mso/cloud/IdentityServerTypeJsonSerializer.java b/adapters/mso-adapter-utils/src/main/java/org/openecomp/mso/cloud/IdentityServerTypeJsonSerializer.java
new file mode 100644
index 0000000000..c008860264
--- /dev/null
+++ b/adapters/mso-adapter-utils/src/main/java/org/openecomp/mso/cloud/IdentityServerTypeJsonSerializer.java
@@ -0,0 +1,38 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * OPENECOMP - MSO
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+package org.openecomp.mso.cloud;
+
+import java.io.IOException;
+
+import org.codehaus.jackson.JsonGenerator;
+import org.codehaus.jackson.JsonProcessingException;
+import org.codehaus.jackson.map.JsonSerializer;
+import org.codehaus.jackson.map.SerializerProvider;
+import org.openecomp.mso.cloud.CloudIdentity.IdentityServerType;
+
+
+public class IdentityServerTypeJsonSerializer extends JsonSerializer<IdentityServerTypeAbstract> {
+
+ @Override
+ public void serialize(IdentityServerTypeAbstract tmpObj, JsonGenerator jsonGenerator, SerializerProvider serializerProvider)
+ throws IOException, JsonProcessingException {
+ jsonGenerator.writeObject(tmpObj.toString());
+ }
+}
diff --git a/adapters/mso-adapter-utils/src/main/java/org/openecomp/mso/cloud/authentication/AuthenticationMethodFactory.java b/adapters/mso-adapter-utils/src/main/java/org/openecomp/mso/cloud/authentication/AuthenticationMethodFactory.java
new file mode 100644
index 0000000000..feaafd3c07
--- /dev/null
+++ b/adapters/mso-adapter-utils/src/main/java/org/openecomp/mso/cloud/authentication/AuthenticationMethodFactory.java
@@ -0,0 +1,79 @@
+/*
+ * ============LICENSE_START==========================================
+ * ===================================================================
+ * Copyright (c) 2017 AT&T Intellectual Property. All rights reserved.
+ * ===================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END============================================
+ *
+ * ECOMP and OpenECOMP are trademarks
+ * and service marks of AT&T Intellectual Property.
+ *
+ */
+
+package org.openecomp.mso.cloud.authentication;
+
+import java.io.IOException;
+import java.net.URISyntaxException;
+import java.util.Map;
+import java.util.concurrent.ConcurrentHashMap;
+
+import org.openecomp.mso.cloud.CloudIdentity;
+
+import com.woorea.openstack.keystone.model.Authentication;
+
+/**
+ * This factory manages all the wrappers associated to authentication types.
+ *
+ */
+public final class AuthenticationMethodFactory {
+
+ private static Map<String, AuthenticationWrapper> authWrappers = new ConcurrentHashMap<>();
+
+ /**
+ *
+ */
+ private AuthenticationMethodFactory() {}
+
+ /**
+ * Function to be called by classes implementing the abstract {@link AuthenticationWrapper#register(String, Class)}.
+ */
+ static final synchronized void register(String authenticationType, Class<? extends AuthenticationWrapper> wrapperClass) throws InstantiationException, IllegalAccessException {
+ if ((authenticationType == null) || ("".equals(authenticationType))) {
+ throw new IllegalArgumentException("Authentication Type to register cannot be null or an empty name string, provided value is " + authenticationType + ".");
+ }
+ if (wrapperClass == null) {
+ throw new IllegalArgumentException("Wrapper Class to register for Authentication cannot be null");
+ }
+
+ if (!authWrappers.containsKey(authenticationType)) {
+ authWrappers.put(authenticationType, wrapperClass.newInstance());
+ }
+ }
+
+ public static final synchronized Authentication getAuthenticationFor(CloudIdentity cloudIdentity) throws InstantiationException, IllegalAccessException, ClassNotFoundException, IOException, URISyntaxException {
+ if (cloudIdentity == null) {
+ throw new IllegalArgumentException("Cloud identity cannot be null");
+ }
+ if ((cloudIdentity.getIdentityAuthenticationType() == null) || ("".equals(cloudIdentity.getIdentityAuthenticationType().toString()))) {
+ throw new IllegalArgumentException("Cloud identity authentication type cannot be null or empty, provided value is " + cloudIdentity.getIdentityAuthenticationType() + ".");
+ }
+ String authenticationType = cloudIdentity.getIdentityAuthenticationType().toString();
+
+ if (authWrappers.containsKey(authenticationType)) {
+ return authWrappers.get(authenticationType).getAuthentication(cloudIdentity);
+ } else {
+ throw new IllegalArgumentException("Provided authentication type (" + authenticationType + ") is not implemented by any wrapper.");
+ }
+ }
+}
diff --git a/adapters/mso-adapter-utils/src/main/java/org/openecomp/mso/cloud/authentication/AuthenticationWrapper.java b/adapters/mso-adapter-utils/src/main/java/org/openecomp/mso/cloud/authentication/AuthenticationWrapper.java
new file mode 100644
index 0000000000..8b3725cd41
--- /dev/null
+++ b/adapters/mso-adapter-utils/src/main/java/org/openecomp/mso/cloud/authentication/AuthenticationWrapper.java
@@ -0,0 +1,58 @@
+/*
+ * ============LICENSE_START==========================================
+ * ===================================================================
+ * Copyright (c) 2017 AT&T Intellectual Property. All rights reserved.
+ * ===================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END============================================
+ *
+ * ECOMP and OpenECOMP are trademarks
+ * and service marks of AT&T Intellectual Property.
+ *
+ */
+
+package org.openecomp.mso.cloud.authentication;
+
+import org.openecomp.mso.cloud.CloudIdentity;
+
+import com.woorea.openstack.keystone.model.Authentication;
+
+/**
+ * This abstract class provides the necessary method for registering authentication
+ * types with wrapper classes, and also defines the contract for providing
+ * Openstack-compatible Authentication implementations for said authentication types.
+ *
+ */
+public abstract class AuthenticationWrapper {
+
+ /**
+ * Registers the implementing class to the list of Authentication Wrappers.
+ *
+ * @param authenticationType The authentication type that is provided by the implementing class
+ * @param wrapperClass The implementing class Class object
+ * @throws InstantiationException If the provided implementing class cannot be instantiated
+ * @throws IllegalAccessException If the provided implementing class cannot be instantiated
+ */
+ public static final void register(String authenticationType, Class<? extends AuthenticationWrapper> wrapperClass) throws InstantiationException, IllegalAccessException {
+ AuthenticationMethodFactory.register(authenticationType, wrapperClass);
+ }
+
+ /**
+ * Returns an OpenStack Authentication object for the provided CloudIdentity.
+ *
+ * @param cloudIdentity The input Cloud Identity instance
+ * @return the OpenStack Authentication associated with this cloud identity instance
+ */
+ protected abstract Authentication getAuthentication(CloudIdentity cloudIdentity);
+
+}
diff --git a/adapters/mso-adapter-utils/src/main/java/org/openecomp/mso/cloud/authentication/models/RackspaceAuthentication.java b/adapters/mso-adapter-utils/src/main/java/org/openecomp/mso/cloud/authentication/models/RackspaceAuthentication.java
new file mode 100644
index 0000000000..2b8da9f641
--- /dev/null
+++ b/adapters/mso-adapter-utils/src/main/java/org/openecomp/mso/cloud/authentication/models/RackspaceAuthentication.java
@@ -0,0 +1,99 @@
+/*
+ * ============LICENSE_START==========================================
+ * ===================================================================
+ * Copyright (c) 2017 AT&T Intellectual Property. All rights reserved.
+ * ===================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END============================================
+ *
+ * ECOMP and OpenECOMP are trademarks
+ * and service marks of AT&T Intellectual Property.
+ *
+ */
+
+package org.openecomp.mso.cloud.authentication.models;
+
+import org.codehaus.jackson.annotate.JsonIgnore;
+import org.codehaus.jackson.annotate.JsonProperty;
+import org.codehaus.jackson.map.annotate.JsonRootName;
+import com.woorea.openstack.keystone.model.Authentication;
+
+@JsonRootName("auth")
+public class RackspaceAuthentication extends Authentication {
+
+ /**
+ *
+ */
+ private static final long serialVersionUID = 5451283386875662918L;
+
+ @JsonIgnore
+ private String tenantId;
+
+ @JsonIgnore
+ private String tenantName;
+
+ public static final class Token {
+
+ private String username;
+ private String apiKey;
+
+ /**
+ * @return the username
+ */
+ public String getUsername() {
+ return username;
+ }
+ /**
+ * @param username the username to set
+ */
+ public void setUsername(String username) {
+ this.username = username;
+ }
+ /**
+ * @return the apiKey
+ */
+ public String getApiKey() {
+ return apiKey;
+ }
+ /**
+ * @param apiKey the apiKey to set
+ */
+ public void setApiKey(String apiKey) {
+ this.apiKey = apiKey;
+ }
+ }
+
+ @JsonProperty("RAX-KSKEY:apiKeyCredentials")
+ private Token token = new Token();
+
+ public RackspaceAuthentication (String username, String apiKey) {
+ this.token.username = username;
+ this.token.apiKey = apiKey;
+
+ }
+
+ /**
+ * @return the token
+ */
+ public Token getToken() {
+ return token;
+ }
+
+ /**
+ * @param token the token to set
+ */
+ public void setToken(Token token) {
+ this.token = token;
+ }
+
+}
diff --git a/adapters/mso-adapter-utils/src/main/java/org/openecomp/mso/cloud/authentication/wrappers/RackspaceAPIKeyWrapper.java b/adapters/mso-adapter-utils/src/main/java/org/openecomp/mso/cloud/authentication/wrappers/RackspaceAPIKeyWrapper.java
new file mode 100644
index 0000000000..87ff2582de
--- /dev/null
+++ b/adapters/mso-adapter-utils/src/main/java/org/openecomp/mso/cloud/authentication/wrappers/RackspaceAPIKeyWrapper.java
@@ -0,0 +1,55 @@
+/*
+ * ============LICENSE_START==========================================
+ * ===================================================================
+ * Copyright (c) 2017 AT&T Intellectual Property. All rights reserved.
+ * ===================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END============================================
+ *
+ * ECOMP and OpenECOMP are trademarks
+ * and service marks of AT&T Intellectual Property.
+ *
+ */
+
+package org.openecomp.mso.cloud.authentication.wrappers;
+
+import org.openecomp.mso.cloud.CloudIdentity;
+import org.openecomp.mso.cloud.authentication.AuthenticationWrapper;
+import org.openecomp.mso.cloud.authentication.models.RackspaceAuthentication;
+
+import com.woorea.openstack.keystone.model.Authentication;
+
+/**
+ * This class implements the authentication wrapper for Rackspace Authentication.
+ *
+ */
+public class RackspaceAPIKeyWrapper extends AuthenticationWrapper {
+
+ /**
+ *
+ */
+ public RackspaceAPIKeyWrapper() {
+ // TODO Auto-generated constructor stub
+ }
+
+ /* (non-Javadoc)
+ * @see org.openecomp.mso.cloud.authentication.AuthenticationWrapper#getAuthentication(org.openecomp.mso.cloud.CloudIdentity)
+ */
+ @Override
+ public Authentication getAuthentication(CloudIdentity cloudIdentity) {
+ if (cloudIdentity == null) {
+ throw new IllegalArgumentException("Provided cloud identity is null, cannot extract username and password");
+ }
+ return new RackspaceAuthentication (cloudIdentity.getMsoId (), cloudIdentity.getMsoPass ());
+ }
+}
diff --git a/adapters/mso-adapter-utils/src/main/java/org/openecomp/mso/cloud/authentication/wrappers/UsernamePasswordWrapper.java b/adapters/mso-adapter-utils/src/main/java/org/openecomp/mso/cloud/authentication/wrappers/UsernamePasswordWrapper.java
new file mode 100644
index 0000000000..2eebbb7d4b
--- /dev/null
+++ b/adapters/mso-adapter-utils/src/main/java/org/openecomp/mso/cloud/authentication/wrappers/UsernamePasswordWrapper.java
@@ -0,0 +1,55 @@
+/*
+ * ============LICENSE_START==========================================
+ * ===================================================================
+ * Copyright (c) 2017 AT&T Intellectual Property. All rights reserved.
+ * ===================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END============================================
+ *
+ * ECOMP and OpenECOMP are trademarks
+ * and service marks of AT&T Intellectual Property.
+ *
+ */
+
+package org.openecomp.mso.cloud.authentication.wrappers;
+
+import org.openecomp.mso.cloud.CloudIdentity;
+import org.openecomp.mso.cloud.authentication.AuthenticationWrapper;
+
+import com.woorea.openstack.keystone.model.Authentication;
+import com.woorea.openstack.keystone.model.authentication.UsernamePassword;
+
+/**
+ * This class implements the authentication wrapper for Openstack provided for
+ * user name and password authentication.
+ *
+ */
+public class UsernamePasswordWrapper extends AuthenticationWrapper {
+
+ /**
+ *
+ */
+ public UsernamePasswordWrapper() {
+ }
+
+ /* (non-Javadoc)
+ * @see org.openecomp.mso.cloud.authentication.AuthenticationWrapper#getAuthentication(org.openecomp.mso.cloud.CloudIdentity)
+ */
+ @Override
+ public Authentication getAuthentication(CloudIdentity cloudIdentity) {
+ if (cloudIdentity == null) {
+ throw new IllegalArgumentException("Provided cloud identity is null, cannot extract username and password");
+ }
+ return new UsernamePassword (cloudIdentity.getMsoId (), cloudIdentity.getMsoPass ());
+ }
+}