Adding UI extensibility
[aai/sparky-be.git] / src / main / java / org / onap / aai / sparky / security / portal / config / PortalAuthenticationConfig.java
1 /**
2  * ============LICENSE_START=======================================================
3  * org.onap.aai
4  * ================================================================================
5  * Copyright © 2017 AT&T Intellectual Property. All rights reserved.
6  * Copyright © 2017 Amdocs
7  * ================================================================================
8  * Licensed under the Apache License, Version 2.0 (the "License");
9  * you may not use this file except in compliance with the License.
10  * You may obtain a copy of the License at
11  *
12  *       http://www.apache.org/licenses/LICENSE-2.0
13  *
14  * Unless required by applicable law or agreed to in writing, software
15  * distributed under the License is distributed on an "AS IS" BASIS,
16  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17  * See the License for the specific language governing permissions and
18  * limitations under the License.
19  * ============LICENSE_END=========================================================
20  *
21  * ECOMP is a trademark and service mark of AT&T Intellectual Property.
22  */
23 package org.onap.aai.sparky.security.portal.config;
24
25 import java.util.Properties;
26
27 import org.onap.aai.sparky.util.ConfigHelper;
28 import org.onap.aai.sparky.util.Encryptor;
29 import org.onap.aai.sparky.viewandinspect.config.TierSupportUiConstants;
30
31
32 /**
33  * Provides Portal authentication configuration.
34  */
35 public class PortalAuthenticationConfig {
36
37   private String username;
38   private String password;
39   private boolean isOnapEnabled;
40
41   public static final String PROP_USERNAME = "username";
42   public static final String PROP_PASSWORD = "password"; // NOSONAR
43   public static final String PROP_IS_ONAP_ENABLED = "onap_enabled"; // NOSONAR
44   private static final String AUTHENTICATION_CONFIG_FILE =
45       TierSupportUiConstants.PORTAL_AUTHENTICATION_FILE_LOCATION;
46
47   private PortalAuthenticationConfig() {
48     // Prevent instantiation
49   }
50
51   private static class PortalAuthenticationConfigHelper {
52     private static final PortalAuthenticationConfig INSTANCE = new PortalAuthenticationConfig();
53
54     private PortalAuthenticationConfigHelper() {
55       // Deliberately empty
56     }
57   }
58
59   /**
60    * Get a singleton instance of the configuration.
61    *
62    * @return
63    */
64   public static PortalAuthenticationConfig getInstance() {
65     PortalAuthenticationConfigHelper.INSTANCE.load();
66     return PortalAuthenticationConfigHelper.INSTANCE;
67   }
68
69   public String getUsername() {
70     return username;
71   }
72
73   public String getPassword() {
74     Encryptor encryptor = new Encryptor();
75     return encryptor.decryptValue(password);
76   }
77
78   public boolean getIsOnapEnabled() {
79     return isOnapEnabled;
80   }
81
82   /**
83    * Reload the Portal authentication properties from the classpath.
84    */
85   public void reload() {
86     load();
87   }
88
89   /**
90    * Load the Portal authentication properties from the classpath.
91    */
92   private void load() {
93     Properties props = ConfigHelper.loadConfigFromExplicitPath(AUTHENTICATION_CONFIG_FILE);
94     username = props.getProperty(PROP_USERNAME);
95     password = props.getProperty(PROP_PASSWORD);
96     isOnapEnabled = Boolean.parseBoolean(props.getProperty(PROP_IS_ONAP_ENABLED, "true"));
97   }
98 }