2 * ============LICENSE_START=======================================================
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
12 * http://www.apache.org/licenses/LICENSE-2.0
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=========================================================
21 * ECOMP is a trademark and service mark of AT&T Intellectual Property.
23 package org.openecomp.sparky.security.portal.config;
25 import java.util.Properties;
27 import org.openecomp.sparky.util.ConfigHelper;
28 import org.openecomp.sparky.util.Encryptor;
29 import org.openecomp.sparky.viewandinspect.config.TierSupportUiConstants;
32 * Provides Portal authentication configuration.
34 public class PortalAuthenticationConfig {
36 private String username;
37 private String password;
38 private boolean isOnapEnabled;
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;
45 private PortalAuthenticationConfig() {
46 // Prevent instantiation
49 private static class PortalAuthenticationConfigHelper {
50 private static final PortalAuthenticationConfig INSTANCE = new PortalAuthenticationConfig();
52 private PortalAuthenticationConfigHelper() {
58 * Get a singleton instance of the configuration.
62 public static PortalAuthenticationConfig getInstance() {
63 PortalAuthenticationConfigHelper.INSTANCE.load();
64 return PortalAuthenticationConfigHelper.INSTANCE;
67 public String getUsername() {
71 public String getPassword() {
72 Encryptor encryptor = new Encryptor();
73 return encryptor.decryptValue(password);
76 public boolean getIsOnapEnabled() {
81 * Reload the Portal authentication properties from the classpath.
83 public void reload() {
88 * Load the Portal authentication properties from the classpath.
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"));