X-Git-Url: https://gerrit.onap.org/r/gitweb?a=blobdiff_plain;f=ONAP-SDK-APP%2Fsrc%2Fmain%2Fjava%2Forg%2Fopenecomp%2Fportalapp%2Flogin%2FLoginStrategyImpl.java;h=3b38f1d8e71747c4f67e2c8fc6b7322a5bad9a97;hb=775f45908025e46a40c9c147fca2066af5c8c5b8;hp=13d8836ea4669d3795e58ac02c46e4a98548d55e;hpb=80f072f60509ef3a35369a60857fe05f6c2a993a;p=policy%2Fengine.git diff --git a/ONAP-SDK-APP/src/main/java/org/openecomp/portalapp/login/LoginStrategyImpl.java b/ONAP-SDK-APP/src/main/java/org/openecomp/portalapp/login/LoginStrategyImpl.java index 13d8836ea..3b38f1d8e 100644 --- a/ONAP-SDK-APP/src/main/java/org/openecomp/portalapp/login/LoginStrategyImpl.java +++ b/ONAP-SDK-APP/src/main/java/org/openecomp/portalapp/login/LoginStrategyImpl.java @@ -1,3 +1,22 @@ +/*- + * ================================================================================ + * ONAP Portal SDK + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ================================================================================ + */ package org.openecomp.portalapp.login; import javax.servlet.http.Cookie; @@ -7,10 +26,10 @@ import javax.servlet.http.HttpServletResponse; import org.onap.policy.common.logging.flexlogger.FlexLogger; import org.onap.policy.common.logging.flexlogger.Logger; import org.openecomp.portalsdk.core.auth.LoginStrategy; +import org.openecomp.portalsdk.core.logging.logic.EELFLoggerDelegate; import org.openecomp.portalsdk.core.onboarding.exception.PortalAPIException; import org.openecomp.portalsdk.core.onboarding.util.CipherUtil; -import org.openecomp.portalsdk.core.onboarding.util.PortalApiConstants; -import org.openecomp.portalsdk.core.onboarding.util.PortalApiProperties; +import org.openecomp.portalsdk.core.util.SystemProperties; import org.springframework.web.servlet.ModelAndView; public class LoginStrategyImpl extends LoginStrategy { @@ -39,23 +58,21 @@ public class LoginStrategyImpl extends LoginStrategy { } private static String getUserIdFromCookie(HttpServletRequest request) throws PortalAPIException { - String userId = ""; - Cookie[] cookies = request.getCookies(); - Cookie userIdcookie = null; - if (cookies != null) - for (Cookie cookie : cookies) - if (cookie.getName().equals(USER_ID)) - userIdcookie = cookie; - if (userIdcookie != null) { - try { - userId = CipherUtil.decrypt(userIdcookie.getValue(), - PortalApiProperties.getProperty(PortalApiConstants.Decryption_Key)); - } catch (Exception e) { - throw new PortalAPIException(e); - } - } - return userId; - + String userId = ""; + Cookie userIdCookie = getCookie(request, USER_ID); + if (userIdCookie != null) { + final String cookieValue = userIdCookie.getValue(); + if (!SystemProperties.containsProperty(SystemProperties.Decryption_Key)) + throw new IllegalStateException("Failed to find property " + SystemProperties.Decryption_Key); + final String decryptionKey = SystemProperties.getProperty(SystemProperties.Decryption_Key); + try { + userId = CipherUtil.decrypt(cookieValue, decryptionKey); + LOGGER.debug("getUserIdFromCookie: decrypted as {}" +userId); + } catch (Exception e) { + LOGGER.error("Exception Occured in getUserIdFromCookie" + e); + } + } + return userId; } private static boolean isLoginCookieExist(HttpServletRequest request) {