从重定向在 Liferay 中触发自动登录

Autologin firing in Liferay from a redirection

当从自定义操作方法执行重定向时,我在 Liferay CE 6.1.1 中尝试启动自动登录 class 时遇到问题。让我解释一下场景。

功能场景1:直接POST动作

假设我有一个 public 页面 A,其中包含一个登录表单(带有用户名和密码)、一个自动登录 class 以执行一些检查和一个私人页面 B 以在正确后显示一些数据身份验证。

我在 public 页面 A 中部署了一个带有登录表单的 JSP,如下(这是一个过于简化的版本):

<form method="post" action="https://localhost:4444/path/to/private/page/b">
    <input id="username" type="text" />
    <input id="password" type="password" />

    <input type="submit" />
</form>

按下提交按钮后,自动登录 class 被启动,如果检查通过,用户将按预期登陆私人页面 B。

非功能性场景 #2:通过自定义操作重定向

之前的方案在某些情况下不起作用,因为之前已经执行了身份验证,因此我需要在执行自动登录之前添加一些检查

我认为创建链接到表单的自定义操作是个好主意,所以我将表单重写如下:

<portlet:actionUrl name="actionLogin" var="urlActionLogin" />

<form method="post" action="${urlActionLogin}">
    <input id="username" type="text" />
    <input id="password" type="password" />

    <input type="submit" />
</form>

在public页面A中部署的portlet的主class中,我们需要一个方法来处理表单动作(再次简化):

public void actionLogin (ActionRequest request, ActionResponse response) {
    if (testsArePassed ( )) {
        response.sendRedirect ("https://localhost:4444/path/to/private/page/b");
    } else {
        // Error page.
    }
}

抛开参数的传递(我在portlet.xml中使用了copy-request-parameters来确保这一点),我得到的都是相同的public页面A,没有自动登录和URL 比如:

https://localhost:4444/path/to/public/page/a?p_p_id=58&p_p_lifecycle=0&_58_redirect=%2Fpath%2Fto%2Fprivate%2Fpage%2Fb

我想我在这里犯了某种概念上的错误,但是,为什么在第二种情况下没有启动自动登录,允许导航到私人页面 B?

谢谢!

假设您使用的是通用 Portlet。

在呈现 jsp 页面之前调用每个 processAction doView 方法之后。所以这样处理。转到 Liferay Forum 了解更多详情。

public class MedelogGetAdmin extends GenericPortlet {

    String actionJsp = "";

    public void processAction(ActionRequest request, ActionResponse response) throws PortletException, IOException {

        //from variables      
        String formType = request.getParameter("formType");
        String buttonClicked = request.getParameter("button");

        //check what page to forward to
        actionJsp = Action.forwardTo(formType, buttonClicked); //jsp = consumers.jsp

        //forward to "/WEB-INF/jsp/"+jsp;
        //but how?


    }

    public void doView(RenderRequest request, RenderResponse response) throws PortletException, IOException {

        response.setContentType("text/html");

        if(actionJsp == null || actionJsp.equals("")){
            PortletRequestDispatcher dispatcher =
            getPortletContext().getRequestDispatcher("/WEB-INF/jsp/MedelogGetAdmin_view.jsp");       
            dispatcher.include(request, response);
        }else{
            PortletRequestDispatcher dispatcher =
            getPortletContext().getRequestDispatcher("/WEB-INF/jsp/"+actionJsp);       
            dispatcher.include(request, response);
        }

        //set the actionJsp back to default
        actionJsp = "";

    }

}