Fix security risk 'Improper Input Validation'
[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 java.io.File;
26 import java.util.HashMap;
27 import java.util.List;
28 import java.util.Map;
29 import lombok.Getter;
30 import lombok.Setter;
31 import org.openecomp.sdc.webseal.simulator.User;
32
33 @Getter
34 @Setter
35 public class Conf {
36
37     private static Conf conf = new Conf();
38     private String feHost;
39     private Map<String, User> users = new HashMap<String, User>();
40     private String portalCookieName;
41     private String permittedAncestors; // Space separated list of permitted ancestors
42     private String dataValidatorFilterExcludedUrls; // Comma separated list of excluded URLs by the DataValidatorFilter
43
44     private Conf() {
45         initConf();
46     }
47
48     private void initConf() {
49         try {
50             String confPath = System.getProperty("config.resource");
51             if (confPath == null) {
52                 System.out.println("config.resource is empty - goint to get it from config.home");
53                 confPath = System.getProperty("config.home") + "/webseal.conf";
54             }
55             System.out.println("confPath=" + confPath);
56             final Config confFile = ConfigFactory.parseFileAnySyntax(new File(confPath));
57             final Config resolve = confFile.resolve();
58             setFeHost(resolve.getString("webseal.fe"));
59             setPortalCookieName(resolve.getString("webseal.portalCookieName"));
60             final List<? extends Config> list = resolve.getConfigList("webseal.users");
61
62             for (final Config config : list) {
63                 String userId = config.getString("userId");
64                 String password = config.getString("password");
65                 String firstName = config.getString("firstName");
66                 String lastName = config.getString("lastName");
67                 String email = config.getString("email");
68                 String role = config.getString("role");
69                 users.put(userId, new User(firstName, lastName, email, userId, role, password));
70             }
71
72         } catch (Exception e) {
73             e.printStackTrace();
74         }
75     }
76
77     public static Conf getInstance() {
78         return conf;
79     }
80
81 }