1 package org.openecomp.portalapp.login;
3 import javax.servlet.http.Cookie;
4 import javax.servlet.http.HttpServletRequest;
5 import javax.servlet.http.HttpServletResponse;
7 import org.onap.policy.common.logging.flexlogger.FlexLogger;
8 import org.onap.policy.common.logging.flexlogger.Logger;
9 import org.openecomp.portalsdk.core.auth.LoginStrategy;
10 import org.openecomp.portalsdk.core.onboarding.exception.PortalAPIException;
11 import org.openecomp.portalsdk.core.onboarding.util.CipherUtil;
12 import org.openecomp.portalsdk.core.onboarding.util.PortalApiConstants;
13 import org.openecomp.portalsdk.core.onboarding.util.PortalApiProperties;
14 import org.springframework.web.servlet.ModelAndView;
16 public class LoginStrategyImpl extends LoginStrategy {
18 private static final Logger LOGGER = FlexLogger.getLogger(LoginStrategyImpl.class);
21 public ModelAndView doLogin(HttpServletRequest request, HttpServletResponse response) throws Exception {
22 // 'login' for opensource is same as 'external' login.
23 return doExternalLogin(request, response);
27 public String getUserId(HttpServletRequest request) throws PortalAPIException {
28 // Check ONAP Portal cookie
29 if (!isLoginCookieExist(request))
34 userid = getUserIdFromCookie(request);
35 } catch (Exception e) {
36 LOGGER.error("Exception Occured" + e);
41 private static String getUserIdFromCookie(HttpServletRequest request) throws PortalAPIException {
43 Cookie[] cookies = request.getCookies();
44 Cookie userIdcookie = null;
46 for (Cookie cookie : cookies)
47 if (cookie.getName().equals(USER_ID))
48 userIdcookie = cookie;
49 if (userIdcookie != null) {
51 userId = CipherUtil.decrypt(userIdcookie.getValue(),
52 PortalApiProperties.getProperty(PortalApiConstants.Decryption_Key));
53 } catch (Exception e) {
54 throw new PortalAPIException(e);
61 private static boolean isLoginCookieExist(HttpServletRequest request) {
62 Cookie ep = getCookie(request, EP_SERVICE);
66 private static Cookie getCookie(HttpServletRequest request, String cookieName) {
67 Cookie[] cookies = request.getCookies();
69 for (Cookie cookie : cookies)
70 if (cookie.getName().equals(cookieName))