0

我正在开发一个在 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 上使用拦截器和注释?)。

任何建议将不胜感激!

4

2 回答 2

2

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

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

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

于 2012-03-23T13:12:40.337 回答
1
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());
}
于 2012-05-10T11:56:15.253 回答