X-Git-Url: https://gerrit.onap.org/r/gitweb?a=blobdiff_plain;f=ecomp-portal-BE-common%2Fsrc%2Fmain%2Fjava%2Forg%2Fonap%2Fportalapp%2Fportal%2Futils%2FMusicCookieCsrfTokenRepository.java;h=891f6d78d0f658a8253110f487ce0e689f480a24;hb=refs%2Fchanges%2F91%2F101891%2F3;hp=988b97a542558e617c5137f3e2562e9cc3c20b0f;hpb=6e50276a42ab82cfe34ced9cf97e545283f37f2a;p=portal.git diff --git a/ecomp-portal-BE-common/src/main/java/org/onap/portalapp/portal/utils/MusicCookieCsrfTokenRepository.java b/ecomp-portal-BE-common/src/main/java/org/onap/portalapp/portal/utils/MusicCookieCsrfTokenRepository.java index 988b97a5..891f6d78 100644 --- a/ecomp-portal-BE-common/src/main/java/org/onap/portalapp/portal/utils/MusicCookieCsrfTokenRepository.java +++ b/ecomp-portal-BE-common/src/main/java/org/onap/portalapp/portal/utils/MusicCookieCsrfTokenRepository.java @@ -50,6 +50,20 @@ import org.springframework.security.web.csrf.CsrfTokenRepository; import org.springframework.security.web.csrf.DefaultCsrfToken; import org.springframework.util.StringUtils; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.databind.JsonMappingException; +import com.fasterxml.jackson.databind.ObjectMapper; + +import org.onap.portalsdk.core.onboarding.exception.CipherUtilException; +import org.onap.portalsdk.core.onboarding.util.CipherUtil; + +import java.io.IOException; +import java.io.UnsupportedEncodingException; +import java.net.URLDecoder; +import java.util.HashMap; +import java.util.Map; +import org.onap.portalapp.portal.utils.EPCommonSystemProperties; + public final class MusicCookieCsrfTokenRepository implements CsrfTokenRepository { static final String CSRF_COOKIE_NAME = "XSRF-TOKEN"; @@ -111,12 +125,22 @@ public final class MusicCookieCsrfTokenRepository implements CsrfTokenRepository return new MusicCookieCsrfTokenRepository(result); } - private String getSessionIdFromCookie (HttpServletRequest request){ + private String getSessionIdFromCookie (HttpServletRequest request) throws JsonParseException, JsonMappingException, UnsupportedEncodingException, IOException, CipherUtilException{ Cookie cookies[] = request.getCookies(); if (cookies != null) { for (Cookie cookie : cookies) { if (EP_SERVICE.equals(cookie.getName())) { - return cookie.getValue(); + ObjectMapper mapper = new ObjectMapper(); + Map epServiceCookieValueMap = mapper.readValue(URLDecoder.decode(cookie.getValue(), "UTF-8"),HashMap.class); + String sessionId = null; + if(epServiceCookieValueMap!=null) { + String multifactorauthfrontendurl = EPCommonSystemProperties.getProperty(EPCommonSystemProperties.MULTI_FACTOR_AUTH_FRONTEND_URL); + String encryptedJSessionId = epServiceCookieValueMap.get(multifactorauthfrontendurl); + if(encryptedJSessionId != null) { + sessionId = CipherUtil.decryptPKC(encryptedJSessionId); + } + } + return sessionId; } } }