不要在 SAP Hybris 的结帐过程中要求 rememberMe 用户登录等

Do not ask login for rememberMe users in checkout process etc. in SAP Hybris

当我在 Hybris 中激活 rememberMe(spring security) 时,我希望 rememberMe 用户的行为像硬登录用户一样。我的意思是,我希望那些 rememberMe 用户(软登录)不会遇到任何障碍,比如当他们想要继续结帐过程或类似的事情时。如何在 SAP Hybris 平台中实现这一点?

Your question: How to disable HardLogin for the remember-me user in Hybris?

找到详细解释here

改变RequireHardLoginBeforeControllerHandler

更改 RequireHardLoginBeforeControllerHandler.javabeforeController 方法,以便它始终检查请求中是否存在 remember-me cookie 并且 guid 是否丢失或无效,然后创建新的 guid 不重定向登录页面。

下面yourstorefrontRememberMe需要改成你的店名,比如mySiteRemmberMe

    public static final String SECURE_REMEMBER_ME_COOKIES = "yourstorefrontRememberMe";

    @Resource(name = "guidCookieStrategy")
    private GUIDCookieStrategy guidCookieStrategy;

    @Override
    public boolean beforeController(final HttpServletRequest request, final HttpServletResponse response,
            final HandlerMethod handler) throws Exception
    {
        boolean redirect = true;

        // We only care if the request is secure
        if (request.isSecure())
        {
            // Check if the handler has our annotation
            final RequireHardLogIn annotation = findAnnotation(handler, RequireHardLogIn.class);
            if (annotation != null)
            {
                final String guid = (String) request.getSession().getAttribute(SECURE_GUID_SESSION_KEY);

                if ((!getUserService().isAnonymousUser(getUserService().getCurrentUser()) || checkForAnonymousCheckout()) &&
                        checkForGUIDCookie(request, response, guid))
                {
                    redirect = false;
                }

                if (redirect)
                {
                    if(isRememberMeCookiePresent(request))
                    {
                        // If you find your guid is missing, lets recreate it.
                        guidCookieStrategy.setCookie(request, response);
                        return true;
                    }
                    else
                    {
                        LOG.warn((guid == null ? "missing secure token in session" : "no matching guid cookie") + ", redirecting");
                        getRedirectStrategy().sendRedirect(request, response, getRedirectUrl(request));
                        return false;
                    }
                }

            }
        }
        return true;
    }


    protected boolean isRememberMeCookiePresent(HttpServletRequest request) {
      Cookie[] cookies = request.getCookies();

      if ((cookies == null) || (cookies.length == 0)) {
          return false;
      }

      for (Cookie cookie : cookies) {
          if (SECURE_REMEMBER_ME_COOKIES.equals(cookie.getName())) {
              return cookie.getValue() != null;
          }
      }
      return false;
  }