Liferay 7中自定义登录后操作中的LAST_PATH重定向 [英] LAST_PATH Redirection in Custom Login Post Action in Liferay 7

查看:138
本文介绍了Liferay 7中自定义登录后操作中的LAST_PATH重定向的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在Liferay 7中实现自定义登录-一个用于登录挂钩Portlet的模块,另一个用于ActionCommand的模块.

I'm implementing custom login in Liferay 7 - one module for login hook portlet and one for ActionCommand.

我还为登录后事件生成了类.问题是重定向在此类或登录挂钩porlet的JSP上均不起作用.

I also generated class for post login event. The problem is redirection won't work on either this class or on JSP of login hook porlet.

这是我的LifecycleAction代码:

This is my code for LifecycleAction:

@Component(
    immediate = true,
    property = {
        "key=login.events.post"
    },
    service = LifecycleAction.class
)
public class UserLoginPostAction implements LifecycleAction {

    private static final Log LOGGER = LogFactoryUtil.getLog(UserLoginActionCommand.class);

    @Override
    public void processLifecycleEvent(LifecycleEvent lifecycleEvent) throws ActionException {   

        HttpServletRequest request = lifecycleEvent.getRequest();
        HttpServletResponse response = lifecycleEvent.getResponse();
        HttpSession session = request.getSession();

        try {
            User currentUser = PortalUtil.getUser(request);
            LOGGER.info("USER|" + currentUser.getFirstName() + "|" + currentUser.getGroup().toString());
            LOGGER.info("LASTPATH|" + session.getAttribute("LAST_PATH"));
            LastPath lastPath = (LastPath) session.getAttribute("LAST_PATH");
            LOGGER.info(lastPath.getPath());
            session.setAttribute(WebKeys.LAST_PATH, lastPath);
            response.sendRedirect(lastPath.getPath());
        } catch (PortalException | IOException exception) {
            LOGGER.error(exception);
        }
    }

}

这是我用于Porlet登录JSP的代码:

This is my code for porlet login JSP:

<c:choose>
    <c:when test="<%= themeDisplay.isSignedIn() %>">        
        <%
        response.sendRedirect(WebKeys.LAST_PATH);
        %>
    </c:when>
    <c:otherwise>
...

我的记录仪能够在控制台上显示正确的值.

My LOGGER is able to display correct values on console.

谢谢.

推荐答案

登录后的转发有些棘手.

The forwarding after login is a bit tricky.

如果使用LAST_PATH和会话属性,则不需要发送重定向行,因为它将由Liferay处理.最后一个路径可能会受到URL参数重定向"的影响.

If you use the LAST_PATH and session attributes you don't need the send redirect line because that will be handled by Liferay. The last path can be though affected by URL parameters as 'redirect'.

如果要使用发送重定向方法.生成您的URL,然后将您创建的URL传递给sendRedirect()调用.不要使用会话参数.

If you are going to use the send redirect approach. Build your URL and then past the URL that you created to the sendRedirect() call. Do not use the session parameter.

PS:如果要修改登录名,请查看

PS: If you are modifying the login have a look at the AuthPipeline rather the doing heavy overrides to the login portlet.

这篇关于Liferay 7中自定义登录后操作中的LAST_PATH重定向的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆