2 * Copyright 2016 Huawei Technologies Co., Ltd.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
17 package org.openo.nfvo.jujuvnfmadapter.common.servicetoken;
20 import java.io.FileInputStream;
21 import java.io.IOException;
22 import java.io.InputStream;
23 import java.util.Properties;
25 import org.slf4j.Logger;
26 import org.slf4j.LoggerFactory;
30 * Vnf Authentication configuration information class.<br>
35 * @version NFVO 0.5 Sep 12, 2016
37 public class VNFAuthConfigInfo {
39 private static final Logger LOG = LoggerFactory.getLogger(VNFAuthConfigInfo.class);
41 private static final String AUTH_CONFIG_FILE = "identity.VNFProperties";
43 private static VNFAuthConfigInfo authConfig = new VNFAuthConfigInfo();
45 private static long lastModify = 0L;
47 private String vnfUserName;
49 private String vnfEncryptedPW;
51 private String vnfDomain;
53 private String vnfResourceDomain;
55 private String defaultDomain;
57 private VNFAuthConfigInfo() {
58 Properties vnfProp = new Properties();
59 InputStream authIn = null;
62 if(isVNFProModified(getAuthCofigPath())) {
63 authIn = new FileInputStream(getAuthCofigPath());
66 vnfUserName = vnfProp.getProperty("name");
67 vnfEncryptedPW = vnfProp.getProperty("value");
68 vnfDomain = vnfProp.getProperty("vnfDomain");
69 vnfResourceDomain = vnfProp.getProperty("vnfResourceDomain");
70 defaultDomain = vnfProp.getProperty("defaultDomain");
74 } catch(IOException e) {
75 LOG.error("loadAuthConfig can't find config file>> e = {}", e);
82 } catch(IOException e) {
83 LOG.error("loadAuthConfig can't find config file>> e = {}", e);
90 private String getAuthCofigPath() {
91 return AUTH_CONFIG_FILE;
94 public static VNFAuthConfigInfo getInstance() {
98 public String getUserName() {
102 public String getEncryptedPW() {
103 return vnfEncryptedPW;
106 public String getDomain() {
110 public void setUserName(String vnfuserName) {
111 this.vnfUserName = vnfuserName;
114 public void setEncryptedPW(String vnfencryptedPW) {
115 this.vnfEncryptedPW = vnfencryptedPW;
118 public void setDomain(String vnfDomain) {
119 this.vnfDomain = vnfDomain;
122 public String getResourceDomain() {
123 return vnfResourceDomain;
126 public void setResourceDomain(String vnfResourceDomain) {
127 this.vnfResourceDomain = vnfResourceDomain;
130 public String getDefaultDomain() {
131 return defaultDomain;
134 public void setDefaultDomain(String defaultDomain) {
135 this.defaultDomain = defaultDomain;
138 private static boolean isVNFProModified(String filename) {
139 boolean returnValue = false;
140 File inputFile = new File(filename);
141 if(inputFile.lastModified() > lastModify) {
142 lastModify = inputFile.lastModified();