2 * ============LICENSE_START==========================================
3 * ===================================================================
4 * Copyright (c) 2017 AT&T Intellectual Property. All rights reserved.
5 * ===================================================================
6 * Licensed under the Apache License, Version 2.0 (the "License");
7 * you may not use this file except in compliance with the License.
8 * You may obtain a copy of the License at
10 * http://www.apache.org/licenses/LICENSE-2.0
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
17 * ============LICENSE_END============================================
19 * ECOMP and OpenECOMP are trademarks
20 * and service marks of AT&T Intellectual Property.
24 package org.openecomp.mso.cloud;
26 import java.io.IOException;
27 import java.net.URISyntaxException;
28 import java.security.GeneralSecurityException;
30 import java.util.concurrent.ConcurrentHashMap;
32 import org.codehaus.jackson.annotate.JsonProperty;
33 import org.codehaus.jackson.map.JsonSerializer;
34 import org.codehaus.jackson.JsonGenerator;
35 import org.codehaus.jackson.map.SerializerProvider;
36 import org.codehaus.jackson.map.annotate.JsonDeserialize;
37 import org.codehaus.jackson.map.annotate.JsonSerialize;
38 import org.codehaus.jackson.JsonProcessingException;
40 import org.openecomp.mso.openstack.exceptions.MsoAdapterException;
41 import org.openecomp.mso.openstack.exceptions.MsoException;
42 import org.openecomp.mso.openstack.utils.MsoCommonUtils;
43 import org.openecomp.mso.openstack.utils.MsoKeystoneUtils;
44 import org.openecomp.mso.openstack.utils.MsoTenantUtils;
45 import org.openecomp.mso.openstack.utils.MsoTenantUtilsFactory;
46 import org.openecomp.mso.cloud.authentication.AuthenticationMethodFactory;
47 import org.openecomp.mso.cloud.authentication.AuthenticationWrapper;
48 import org.openecomp.mso.cloud.authentication.models.RackspaceAuthentication;
49 import org.openecomp.mso.cloud.authentication.wrappers.RackspaceAPIKeyWrapper;
50 import org.openecomp.mso.cloud.authentication.wrappers.UsernamePasswordWrapper;
51 import org.openecomp.mso.logger.MessageEnum;
52 import org.openecomp.mso.logger.MsoLogger;
54 import com.woorea.openstack.keystone.model.authentication.UsernamePassword;
55 import org.openecomp.mso.utils.CryptoUtils;
56 import com.woorea.openstack.keystone.model.Authentication;
59 * JavaBean JSON class for a CloudIdentity. This bean represents a cloud identity
60 * service instance (i.e. a DCP node) in the NVP/AIC cloud. It will be loaded via
61 * CloudConfig object, of which it is a component (a CloudConfig JSON configuration
62 * file may contain multiple CloudIdentity definitions).
64 * Note that this is only used to access Cloud Configurations loaded from a
65 * JSON config file, so there are no explicit setters.
68 public class CloudIdentity {
70 // This block is needed to trigger the class loader so that static initialization
71 // of both inner static classes occur. This is required when the Json Deserializer
72 // gets called and no access to any of these inner classes happened yet.
74 IdentityServerType.bootstrap();
75 IdentityAuthenticationType.bootstrap();
78 private static MsoLogger LOGGER = MsoLogger.getMsoLogger (MsoLogger.Catalog.RA);
80 public final static class IdentityServerType extends IdentityServerTypeAbstract {
82 public static final IdentityServerType KEYSTONE = new IdentityServerType("KEYSTONE", MsoKeystoneUtils.class);
84 public IdentityServerType(String serverType, Class<? extends MsoTenantUtils> utilsClass) {
85 super(serverType, utilsClass);
88 public static final void bootstrap() {}
91 public static final class IdentityAuthenticationType extends IdentityAuthenticationTypeAbstract {
93 public static final IdentityAuthenticationType USERNAME_PASSWORD = new IdentityAuthenticationType("USERNAME_PASSWORD", UsernamePasswordWrapper.class);
95 public static final IdentityAuthenticationType RACKSPACE_APIKEY = new IdentityAuthenticationType("RACKSPACE_APIKEY", RackspaceAPIKeyWrapper.class);
97 public IdentityAuthenticationType(String identityType, Class<? extends AuthenticationWrapper> wrapperClass) {
98 super(identityType, wrapperClass);
101 public static final void bootstrap() {}
106 @JsonProperty("identity_url")
107 private String identityUrl;
108 @JsonProperty("mso_id")
109 private String msoId;
110 @JsonProperty("mso_pass")
111 private String msoPass;
112 @JsonProperty("admin_tenant")
113 private String adminTenant;
114 @JsonProperty("member_role")
115 private String memberRole;
116 @JsonProperty("tenant_metadata")
117 private Boolean tenantMetadata;
118 @JsonProperty("identity_server_type")
119 @JsonSerialize(using=IdentityServerTypeJsonSerializer.class)
120 @JsonDeserialize(using=IdentityServerTypeJsonDeserializer.class)
121 private IdentityServerType identityServerType;
122 @JsonProperty("identity_authentication_type")
123 @JsonSerialize(using=IdentityAuthenticationTypeJsonSerializer.class)
124 @JsonDeserialize(using=IdentityAuthenticationTypeJsonDeserializer.class)
125 private IdentityAuthenticationType identityAuthenticationType;
127 private static String cloudKey = "aa3871669d893c7fb8abbcda31b88b4f";
129 public CloudIdentity () {
132 public String getId () {
136 public void setId (String id) {
141 public String getKeystoneUrl () throws MsoException {
142 if (this.identityServerType.equals(IdentityServerType.KEYSTONE))
143 return this.identityUrl;
148 public String getKeystoneUrl (String regionId, String msoPropID) throws MsoException {
149 if (IdentityServerType.KEYSTONE.equals(this.identityServerType)) {
150 return this.identityUrl;
152 if (this.identityServerType == null) {
155 MsoTenantUtils tenantUtils = new MsoTenantUtilsFactory(msoPropID).getTenantUtilsByServerType(this.identityServerType.toString());
156 if (tenantUtils != null) {
157 return tenantUtils.getKeystoneUrl(regionId, msoPropID, this);
164 public Authentication getAuthentication () throws MsoException {
165 if (this.getIdentityAuthenticationType() != null) {
167 return AuthenticationMethodFactory.getAuthenticationFor(this);
168 } catch (IllegalAccessException | InstantiationException | ClassNotFoundException | IOException | URISyntaxException e) {
169 throw new MsoAdapterException("Could not retrieve authentication for " + this.identityAuthenticationType, e);
172 return new UsernamePassword(this.getMsoId(), this.getMsoPass());
176 public void setKeystoneUrl (String url) {
177 if (IdentityServerType.KEYSTONE.equals(this.identityServerType)) {
178 this.identityUrl = url;
182 public String getIdentityUrl() {
183 return this.identityUrl;
185 public void setIdentityUrl(String url) {
186 this.identityUrl = url;
189 public String getMsoId () {
193 public void setMsoId (String id) {
197 public String getMsoPass () {
199 return CryptoUtils.decrypt (msoPass, cloudKey);
200 } catch (GeneralSecurityException e) {
201 LOGGER.error (MessageEnum.RA_GENERAL_EXCEPTION, "", "", MsoLogger.ErrorCode.BusinessProcesssError, "Exception in getMsoPass", e);
206 public void setMsoPass (String pwd) {
210 public String getAdminTenant () {
214 public void setAdminTenant (String tenant) {
215 this.adminTenant = tenant;
218 public String getMemberRole () {
222 public void setMemberRole (String role) {
223 this.memberRole = role;
226 public boolean hasTenantMetadata () {
227 return tenantMetadata;
230 public void setTenantMetadata (boolean meta) {
231 this.tenantMetadata = meta;
234 public IdentityServerType getIdentityServerType() {
235 return this.identityServerType;
237 public void setIdentityServerType(IdentityServerType ist) {
238 this.identityServerType = ist;
240 public String getIdentityServerTypeAsString() {
241 return this.identityServerType.toString();
244 * @return the identityAuthenticationType
246 public IdentityAuthenticationType getIdentityAuthenticationType() {
247 return identityAuthenticationType;
251 * @param identityAuthenticationType the identityAuthenticationType to set
253 public void setIdentityAuthenticationType(IdentityAuthenticationType identityAuthenticationType) {
254 this.identityAuthenticationType = identityAuthenticationType;
258 public String toString () {
259 StringBuilder stringBuilder = new StringBuilder ();
260 stringBuilder.append ("Cloud Identity Service: id=")
262 .append (", identityUrl=")
263 .append (this.identityUrl)
266 .append (", adminTenant=")
267 .append (adminTenant)
268 .append (", memberRole=")
270 .append (", tenantMetadata=")
271 .append (tenantMetadata)
272 .append (", identityServerType=")
273 .append (identityServerType == null ? "null" : identityServerType.toString())
274 .append (", identityAuthenticationType=")
275 .append (identityAuthenticationType == null ? "null" : identityAuthenticationType.toString());
277 return stringBuilder.toString ();
280 public static String encryptPassword (String msoPass) {
282 return CryptoUtils.encrypt (msoPass, cloudKey);
283 } catch (GeneralSecurityException e) {
284 LOGGER.error (MessageEnum.RA_GENERAL_EXCEPTION, "", "", MsoLogger.ErrorCode.BusinessProcesssError, "Exception in encryptPassword", e);
291 public CloudIdentity clone() {
292 CloudIdentity cloudIdentityCopy = new CloudIdentity();
294 cloudIdentityCopy.id = this.id;
295 cloudIdentityCopy.identityUrl = this.identityUrl;
296 cloudIdentityCopy.msoId = this.msoId;
297 cloudIdentityCopy.msoPass = this.msoPass;
298 cloudIdentityCopy.adminTenant = this.adminTenant;
299 cloudIdentityCopy.memberRole = this.memberRole;
300 cloudIdentityCopy.tenantMetadata = this.tenantMetadata;
301 cloudIdentityCopy.identityServerType = this.identityServerType;
302 cloudIdentityCopy.identityAuthenticationType = this.identityAuthenticationType;
304 return cloudIdentityCopy;
308 public int hashCode() {
309 final int prime = 31;
311 result = prime * result + ((adminTenant == null) ? 0 : adminTenant.hashCode());
312 result = prime * result + ((id == null) ? 0 : id.hashCode());
313 result = prime * result + ((identityUrl == null) ? 0 : identityUrl.hashCode());
314 result = prime * result + ((memberRole == null) ? 0 : memberRole.hashCode());
315 result = prime * result + ((msoId == null) ? 0 : msoId.hashCode());
316 result = prime * result + ((msoPass == null) ? 0 : msoPass.hashCode());
317 result = prime * result + ((tenantMetadata == null) ? 0 : tenantMetadata.hashCode());
318 result = prime * result + ((identityServerType == null) ? 0 : identityServerType.hashCode());
319 result = prime * result + ((identityAuthenticationType == null) ? 0 : identityAuthenticationType.hashCode());
324 public boolean equals(Object obj) {
329 if (getClass() != obj.getClass())
331 CloudIdentity other = (CloudIdentity) obj;
332 if (adminTenant == null) {
333 if (other.adminTenant != null)
335 } else if (!adminTenant.equals(other.adminTenant))
338 if (other.id != null)
340 } else if (!id.equals(other.id))
342 if (identityUrl == null) {
343 if (other.identityUrl != null)
345 } else if (!identityUrl.equals(other.identityUrl))
347 if (memberRole == null) {
348 if (other.memberRole != null)
350 } else if (!memberRole.equals(other.memberRole))
353 if (other.msoId != null)
355 } else if (!msoId.equals(other.msoId))
357 if (msoPass == null) {
358 if (other.msoPass != null)
360 } else if (!msoPass.equals(other.msoPass))
362 if (tenantMetadata == null) {
363 if (other.tenantMetadata != null)
365 } else if (!tenantMetadata.equals(other.tenantMetadata))
367 if (identityServerType == null) {
368 if (other.getIdentityServerType() != null)
370 } else if (!identityServerType.equals(other.getIdentityServerType()))
372 if (identityAuthenticationType == null) {
373 if (other.getIdentityAuthenticationType() != null)
375 } else if (!identityAuthenticationType.equals(other.getIdentityAuthenticationType()))