Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

LPS-197124 - Cookies PreAction setup #3892

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import {
getCookie,
setCookie,
setUserConfigCookie,
userConfigCookieName,
} from '../../js/CookiesUtil';

export default function ({
Expand All @@ -37,12 +36,7 @@ export default function ({

toggleSwitch.addEventListener('click', notifyCookiePreferenceUpdate);

if (getCookie(userConfigCookieName)) {
toggleSwitch.checked = getCookie(cookieKey) === 'true';
}
else {
toggleSwitch.checked = toggleSwitch.dataset.prechecked === 'true';
}
toggleSwitch.checked = getCookie(cookieKey) === 'true';

notifyCookiePreferenceUpdate();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,9 @@ private void _run(
httpServletRequest, httpServletResponse,
CookiesConstants.NAME_USER_CONSENT_CONFIGURED);
}

CookiesManagerUtil.addNecessaryCookies(
httpServletRequest, httpServletResponse);
}

private static final Log _log = LogFactoryUtil.getLog(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -136,23 +136,11 @@ public boolean addCookie(
int consentType, Cookie cookie, HttpServletRequest httpServletRequest,
HttpServletResponse httpServletResponse, boolean secure) {

if (!_SESSION_ENABLE_PERSISTENT_COOKIES) {
return false;
}

if (cookie.getMaxAge() != 0) {
CookiesPreferenceHandlingConfiguration
cookiesPreferenceHandlingConfiguration =
_getCookiesPreferenceHandlingConfiguration(
httpServletRequest);
if (!_SESSION_ENABLE_PERSISTENT_COOKIES ||
((cookie.getMaxAge() != 0) &&
!hasConsentType(consentType, httpServletRequest))) {

if (!cookiesPreferenceHandlingConfiguration.enabled()) {
_deleteCookieConsentCookies(
httpServletRequest, httpServletResponse);
}
else if (!hasConsentType(consentType, httpServletRequest)) {
return false;
}
return false;
}

// LEP-5175
Expand Down Expand Up @@ -202,6 +190,97 @@ else if (!hasConsentType(consentType, httpServletRequest)) {
return true;
}

@Override
public void addNecessaryCookies(
HttpServletRequest httpServletRequest,
HttpServletResponse httpServletResponse) {

CookiesPreferenceHandlingConfiguration
cookiesPreferenceHandlingConfiguration =
_getCookiesPreferenceHandlingConfiguration(httpServletRequest);

boolean cookiesHandlingEnabled =
cookiesPreferenceHandlingConfiguration.enabled();

if (!cookiesHandlingEnabled) {
_deleteCookieConsentCookies(
httpServletRequest, httpServletResponse);
}

boolean explicitConsentMode =
cookiesPreferenceHandlingConfiguration.explicitConsentMode();

boolean functionalConsentCookie = Validator.isNotNull(
_getCookieValue(
CookiesConstants.NAME_CONSENT_TYPE_FUNCTIONAL,
httpServletRequest, true));
boolean necessaryConsentCookie = Validator.isNotNull(
_getCookieValue(
CookiesConstants.NAME_CONSENT_TYPE_NECESSARY,
httpServletRequest, true));
boolean performanceConsentCookie = Validator.isNotNull(
_getCookieValue(
CookiesConstants.NAME_CONSENT_TYPE_PERFORMANCE,
httpServletRequest, true));
boolean personalizationConsentCookie = Validator.isNotNull(
_getCookieValue(
CookiesConstants.NAME_CONSENT_TYPE_PERSONALIZATION,
httpServletRequest, true));

if (!necessaryConsentCookie) {
Cookie necessaryCookie = new Cookie(
CookiesConstants.NAME_CONSENT_TYPE_NECESSARY, "true");

necessaryCookie.setPath(StringPool.SLASH);

addCookie(
CookiesConstants.CONSENT_TYPE_NECESSARY, necessaryCookie,
httpServletRequest, httpServletResponse);
}

String cookieValue = "false";

if (!functionalConsentCookie ||
(!cookiesHandlingEnabled && explicitConsentMode)) {

Cookie functionalCookie = new Cookie(
CookiesConstants.NAME_CONSENT_TYPE_FUNCTIONAL, cookieValue);

functionalCookie.setPath(StringPool.SLASH);

addCookie(
CookiesConstants.CONSENT_TYPE_NECESSARY, functionalCookie,
httpServletRequest, httpServletResponse);
}

if (!performanceConsentCookie ||
(!cookiesHandlingEnabled && explicitConsentMode)) {

Cookie performanceCookie = new Cookie(
CookiesConstants.NAME_CONSENT_TYPE_PERFORMANCE, cookieValue);

performanceCookie.setPath(StringPool.SLASH);

addCookie(
CookiesConstants.CONSENT_TYPE_NECESSARY, performanceCookie,
httpServletRequest, httpServletResponse);
}

if (!personalizationConsentCookie ||
(!cookiesHandlingEnabled && explicitConsentMode)) {

Cookie personalizationCookie = new Cookie(
CookiesConstants.NAME_CONSENT_TYPE_PERSONALIZATION,
cookieValue);

personalizationCookie.setPath(StringPool.SLASH);

addCookie(
CookiesConstants.CONSENT_TYPE_NECESSARY, personalizationCookie,
httpServletRequest, httpServletResponse);
}
}

@Override
public boolean addSupportCookie(
HttpServletRequest httpServletRequest,
Expand Down Expand Up @@ -456,33 +535,15 @@ private boolean _deleteCookieConsentCookies(
HttpServletRequest httpServletRequest,
HttpServletResponse httpServletResponse) {

boolean hasConsentTypeFunctionalCookie = Validator.isNotNull(
getCookieValue(
CookiesConstants.NAME_CONSENT_TYPE_FUNCTIONAL,
httpServletRequest));
boolean hasConsentTypePerformanceCookie = Validator.isNotNull(
getCookieValue(
CookiesConstants.NAME_CONSENT_TYPE_PERFORMANCE,
httpServletRequest));
boolean hasConsentTypePersonalizationCookie = Validator.isNotNull(
getCookieValue(
CookiesConstants.NAME_CONSENT_TYPE_PERSONALIZATION,
httpServletRequest));
boolean hasUserConsentConfiguredCookie = Validator.isNotNull(
getCookieValue(
CookiesConstants.NAME_USER_CONSENT_CONFIGURED,
httpServletRequest));

if (hasConsentTypeFunctionalCookie || hasConsentTypePerformanceCookie ||
hasConsentTypePersonalizationCookie ||
hasUserConsentConfiguredCookie) {

if (hasUserConsentConfiguredCookie) {
return deleteCookies(
getDomain(httpServletRequest), httpServletRequest,
httpServletResponse,
CookiesConstants.NAME_CONSENT_TYPE_FUNCTIONAL,
CookiesConstants.NAME_CONSENT_TYPE_PERFORMANCE,
CookiesConstants.NAME_CONSENT_TYPE_PERSONALIZATION,
CookiesConstants.NAME_USER_CONSENT_CONFIGURED);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,10 @@ public boolean addCookie(
int consentType, Cookie cookie, HttpServletRequest httpServletRequest,
HttpServletResponse httpServletResponse, boolean secure);

public void addNecessaryCookies(
HttpServletRequest httpServletRequest,
HttpServletResponse httpServletResponse);

public boolean addSupportCookie(
HttpServletRequest httpServletRequest,
HttpServletResponse httpServletResponse);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,16 @@ public static boolean addCookie(
secure);
}

public static void addNecessaryCookies(
HttpServletRequest httpServletRequest,
HttpServletResponse httpServletResponse) {

CookiesManager cookiesManager = _cookiesManagerSnapshot.get();

cookiesManager.addNecessaryCookies(
httpServletRequest, httpServletResponse);
}

public static boolean addSupportCookie(
HttpServletRequest httpServletRequest,
HttpServletResponse httpServletResponse) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1 +1 @@
version 3.1.0
version 3.2.0