【问题标题】:Protocol redirection upon RenderRequestRenderRequest 时的协议重定向
【发布时间】:2012-03-22 08:53:15
【问题描述】:

我正在开发一个在 Liferay 门户服务器上使用 Spring Portlet-MVC 框架和 Velocity 的项目。对于一些页面,我们需要在安全连接上为它们提供服务。作为 Portlets 的新手,我想出了链接到 Action-Method 并从那里重定向的解决方案。

@ActionMapping(params = "command=secureRedirect")
public void actionSecureRedirect(ActionRequest request, ActionResponse response) {
    HttpServletRequest servletRequest = PortalUtil.getHttpServletRequest(request);
    String absoluteUrl = servletRequest.getRequestURL().toString();
    String[] urlComponents = StringUtils.split(absoluteUrl, '/');
    StringBuffer redirectUrl = new StringBuffer("https://");
    redirectUrl.append(urlComponents[1]);
    redirectUrl.append("<specificPath>");
    response.sendRedirect(redirectUrl.toString());
}

我的解决方案有效,但对我来说似乎不太好。我想知道是否有人可以想到另一种更透明的方式来做到这一点(也许在 RenderMappings 上使用拦截器和注释?)。

任何建议将不胜感激!

【问题讨论】:

    标签: java spring spring-mvc portlet spring-portlet-mvc


    【解决方案1】:

    您所说的某些页面是指 Liferay 页面,还是您只是关心当用户单击 portlet 中的某个链接时生成的 url。

    如果你想让portlet 的某些链接安全,那么在使用liferay-portlet 风格或renderURL 或actionURL 时。它有一个名为 secure 的属性,如果设置为 true 将使您的 url 以 https 开头

    如果您正在寻找一些安全的 liferay 页面(例如 /web/guest/mypage),那么它是一种黑客攻击,我不会向任何人建议这个,但如果您没有其他选择,您可以创建一个服务预挂钩并检查您关心的 url 模式并重定向到该 url 的 https 版本。

    【讨论】:

      【解决方案2】:
      write this code in controller 
      
      
       protected PortletURL getRedirectURL(ActionRequest actionRequest) {
              ThemeDisplay themeDisplay = (ThemeDisplay) actionRequest.getAttribute(WebKeys.THEME_DISPLAY);
              String portletName = (String) actionRequest.getAttribute(WebKeys.PORTLET_ID);
              PortletURL redirectURL = PortletURLFactoryUtil.create(PortalUtil.getHttpServletRequest(actionRequest), portletName, themeDisplay.getLayout().getPlid(),
                      PortletRequest.RENDER_PHASE);
              return redirectURL;
          }
      
      @ActionMapping(params="something")
      public void save(ActionRequest actionRequest, Other parameters){
      
      
      
      /.....Your code
      
      
      
      .....//
       redirectURL = getRedirectURL(actionRequest);
       actionResponse.sendRedirect(redirectURL.toString());
      }
      

      【讨论】:

        猜你喜欢
        • 2011-01-19
        • 1970-01-01
        • 1970-01-01
        • 2014-12-10
        • 2015-04-24
        • 2013-06-20
        • 2017-04-05
        • 2022-01-21
        • 2011-02-22
        相关资源
        最近更新 更多