2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright © 2017-2018 AT&T Intellectual Property. All rights reserved.
6 * Copyright © 2017-2018 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 package org.onap.aai.sparky.security.portal.config;
24 import java.util.Properties;
26 import org.onap.aai.cl.api.Logger;
27 import org.onap.aai.cl.eelf.LoggerFactory;
28 import org.onap.aai.sparky.logging.AaiUiMsgs;
29 import org.onap.aai.sparky.security.CookieDecryptor;
30 import org.onap.aai.sparky.util.ConfigHelper;
31 import org.onap.aai.sparky.util.Encryptor;
32 import org.onap.aai.sparky.viewandinspect.config.SparkyConstants;
36 * Provides Portal authentication configuration.
38 public class PortalAuthenticationConfig {
40 private String username;
41 private String password;
42 private boolean isOnapEnabled;
43 private String userIdCookieName;
44 private CookieDecryptor cookieDecryptor;
45 private String cookieDecryptorClassName;
47 public static final String PROP_USERNAME = "username";
48 public static final String PROP_PASSWORD = "password"; // NOSONAR
49 public static final String PROP_IS_ONAP_ENABLED = "onap_enabled"; // NOSONAR
50 public static final String PROP_USERID_COOKIE_NAME = "onap.user_id_cookie_name"; // NOSONAR
51 private static final String AUTHENTICATION_CONFIG_FILE = SparkyConstants.PORTAL_AUTHENTICATION_FILE_LOCATION;
52 public static final String PROP_COOKIEDECRYPTORCLASSNAME = "cookie_decryptor_classname";
53 private static final Logger LOG = LoggerFactory.getInstance().getLogger(PortalAuthenticationConfig.class);
55 private PortalAuthenticationConfig() {
56 // Prevent instantiation
59 private static class PortalAuthenticationConfigHelper {
60 private static final PortalAuthenticationConfig INSTANCE = new PortalAuthenticationConfig();
62 private PortalAuthenticationConfigHelper() {
68 * Get a singleton instance of the configuration.
72 public static PortalAuthenticationConfig getInstance() {
73 PortalAuthenticationConfigHelper.INSTANCE.load();
74 return PortalAuthenticationConfigHelper.INSTANCE;
77 public String getUsername() {
81 public String getPassword() {
82 Encryptor encryptor = new Encryptor();
83 return encryptor.decryptValue(password);
86 public boolean getIsOnapEnabled() {
89 public String getcookieDecryptorClassName() {
90 return cookieDecryptorClassName;
92 public String getUserIdCookieName() {
93 return userIdCookieName;
96 public void setUserIdCookieName(String userIdCookieName) {
97 this.userIdCookieName = userIdCookieName;
100 * Reload the Portal authentication properties from the classpath.
102 public void reload() {
107 * Load the Portal authentication properties from the classpath.
109 private void load() {
110 Properties props = ConfigHelper.loadConfigFromExplicitPath(AUTHENTICATION_CONFIG_FILE);
111 username = props.getProperty(PROP_USERNAME);
112 password = props.getProperty(PROP_PASSWORD);
113 isOnapEnabled = Boolean.parseBoolean(props.getProperty(PROP_IS_ONAP_ENABLED, "true"));
114 userIdCookieName = props.getProperty(PROP_USERID_COOKIE_NAME);
115 cookieDecryptorClassName= props.getProperty(PROP_COOKIEDECRYPTORCLASSNAME);
118 public CookieDecryptor getCookieDecryptor() throws ClassNotFoundException{
120 Class cookieDecrypterClass = Class.forName(cookieDecryptorClassName);
122 cookieDecryptor = (CookieDecryptor) cookieDecrypterClass.newInstance();
123 } catch (InstantiationException | IllegalAccessException e) {
124 LOG.error(AaiUiMsgs.DECRYPTION_ERROR,"Unable to instantiate Cookie Decryptor Class");
126 return cookieDecryptor;