Class DefaultConsentService

java.lang.Object
com.hybris.yprofile.consent.services.DefaultConsentService
All Implemented Interfaces:
ConsentService

public class DefaultConsentService extends Object implements ConsentService
Implementation for ConsentService. Service is responsible to generate and provide the consent reference.
  • Field Details

  • Constructor Details

    • DefaultConsentService

      public DefaultConsentService()
  • Method Details

    • isProfileTrackingConsentGiven

      public boolean isProfileTrackingConsentGiven(javax.servlet.http.HttpServletRequest request)
      Description copied from interface: ConsentService
      Checks if the user (logged In or Anonymous) has granted the consent to allow profile tracking
      Specified by:
      isProfileTrackingConsentGiven in interface ConsentService
      Parameters:
      request - the http request
      Returns:
      true or false
    • isProfileTrackingConsentGivenForLoggedInUser

      protected boolean isProfileTrackingConsentGivenForLoggedInUser()
    • profileTrackingConsentForLoggedInUser

      protected boolean profileTrackingConsentForLoggedInUser(String consent)
    • isAnonymousUser

      protected boolean isAnonymousUser()
    • isUserSoftLoggedIn

      protected boolean isUserSoftLoggedIn()
    • isProfileTrackingConsentGivenForAnonymousUser

      protected boolean isProfileTrackingConsentGivenForAnonymousUser(javax.servlet.http.HttpServletRequest request)
    • isProfileTrackingConsentGivenInCookieForAnonymousUser

      protected boolean isProfileTrackingConsentGivenInCookieForAnonymousUser(javax.servlet.http.Cookie anonymousConsentCookie)
    • isProfileTrackingConsentGivenInHeaderForAnonymousUser

      protected boolean isProfileTrackingConsentGivenInHeaderForAnonymousUser(String anonymousConsentHeader)
    • saveConsentReferenceInSessionAndConsentModel

      public void saveConsentReferenceInSessionAndConsentModel(javax.servlet.http.HttpServletRequest request)
      Description copied from interface: ConsentService
      It gets the consent reference stored in a cookie (generated by ProfileTag) and saves it in the session and in the user model (for logged In users) for further events
      Specified by:
      saveConsentReferenceInSessionAndConsentModel in interface ConsentService
      Parameters:
      request - Http request
    • getConsentReferenceFromCookie

      public String getConsentReferenceFromCookie(String siteId, javax.servlet.http.HttpServletRequest request)
      Description copied from interface: ConsentService
      Fetches the consent reference from cookie
      Specified by:
      getConsentReferenceFromCookie in interface ConsentService
      Parameters:
      siteId - base site identifier
      request - http request
      Returns:
      consent reference
    • getConsentReferenceFromHeader

      public String getConsentReferenceFromHeader(javax.servlet.http.HttpServletRequest request)
      Description copied from interface: ConsentService
      Fetches the consent reference from header name specified in the property profileservices.occ.consent.header.name
      Specified by:
      getConsentReferenceFromHeader in interface ConsentService
      Parameters:
      request - http request
      Returns:
      consent reference
    • getConsentReferenceFromSession

      public String getConsentReferenceFromSession()
      Description copied from interface: ConsentService
      Fetches the consent reference from session
      Specified by:
      getConsentReferenceFromSession in interface ConsentService
      Returns:
      consent reference
    • getConsentReferenceFromConsentModel

      public String getConsentReferenceFromConsentModel()
      Description copied from interface: ConsentService
      Fetches the consent reference from the active consent model.
      Specified by:
      getConsentReferenceFromConsentModel in interface ConsentService
      Returns:
      consent reference
    • setProfileConsentCookieAndSession

      public void setProfileConsentCookieAndSession(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response, boolean consent)
      Description copied from interface: ConsentService
      Saves the profile consent separately in a cookie and session attribute
      Specified by:
      setProfileConsentCookieAndSession in interface ConsentService
      Parameters:
      request - http request
      response - http reponse
      consent - true or false
    • setProfileConsent

      public void setProfileConsent(boolean consent)
      Specified by:
      setProfileConsent in interface ConsentService
    • removeConsentReferenceInSession

      public void removeConsentReferenceInSession()
      Description copied from interface: ConsentService
      removes the consent reference in session
      Specified by:
      removeConsentReferenceInSession in interface ConsentService
    • deleteConsentReferenceInConsentServiceAndInConsentModel

      public void deleteConsentReferenceInConsentServiceAndInConsentModel(ConsentModel consentModel, String baseSiteId)
      Description copied from interface: ConsentService
      Deletes the consent reference when the user revokes the consent for profile or user closes the account
      Specified by:
      deleteConsentReferenceInConsentServiceAndInConsentModel in interface ConsentService
      Parameters:
      consentModel - the user
      baseSiteId - the base site id
    • saveConsentReferenceInSession

      public void saveConsentReferenceInSession(String consentId)
      Description copied from interface: ConsentService
      It gets the consent reference stored in a cookie and saves it in the session for further events
      Specified by:
      saveConsentReferenceInSession in interface ConsentService
      Parameters:
      consentId - the consent reference
    • isProfileTrackingConsentGiven

      public boolean isProfileTrackingConsentGiven()
      Method checks for consents stored in the session - in the same way for both anonymous and logged in user. Consents must be already stored in the session.
      Specified by:
      isProfileTrackingConsentGiven in interface ConsentService
      Returns:
      true if consent is given
    • getDebugFlagValue

      protected static String getDebugFlagValue(UserModel userModel)
    • shouldSendEvent

      protected boolean shouldSendEvent(String consentReference, String baseSiteId)
    • isValidConsentReference

      protected static boolean isValidConsentReference(String consentReferenceId)
    • setAttributeInSession

      protected void setAttributeInSession(String key, Object value)
    • getSiteId

      protected String getSiteId()
    • getCurrentBaseSiteModel

      protected Optional<BaseSiteModel> getCurrentBaseSiteModel()
    • logSuccess

      protected static void logSuccess(Optional<com.hybris.charon.RawResponse> rawResponse, String message)
    • logError

      protected static void logError(Throwable error)
    • getClient

      protected ConsentServiceClient getClient()
    • getCookieGenerator

      protected EnhancedCookieGenerator getCookieGenerator()
    • setCookieGenerator

      public void setCookieGenerator(EnhancedCookieGenerator cookieGenerator)
    • getSessionService

      public SessionService getSessionService()
    • setSessionService

      public void setSessionService(SessionService sessionService)
    • getUserService

      public UserService getUserService()
    • setUserService

      public void setUserService(UserService userService)
    • getProfileConfigurationService

      public ProfileConfigurationService getProfileConfigurationService()
    • setProfileConfigurationService

      public void setProfileConfigurationService(ProfileConfigurationService profileConfigurationService)
    • getRetrieveRestClientStrategy

      public RetrieveRestClientStrategy getRetrieveRestClientStrategy()
    • setRetrieveRestClientStrategy

      public void setRetrieveRestClientStrategy(RetrieveRestClientStrategy retrieveRestClientStrategy)
    • getBaseSiteService

      public BaseSiteService getBaseSiteService()
    • setBaseSiteService

      public void setBaseSiteService(BaseSiteService baseSiteService)
    • getModelService

      public ModelService getModelService()
    • setModelService

      public void setModelService(ModelService modelService)
    • getConfigurationService

      public ConfigurationService getConfigurationService()
    • setConfigurationService

      public void setConfigurationService(ConfigurationService configurationService)
    • getCommerceConsentService

      public CommerceConsentService getCommerceConsentService()
    • setCommerceConsentService

      public void setCommerceConsentService(CommerceConsentService commerceConsentService)
    • setConsentReferenceInConsentModel

      protected void setConsentReferenceInConsentModel(String consentReferenceId)
    • resetConsentReferenceInConsentModel

      protected void resetConsentReferenceInConsentModel(ConsentModel consentModel)
    • setProfileIdCookie

      public void setProfileIdCookie(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response, String consentReferenceId)
      Description copied from interface: ConsentService
      Saves the profile id i.e old consent reference separately as a session cookie so that profile tag can skip getting a new consent reference.
      Specified by:
      setProfileIdCookie in interface ConsentService
      Parameters:
      request - http request
      response - http response to which the cookie is added if the request doesnt have CR cookie
      consentReferenceId - the profile id or consent reference id of the user