Changing the license and trademark
[aai/sparky-be.git] / src / main / java / org / openecomp / 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.openecomp.sparky.security.portal.config;
24
25 import java.util.Properties;
26
27 import org.openecomp.sparky.util.ConfigHelper;
28 import org.openecomp.sparky.util.Encryptor;
29 import org.openecomp.sparky.viewandinspect.config.TierSupportUiConstants;
30
31 /**
32  * Provides Portal authentication configuration.
33  */
34 public class PortalAuthenticationConfig {
35
36   private String username;
37   private String password;
38   private boolean isOnapEnabled;
39
40   public static final String PROP_USERNAME = "username";
41   public static final String PROP_PASSWORD = "password"; // NOSONAR
42   public static final String PROP_IS_ONAP_ENABLED = "onap_enabled"; // NOSONAR
43   private static final String AUTHENTICATION_CONFIG_FILE = TierSupportUiConstants.PORTAL_AUTHENTICATION_FILE_LOCATION;
44
45   private PortalAuthenticationConfig() {
46     // Prevent instantiation
47   }
48
49   private static class PortalAuthenticationConfigHelper {
50     private static final PortalAuthenticationConfig INSTANCE = new PortalAuthenticationConfig();
51
52     private PortalAuthenticationConfigHelper() {
53       // Deliberately empty
54     }
55   }
56
57   /**
58    * Get a singleton instance of the configuration.
59    *
60    * @return
61    */
62   public static PortalAuthenticationConfig getInstance() {
63     PortalAuthenticationConfigHelper.INSTANCE.load();
64     return PortalAuthenticationConfigHelper.INSTANCE;
65   }
66
67   public String getUsername() {
68     return username;
69   }
70
71   public String getPassword() {
72     Encryptor encryptor = new Encryptor();
73     return encryptor.decryptValue(password);
74   }
75   
76   public boolean getIsOnapEnabled() {
77     return isOnapEnabled;
78   }
79
80   /**
81    * Reload the Portal authentication properties from the classpath.
82    */
83   public void reload() {
84     load();
85   }
86
87   /**
88    * Load the Portal authentication properties from the classpath.
89    */
90   private void load() {
91     Properties props = ConfigHelper.loadConfigFromExplicitPath(AUTHENTICATION_CONFIG_FILE);
92     username = props.getProperty(PROP_USERNAME);
93     password = props.getProperty(PROP_PASSWORD);
94     isOnapEnabled = Boolean.parseBoolean(props.getProperty(PROP_IS_ONAP_ENABLED, "true"));
95   }
96 }