2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
6 * ================================================================================
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 * ============LICENSE_END=========================================================
21 package org.openecomp.mso.cloud;
23 import java.security.GeneralSecurityException;
25 import org.codehaus.jackson.annotate.JsonProperty;
26 import org.openecomp.mso.openstack.exceptions.MsoException;
27 import org.openecomp.mso.logger.MessageEnum;
28 import org.openecomp.mso.logger.MsoLogger;
29 import com.woorea.openstack.keystone.model.authentication.RackspaceAuthentication;
30 import com.woorea.openstack.keystone.model.authentication.UsernamePassword;
31 import org.openecomp.mso.utils.CryptoUtils;
32 import com.woorea.openstack.keystone.model.Authentication;
35 * JavaBean JSON class for a CloudIdentity. This bean represents a cloud identity
36 * service instance (i.e. a DCP node) in the NVP/AIC cloud. It will be loaded via
37 * CloudConfig object, of which it is a component (a CloudConfig JSON configuration
38 * file may contain multiple CloudIdentity definitions).
40 * Note that this is only used to access Cloud Configurations loaded from a
41 * JSON config file, so there are no explicit setters.
44 public class CloudIdentity {
46 private static MsoLogger LOGGER = MsoLogger.getMsoLogger (MsoLogger.Catalog.RA);
48 public enum IdentityServerType {KEYSTONE};
50 public enum IdentityAuthenticationType { USERNAME_PASSWORD, RACKSPACE_APIKEY };
54 @JsonProperty("identity_url")
55 private String identityUrl;
56 @JsonProperty("mso_id")
58 @JsonProperty("mso_pass")
59 private String msoPass;
60 @JsonProperty("admin_tenant")
61 private String adminTenant;
62 @JsonProperty("member_role")
63 private String memberRole;
64 @JsonProperty("tenant_metadata")
65 private Boolean tenantMetadata;
66 @JsonProperty("identity_server_type")
67 private IdentityServerType identityServerType;
68 @JsonProperty("identity_authentication_type")
69 private IdentityAuthenticationType identityAuthenticationType;
71 private static String cloudKey = "aa3871669d893c7fb8abbcda31b88b4f";
73 public CloudIdentity () {
76 public String getId () {
80 public void setId (String id) {
85 public String getKeystoneUrl () throws MsoException {
86 if (this.identityServerType.equals(IdentityServerType.KEYSTONE))
87 return this.identityUrl;
92 public String getKeystoneUrl (String regionId, String msoPropID) throws MsoException {
93 if (IdentityServerType.KEYSTONE.equals(this.identityServerType)) {
94 return this.identityUrl;
101 public Authentication getAuthentication () throws MsoException {
102 if (IdentityAuthenticationType.RACKSPACE_APIKEY.equals(this.identityAuthenticationType)) {
103 return new RackspaceAuthentication (this.getMsoId (),this.getMsoPass ());
107 return new UsernamePassword (this.getMsoId (),this.getMsoPass ());
112 public void setKeystoneUrl (String url) {
113 if (IdentityServerType.KEYSTONE.equals(this.identityServerType)) {
114 this.identityUrl = url;
118 public String getIdentityUrl() {
119 return this.identityUrl;
121 public void setIdentityUrl(String url) {
122 this.identityUrl = url;
125 public String getMsoId () {
129 public void setMsoId (String id) {
133 public String getMsoPass () {
135 return CryptoUtils.decrypt (msoPass, cloudKey);
136 } catch (GeneralSecurityException e) {
137 LOGGER.error (MessageEnum.RA_GENERAL_EXCEPTION, "", "", MsoLogger.ErrorCode.BusinessProcesssError, "Exception in getMsoPass", e);
142 public void setMsoPass (String pwd) {
146 public String getAdminTenant () {
150 public void setAdminTenant (String tenant) {
151 this.adminTenant = tenant;
154 public String getMemberRole () {
158 public void setMemberRole (String role) {
159 this.memberRole = role;
162 public boolean hasTenantMetadata () {
163 return tenantMetadata;
166 public void setTenantMetadata (boolean meta) {
167 this.tenantMetadata = meta;
170 public IdentityServerType getIdentityServerType() {
171 return this.identityServerType;
173 public void setIdentityServerType(IdentityServerType ist) {
174 this.identityServerType = ist;
176 public String getIdentityServerTypeAsString() {
177 return this.identityServerType.toString();
180 * @return the identityAuthenticationType
182 public IdentityAuthenticationType getIdentityAuthenticationType() {
183 return identityAuthenticationType;
187 * @param identityAuthenticationType the identityAuthenticationType to set
189 public void setIdentityAuthenticationType(IdentityAuthenticationType identityAuthenticationType) {
190 this.identityAuthenticationType = identityAuthenticationType;
194 public String toString () {
195 StringBuilder stringBuilder = new StringBuilder ();
196 stringBuilder.append ("Cloud Identity Service: id=")
198 .append (", identityUrl=")
199 .append (this.identityUrl)
202 .append (", adminTenant=")
203 .append (adminTenant)
204 .append (", memberRole=")
206 .append (", tenantMetadata=")
207 .append (tenantMetadata)
208 .append (", identityServerType=")
209 .append (identityServerType.toString())
210 .append (", identityAuthenticationType=")
211 .append (identityAuthenticationType.toString());
213 return stringBuilder.toString ();
216 public static String encryptPassword (String msoPass) {
218 return CryptoUtils.encrypt (msoPass, cloudKey);
219 } catch (GeneralSecurityException e) {
220 LOGGER.error (MessageEnum.RA_GENERAL_EXCEPTION, "", "", MsoLogger.ErrorCode.BusinessProcesssError, "Exception in encryptPassword", e);
227 public CloudIdentity clone() {
228 CloudIdentity cloudIdentityCopy = new CloudIdentity();
230 cloudIdentityCopy.id = this.id;
231 cloudIdentityCopy.identityUrl = this.identityUrl;
232 cloudIdentityCopy.msoId = this.msoId;
233 cloudIdentityCopy.msoPass = this.msoPass;
234 cloudIdentityCopy.adminTenant = this.adminTenant;
235 cloudIdentityCopy.memberRole = this.memberRole;
236 cloudIdentityCopy.tenantMetadata = this.tenantMetadata;
237 cloudIdentityCopy.identityServerType = this.identityServerType;
238 cloudIdentityCopy.identityAuthenticationType = this.identityAuthenticationType;
240 return cloudIdentityCopy;
244 public int hashCode() {
245 final int prime = 31;
247 result = prime * result + ((adminTenant == null) ? 0 : adminTenant.hashCode());
248 result = prime * result + ((id == null) ? 0 : id.hashCode());
249 result = prime * result + ((identityUrl == null) ? 0 : identityUrl.hashCode());
250 result = prime * result + ((memberRole == null) ? 0 : memberRole.hashCode());
251 result = prime * result + ((msoId == null) ? 0 : msoId.hashCode());
252 result = prime * result + ((msoPass == null) ? 0 : msoPass.hashCode());
253 result = prime * result + ((tenantMetadata == null) ? 0 : tenantMetadata.hashCode());
254 result = prime * result + ((identityServerType == null) ? 0 : identityServerType.hashCode());
255 result = prime * result + ((identityAuthenticationType == null) ? 0 : identityAuthenticationType.hashCode());
260 public boolean equals(Object obj) {
265 if (getClass() != obj.getClass())
267 CloudIdentity other = (CloudIdentity) obj;
268 if (adminTenant == null) {
269 if (other.adminTenant != null)
271 } else if (!adminTenant.equals(other.adminTenant))
274 if (other.id != null)
276 } else if (!id.equals(other.id))
278 if (identityUrl == null) {
279 if (other.identityUrl != null)
281 } else if (!identityUrl.equals(other.identityUrl))
283 if (memberRole == null) {
284 if (other.memberRole != null)
286 } else if (!memberRole.equals(other.memberRole))
289 if (other.msoId != null)
291 } else if (!msoId.equals(other.msoId))
293 if (msoPass == null) {
294 if (other.msoPass != null)
296 } else if (!msoPass.equals(other.msoPass))
298 if (tenantMetadata == null) {
299 if (other.tenantMetadata != null)
301 } else if (!tenantMetadata.equals(other.tenantMetadata))
303 if (identityServerType == null) {
304 if (other.getIdentityServerType() != null)
306 } else if (!identityServerType.equals(other.getIdentityServerType()))
308 if (identityAuthenticationType == null) {
309 if (other.getIdentityAuthenticationType() != null)
311 } else if (!identityAuthenticationType.equals(other.getIdentityAuthenticationType()))