通过重定向在Liferay中自动触发 [英] Autologin firing in Liferay from a redirection

查看:177
本文介绍了通过重定向在Liferay中自动触发的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

从自定义操作方法执行重定向时,尝试在Liferay CE 6.1.1中启动自动登录类时遇到问题.让我解释一下情况.

I have a problem trying to fire up an autologin class in Liferay CE 6.1.1 when performing a redirection from a custom action method. Let me explain the scenarios.

假设我有一个带有登录表单(带有用户名和密码)的公共页面A,一个用于进行某些检查的自动登录类,以及一个经过正确身份验证后显示一些数据的私有页面B.

Let's say I have a public page A with a login form (with username and password), an autologin class to perform some checks and a private page B to show some data after proper authentication.

我在公共页面A中部署了一个Portlet中有一个带有登录表单的JSP,如下所示(这是一个简化的版本):

I have a JSP with the login form in a portlet deployed in public page A, as follows (this is an oversimplified version):

<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>

按下提交按钮时,将触发自动登录类,并且如果通过了检查,则用户将按预期方式进入私有页面B.

When the submit button is pressed, the autologin class is fired up and, if the checks are passed, the user lands in the private page B, as intended.

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

The previous scenario doesn't work in certain situations where a previous authentication has been performed, so I need to add some checks before the autologin gets executed.

我认为创建一个链接到表单的自定义操作是一个好主意,因此我按如下方式重写了表单:

I thought that creating a custom action linked to the form was a good idea, so I rewrote the form as follows:

<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>

在公共页面A中部署的portlet的主类中,我们需要一种方法来处理表单操作(再次简化):

In the main class of the portlet deployed in public page A, we need a method to deal with the form action (oversimplifying again):

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来确保),我得到的只是再次是相同的公共页面A,没有自动登录并且具有如下URL:

Putting aside the passing of parameters (I used copy-request-parameters in portlet.xml to ensure that), all I get is the same public page A again, with no autologin and with an URL like:

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

I guess I'm making some kind of conceptual mistake here, but, what's the reason why the autologin is not fired up in the second scenario, allowing navigation to private page B?

谢谢!

推荐答案

假设您正在使用通用Portlet.

Assuming you are using Generic Portlet.

在渲染jsp页面之前,在每个processAction之后都将调用doView方法.因此,以这种方式处理它.转到 Liferay论坛以获取更多详细信息.

After every processAction doView method is called before rendering the jsp page. So handle it this way. Goto Liferay Forum for more details.

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 = "";

    }

}

这篇关于通过重定向在Liferay中自动触发的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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