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;
23 import javax.servlet.http.Cookie;
24 import javax.servlet.http.HttpServletRequest;
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.portal.config.PortalAuthenticationConfig;
30 import org.onap.portalsdk.core.onboarding.exception.CipherUtilException;
31 import org.onap.portalsdk.core.onboarding.util.CipherUtil;
32 import org.onap.portalsdk.core.onboarding.util.PortalApiProperties;
35 * Provides authentication services for onboarded ECOMP applications.
37 public class EcompSso {
39 public static final String EP_SERVICE = "EPService";
40 public static final String CSP_COOKIE_NAME = "csp_cookie_name";
41 public static final String CSP_GATE_KEEPER_PROD_KEY = "csp_gate_keeper_prod_key";
42 public static final String ONAP_ENABLED = "ONAP_ENABLED";
43 private static final Logger LOG = LoggerFactory.getInstance().getLogger(EcompSso.class);
46 * Searches the request for a cookie with the specified name.
50 * @return Cookie, or null if not found.
52 public static Cookie getCookie(HttpServletRequest request, String cookieName) {
53 Cookie[] cookies = request.getCookies();
55 for (Cookie cookie : cookies) {
56 if (cookie.getName().equals(cookieName)) {
65 * Validates whether the ECOMP Portal sign-on process has completed, which relies the AT&T Global
66 * Log On single-sign on process. Checks for the ECOMP cookie (see {@link #EP_SERVICE}). If found,
67 * then searches for a CSP cookie; if not found, for a WebJunction header.
70 * @return ATT UID if the ECOMP cookie is present and the sign-on process established an ATT UID;
73 public static String validateEcompSso(HttpServletRequest request) {
75 boolean isOnapEnabled = PortalAuthenticationConfig.getInstance().getIsOnapEnabled();
77 final String cookieName = PortalAuthenticationConfig.getInstance().getUserIdCookieName();
79 if (cookieName == null) {
80 LOG.debug(AaiUiMsgs.LOGIN_FILTER_DEBUG, "getCspData failed to load cookie");
83 Cookie csp = getCookie(request, cookieName);
85 LOG.debug(AaiUiMsgs.LOGIN_FILTER_DEBUG, "getCspData failed to get cookie " + cookieName);
88 final String cspCookieEncrypted = csp.getValue();
91 uid = PortalAuthenticationConfig.getInstance().getCookieDecryptor()
92 .decryptCookie(cspCookieEncrypted);
93 } catch (ClassNotFoundException e) {
94 LOG.error(AaiUiMsgs.DECRYPTION_ERROR, "Unable to find the Cookie Decryptor Class");
99 String[] cspFields = getCspData(request);
100 if (cspFields != null && cspFields.length > 5)
102 } catch (Exception t) {
103 LOG.info(AaiUiMsgs.LOGIN_FILTER_INFO,
104 "getLoginIdFromCookie failed " + t.getLocalizedMessage());
111 * Searches the specified request for the CSP cookie, decodes it and parses it to a String array.
114 * @return Array of String as parsed from the cookie; null if the cookie is not present; empty
115 * array if the cookie could not be decoded.
117 private static String[] getCspData(HttpServletRequest request) {
118 final String cookieName = PortalApiProperties.getProperty(CSP_COOKIE_NAME);
119 if (cookieName == null) {
120 LOG.debug(AaiUiMsgs.LOGIN_FILTER_DEBUG,
121 "getCspData: Failed to get property " + CSP_COOKIE_NAME);
124 Cookie csp = getCookie(request, cookieName);
126 LOG.debug(AaiUiMsgs.LOGIN_FILTER_DEBUG, "getCspData failed to get cookie " + cookieName);
129 final String cspCookieEncrypted = csp.getValue();
131 String cspCookieDecrypted = null;
133 cspCookieDecrypted = PortalAuthenticationConfig.getInstance().getCookieDecryptor()
134 .decryptCookie(cspCookieEncrypted);
135 return cspCookieDecrypted.split("\\|");
137 } catch (ClassNotFoundException e) {
138 LOG.error(AaiUiMsgs.DECRYPTION_ERROR, "Unable to find the Cookie Decryptor Class");