summaryrefslogtreecommitdiffstats
path: root/juju/juju-vnfmadapter/Juju-vnfmadapterService/service/src/main/java/org/openo/nfvo/jujuvnfmadapter/common/servicetoken/VNFAuthConfigInfo.java
blob: 4e7c13ef505fcd36c50648e4d4ae4f2c7446fc8a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
/*
 * Copyright 2016 Huawei Technologies Co., Ltd.
 *
 * 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.
 */

package org.openo.nfvo.jujuvnfmadapter.common.servicetoken;

import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * 
 * Vnf Authentication configuration information class.<br>
 * <p>
 * </p>
 * 
 * @author
 * @version     NFVO 0.5  Sep 12, 2016
 */
public class VNFAuthConfigInfo {

    private static final Logger LOG = LoggerFactory.getLogger(VNFAuthConfigInfo.class);

    private static final String AUTH_CONFIG_FILE = "identity.VNFProperties";

    private static VNFAuthConfigInfo authConfig = new VNFAuthConfigInfo();

    private static long lastModify = 0L;

    private String vnfUserName;

    private String vnfEncryptedPW;

    private String vnfDomain;

    private String vnfResourceDomain;

    private String defaultDomain;

    private VNFAuthConfigInfo() {
        Properties vnfProp = new Properties();
        InputStream authIn = null;

        try {
            if(isVNFProModified(getAuthCofigPath())) {
                authIn = new FileInputStream(getAuthCofigPath());

                vnfProp.load(authIn);
                vnfUserName = vnfProp.getProperty("name");
                vnfEncryptedPW = vnfProp.getProperty("value");
                vnfDomain = vnfProp.getProperty("vnfDomain");
                vnfResourceDomain = vnfProp.getProperty("vnfResourceDomain");
                defaultDomain = vnfProp.getProperty("defaultDomain");
                authIn.close();
            }

        } catch(IOException e) {
            LOG.error("loadAuthConfig can't find config file>> e = {}", e);
        } finally {
            try {
                if(authIn != null) {

                    authIn.close();
                }
            } catch(IOException e) {
                LOG.error("loadAuthConfig can't find config file>> e = {}", e);
            }

            }

        }

    private String getAuthCofigPath() {
        return AUTH_CONFIG_FILE;
    }
    
    public static VNFAuthConfigInfo getInstance() {
        return authConfig;
    }

    public String getUserName() {
        return vnfUserName;
    }

    public String getEncryptedPW() {
        return vnfEncryptedPW;
    }

    public String getDomain() {
        return vnfDomain;
    }

    public void setUserName(String vnfuserName) {
        this.vnfUserName = vnfuserName;
    }

    public void setEncryptedPW(String vnfencryptedPW) {
        this.vnfEncryptedPW = vnfencryptedPW;
    }

    public void setDomain(String vnfDomain) {
        this.vnfDomain = vnfDomain;
    }

    public String getResourceDomain() {
        return vnfResourceDomain;
    }

    public void setResourceDomain(String vnfResourceDomain) {
        this.vnfResourceDomain = vnfResourceDomain;
    }

    public String getDefaultDomain() {
        return defaultDomain;
    }

    public void setDefaultDomain(String defaultDomain) {
        this.defaultDomain = defaultDomain;
    }

    private static boolean isVNFProModified(String filename) {
        boolean returnValue = false;
        File inputFile = new File(filename);
        if(inputFile.lastModified() > lastModify) {
            lastModify = inputFile.lastModified();
            returnValue = true;
        }
        return returnValue;
    }
}