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

hat*_*bak 5 spring-security remember-me hybris

当我rememberMe在Hybris中激活(spring security)时,我希望rememberMe用户的行为类似于Hard Login用户.我的意思是,我希望那些rememberMe用户(软登录)不会遇到任何障碍,比如他们想要在结账过程中进行或类似的事情.如何在SAP Hybris平台中实现这一目标?

Hyb*_*elp 4

您的问题:如何在 Hybris 中禁用记住我用户的 HardLogin?

在这里找到详细的解释

改变RequireHardLoginBeforeControllerHandler

更改 的beforeController方法RequireHardLoginBeforeControllerHandler.java,以便它始终检查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;
  }
Run Code Online (Sandbox Code Playgroud)