Update gvnfm-driver .gitreview file
[vfc/nfvo/driver/vnfm/gvnfm.git] / juju / juju-vnfmadapter / Juju-vnfmadapterService / service / src / main / java / org / openo / nfvo / jujuvnfmadapter / common / servicetoken / VNFAuthConfigInfo.java
1 /*
2  * Copyright 2016 Huawei Technologies Co., Ltd.
3  *
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
7  *
8  *     http://www.apache.org/licenses/LICENSE-2.0
9  *
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.
15  */
16
17 package org.openo.nfvo.jujuvnfmadapter.common.servicetoken;
18
19 import java.io.File;
20 import java.io.FileInputStream;
21 import java.io.IOException;
22 import java.io.InputStream;
23 import java.util.Properties;
24
25 import org.slf4j.Logger;
26 import org.slf4j.LoggerFactory;
27
28 /**
29  * 
30  * Vnf Authentication configuration information class.<br>
31  * <p>
32  * </p>
33  * 
34  * @author
35  * @version     NFVO 0.5  Sep 12, 2016
36  */
37 public class VNFAuthConfigInfo {
38
39     private static final Logger LOG = LoggerFactory.getLogger(VNFAuthConfigInfo.class);
40
41     private static final String AUTH_CONFIG_FILE = "identity.VNFProperties";
42
43     private static VNFAuthConfigInfo authConfig = new VNFAuthConfigInfo();
44
45     private static long lastModify = 0L;
46
47     private String vnfUserName;
48
49     private String vnfEncryptedPW;
50
51     private String vnfDomain;
52
53     private String vnfResourceDomain;
54
55     private String defaultDomain;
56
57     private VNFAuthConfigInfo() {
58         Properties vnfProp = new Properties();
59         InputStream authIn = null;
60
61         try {
62             if(isVNFProModified(getAuthCofigPath())) {
63                 authIn = new FileInputStream(getAuthCofigPath());
64
65                 vnfProp.load(authIn);
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");
71                 authIn.close();
72             }
73
74         } catch(IOException e) {
75             LOG.error("loadAuthConfig can't find config file>> e = {}", e);
76         } finally {
77             try {
78                 if(authIn != null) {
79
80                     authIn.close();
81                 }
82             } catch(IOException e) {
83                 LOG.error("loadAuthConfig can't find config file>> e = {}", e);
84             }
85
86             }
87
88         }
89
90     private String getAuthCofigPath() {
91         return AUTH_CONFIG_FILE;
92     }
93     
94     public static VNFAuthConfigInfo getInstance() {
95         return authConfig;
96     }
97
98     public String getUserName() {
99         return vnfUserName;
100     }
101
102     public String getEncryptedPW() {
103         return vnfEncryptedPW;
104     }
105
106     public String getDomain() {
107         return vnfDomain;
108     }
109
110     public void setUserName(String vnfuserName) {
111         this.vnfUserName = vnfuserName;
112     }
113
114     public void setEncryptedPW(String vnfencryptedPW) {
115         this.vnfEncryptedPW = vnfencryptedPW;
116     }
117
118     public void setDomain(String vnfDomain) {
119         this.vnfDomain = vnfDomain;
120     }
121
122     public String getResourceDomain() {
123         return vnfResourceDomain;
124     }
125
126     public void setResourceDomain(String vnfResourceDomain) {
127         this.vnfResourceDomain = vnfResourceDomain;
128     }
129
130     public String getDefaultDomain() {
131         return defaultDomain;
132     }
133
134     public void setDefaultDomain(String defaultDomain) {
135         this.defaultDomain = defaultDomain;
136     }
137
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();
143             returnValue = true;
144         }
145         return returnValue;
146     }
147 }