Catalog alignment
[sdc.git] / utils / webseal-simulator / src / main / java / org / openecomp / sdc / webseal / simulator / conf / Conf.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * SDC
4  * ================================================================================
5  * Copyright (C) 2019 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
10  * 
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  * 
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=========================================================
19  */
20
21 package org.openecomp.sdc.webseal.simulator.conf;
22
23 import com.typesafe.config.Config;
24 import com.typesafe.config.ConfigFactory;
25 import org.openecomp.sdc.webseal.simulator.User;
26
27 import java.io.File;
28 import java.util.HashMap;
29 import java.util.List;
30 import java.util.Map;
31
32 public class Conf {
33
34         private static Conf conf = new Conf();
35         private String feHost;
36         private Map<String,User> users = new HashMap<String,User>();
37     private String portalCookieName;
38
39     private void setPortalCookieName(String portalCookieName) {
40         this.portalCookieName = portalCookieName;
41     }
42
43     public String getPortalCookieName() {
44         return portalCookieName;
45     }
46
47         private Conf(){ 
48                 initConf();
49         }
50         
51         private void initConf() {
52                 try{
53                         String confPath = System.getProperty("config.resource");                        
54                         if (confPath == null){
55                                 System.out.println("config.resource is empty - goint to get it from config.home");
56                                 confPath = System.getProperty("config.home") + "/webseal.conf";
57                         }
58                         System.out.println("confPath=" + confPath );
59                         Config confFile = ConfigFactory.parseFileAnySyntax(new File(confPath));
60                         Config resolve = confFile.resolve();            
61                         setFeHost(resolve.getString("webseal.fe"));
62                         setPortalCookieName(resolve.getString("webseal.portalCookieName"));
63                         List<? extends Config> list = resolve.getConfigList("webseal.users");
64
65                         for (Config conf : list  ){
66                                 String userId = conf.getString("userId");
67                                 String password = conf.getString("password");
68                                 String firstName = conf.getString("firstName");
69                                 String lastName = conf.getString("lastName");
70                                 String email = conf.getString("email");
71                                 String role = conf.getString("role");
72                                 users.put(userId,new User(firstName,lastName,email,userId,role,password));                              
73                         }
74                                         
75                 }catch(Exception e){
76                         e.printStackTrace();
77                 }
78         }
79
80         public static Conf getInstance(){
81                 return conf;
82         }
83
84         public String getFeHost() {
85                 return feHost;
86         }
87
88         public void setFeHost(String feHost) {
89                 this.feHost = feHost;
90         }
91         
92         public Map<String,User> getUsers() {
93                 return users;
94         }       
95         
96 }