简体   繁体   English

RenderRequest上的协议重定向

[英]Protocol redirection upon RenderRequest

I'm working on a project that uses the Spring Portlet-MVC framework and Velocity on a Liferay Portal server. 我正在研究一个在Liferay Portal服务器上使用Spring Portlet-MVC框架和Velocity的项目。 For a few pages we have the requirement to serve them on a secure connection. 对于几页,我们需要在安全连接上为它们提供服务。 Being fairly new to Portlets I came up with the solution of linking to an Action-Method and redirecting from there. 作为Portlet的新手,我想到了链接到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());
}

My solution works but to me it doesn't seem really nice. 我的解决方案有效,但对我来说似乎并不好。 I was wondering if somebody could think of another, more transparent way to do this (using Interceptors and Annotations on RenderMappings maybe?). 我想知道是否有人会想到另一种更透明的方法(使用RenderMappings上的Interceptor和Annotations?)。

Any suggestions will be greatly appreciated! 任何建议将不胜感激!

By some pages, do you mean Liferay pages or are you just concerned about the url that gets generated when a user clicks on some link from the portlet. 在某些页面上,您指的是Liferay页面,还是只关心用户单击portlet中的某些链接时生成的URL。

If you want to make some link of the portlet secure, then when use liferay-portlet flavour or renderURL or actionURL. 如果要确保Portlet的某些链接安全,则在使用liferay-portlet时,或使用renderURL或actionURL。 It has an attribute called secure, which if set to true will make your url starting with https 它具有一个称为secure的属性,如果将其设置为true,它将使您的URL以https开头

If you are looking for some liferay page(for example /web/guest/mypage) to be secure then its kind of a hack and I wouldnt really suggest this to anyone, but if you have got no other option, you can create a service pre hook and check for url patterns you are concerned about and redirect to an https version of that url. 如果您正在寻找一些liferay页面(例如/ web / guest / mypage)以确保安全,那么它是一种hack,我真的不建议任何人这样做,但是如果您没有其他选择,则可以创建服务预先挂接并检查您关注的网址格式,然后重定向到该网址的https版本。

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());
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM