Vista combinada Visión Plana Vista de árbol
Discusiones [ Anterior | Siguiente ]
toggle
Guenter Nobody
Redirect to custom jsp after login (NOT DEFAULT LANDING PAGE!)
18 de agosto de 2012 1:48
Respuesta

Guenter Nobody

Ranking: Regular Member

Mensajes: 119

Fecha de incorporación: 27 de enero de 2012

Mensajes recientes

Hi,

how can redirect to a certain jsp after login ? I searched the forum and tried many things.
My jsp redirects to the login page like this :

/home?p_p_state=maximized&p_p_mode=view&saveLastPath=0&_58_struts_action=%2Flogin%2Flogin&p_p_id=58&p_p_lifecycle=0&_58_redirect=%2FXApp-portlet%2Fxas.jsp%3FappId%3Dwebapp%26uuid%3D11166763-e89c-44ba-aba7-4e9f4fdf97a9

but after the login, it never goes back to original page.

I also tried :

LastPath lastPath = new LastPath(newUrl,null);
request.getSession().setAttribute( WebKeys.LAST_PATH, lastPath );

but no !

The jsp is deployed with a custom portlet but isn't exactly a portlet, just a jsp !

Thanks !

g
Sagar A Vyas
RE: Redirect to custom jsp after login
17 de agosto de 2012 13:32
Respuesta

Sagar A Vyas

Ranking: Liferay Master

Mensajes: 657

Fecha de incorporación: 17 de abril de 2009

Mensajes recientes

Hi Guenter,

You can set default landing page by following property in portal-ext.properties or as per my knowladge you can set landing page from Control Panel too.

 1##
 2## Default Landing Page
 3##
 4
 5    #
 6    # Set the default landing page path for logged in users relative to the
 7    # server path. This is the page users are automatically redirected to after
 8    # logging in. For example, if you want the default landing page to be
 9    # http://localhost:8080/web/guest/login, set this to /web/guest/login. To
10    # activate this feature, set auth.forward.by.last.path to true. To customize
11    # the behavior, see com.liferay.portal.events.DefaultLandingPageAction in
12    # the "login.events.post" property above.
13    #
14    default.landing.page.path=
15    #default.landing.page.path=/web/guest/login


Hope this help.

Thanks,
Sagar Vyas
Guenter Nobody
RE: Redirect to custom jsp after login
17 de agosto de 2012 13:42
Respuesta

Guenter Nobody

Ranking: Regular Member

Mensajes: 119

Fecha de incorporación: 27 de enero de 2012

Mensajes recientes

Thank you,
but no, I need to authentificate a specific jsp against liferay without changing the global landing page.

Do I have to make a dummy portlet which makes then another and second forward ? The mentioned redirect works of course with registered portlet targets but breaks when its a jsp only.

Any clue how to fix this ?

g.
Amit Doshi
RE: Redirect to custom jsp after login
18 de agosto de 2012 1:20
Respuesta

Amit Doshi

Ranking: Liferay Master

Mensajes: 549

Fecha de incorporación: 29 de diciembre de 2010

Mensajes recientes

Guenter Baumgart:
Thank you,
but no, I need to authentificate a specific jsp against liferay without changing the global landing page.

Do I have to make a dummy portlet which makes then another and second forward ? The mentioned redirect works of course with registered portlet targets but breaks when its a jsp only.

Any clue how to fix this ?

g.


It's inbuilt functionality of Liferay.
Please find below screenshot which will explain you all your requirements. It was very well mentioned in the tooltip.

Hope it helps.

Thanks & Regards,
Amit Doshi
Adjunto

archivos adjuntos: 2.PNG (78,7k)
Guenter Nobody
RE: Redirect to custom jsp after login
18 de agosto de 2012 11:31
Respuesta

Guenter Nobody

Ranking: Regular Member

Mensajes: 119

Fecha de incorporación: 27 de enero de 2012

Mensajes recientes

Thank you, this is very kind of you.

But please understand : I can NOT change the entire default landing page just for that !!

What I want is VERY simple but it seems Liferay has a bug. I need to redirect the user to the login page and then he got authenticated, the login portlet needs to send him back to the original page. This here works with registered portlets but not with custom JSP's :

/home?p_p_state=maximized&p_p_mode=view&saveLastPath=0&_58_struts_action=%2Flogin%2Flogin&p_p_id=58&p_p_lifecycle=0&_58_redirect=%2FXApp-portlet%2Fxas.jsp%3FappId%3Dwebapp%26uuid%3D1116663-e89c-44ba-aba7-4e9f4fdf97a9

Do you see the "redirect" parameter here : "_58_redirect=" ? It doesnt work ! After login, its stays on the login page instead of going to the redirect page !!
Sagar A Vyas
RE: Redirect to custom jsp after login
18 de agosto de 2012 1:59
Respuesta

Sagar A Vyas

Ranking: Liferay Master

Mensajes: 657

Fecha de incorporación: 17 de abril de 2009

Mensajes recientes

What I want is VERY simple but it seems Liferay has a bug. I need to redirect the user to the login page and then he got authenticated, the login portlet needs to send him back to the original page. This here works with registered portlets but not with custom JSP's


Hi Guenter,

I guess I got your point please correct me if i understood wrongly.

1st - User will visit site as a Guest user.
2nd - On certain click user should redirect on login page for authentication. (For example page emoticon
3rd - If user authenticate properly then it should be redirect on Page B with authenticated user

And as per your this is working as expected in login portlet but not with custom portlet ?

If it is a case what i would suggest instead of going to some other page just open one pop-up with login portlet and if user is authenticate then close that pop up.

Hope this make sense.

Thanks,
Sagar Vyas
Guenter Nobody
RE: Redirect to custom jsp after login
18 de agosto de 2012 2:07
Respuesta

Guenter Nobody

Ranking: Regular Member

Mensajes: 119

Fecha de incorporación: 27 de enero de 2012

Mensajes recientes

Hi,

yes, the custom jsp is stored within a custom portlet but it is NOT a portlet as such.

A popup isn't exactly fool proof and the problem then is that my jsp doesn't know when the login has been done successfully. In that case the user must reload the jsp and that doesn't work our QA. In top, people have popup blockers,...

However, it looks rather that I need to write my own login portlet or fix the built-in portlet.

I will file a bug report. Thank you guys !
guenter.
Sagar A Vyas
RE: Redirect to custom jsp after login
18 de agosto de 2012 2:19
Respuesta

Sagar A Vyas

Ranking: Liferay Master

Mensajes: 657

Fecha de incorporación: 17 de abril de 2009

Mensajes recientes

As I have read your requirement what is in Top of my mind is.

You can have maintain current page whenever user click on Login link you need to pass current page parameter (PortalUtil.getCurrentURL(portletRequest) )with login redirect url.

Now what you need to do is like create ext portlet and change struts path to your controller instead of OOB controller of login (_58_struts_action=%2Flogin%2Flogin&)

and from your controller just redirect on currentPage url.

Thanks,
Sagar Vyas
Guenter Nobody
RE: Redirect to custom jsp after login
18 de agosto de 2012 2:23
Respuesta

Guenter Nobody

Ranking: Regular Member

Mensajes: 119

Fecha de incorporación: 27 de enero de 2012

Mensajes recientes

well, that is what I was afraid of. Isn't it easier to fix the login portlet ? I am not sure yet, the jsp is the only one which needs an auth.
thanks,
g
David H Nebinger
RE: Redirect to custom jsp after login (NOT DEFAULT LANDING PAGE!)
18 de agosto de 2012 8:39
Respuesta

David H Nebinger

Community Moderator

Ranking: Liferay Legend

Mensajes: 11478

Fecha de incorporación: 1 de septiembre de 2006

Mensajes recientes

Guenter Baumgart:
The jsp is deployed with a custom portlet but isn't exactly a portlet, just a jsp !


Look, Liferay is not a normal web application. You don't just indicate what JSP page you want to land on in certain conditions within the portal.

When in Liferay, Liferay wants to control all aspects of the communication w/ the end user. Even if you could exit the Liferay portal context to hit your stand alone JSP page, you'd have a difficult time re-entering the Liferay context after you are done.

Instead of trying to redirect to your own JSP page, instead you should be thinking how to do what you're after within a portal context. For example, you create a portlet that contains the necessary functionality you want. Put it on a portal page, use a 1 column layout (full page) and put the portlet on there. Then post login you are simply navigating to a portal page (which is something the portal supports) that has your portlet on it.

The Terms Of Use is another portal-friendly implementation. This uses an article to display the terms of use acceptance, but it is still within the confines of the portal context.
Guenter Nobody
RE: Redirect to custom jsp after login (NOT DEFAULT LANDING PAGE!)
18 de agosto de 2012 9:21
Respuesta

Guenter Nobody

Ranking: Regular Member

Mensajes: 119

Fecha de incorporación: 27 de enero de 2012

Mensajes recientes

Hi David,

thats's somehow funny we meet here about this again !

Regarding your recommendations or Liferay best practice hints : the actual problem is that our portlet needs to be moved out of a portlet, because we're having a real complex application running. A mobile app builder which runs a mobile app simulator inside for different devices and platforms at the same time (no iframes). Liferay's base css and more specifically, AUI is disturbing or app(http://xapp-studio.com/documents/10197/0/latestXAS.jpg?t=1345044285979).

In the last 4 months we had a VERY hard time to get it running as regular portlet but we'll give it up and prefer to spent our time on the product instead of getting it into Liferay at any cost. We really wished we could have both running at the same time as Liferay has wonderful features to add community or support related portlets to our app !

I am having still problems with your example ("The post login...") :

Then post login you are simply navigating to a portal page (which is something the portal supports) that has your portlet on it.


Can you explain this please in another way ? Or did you assume that I've to give up the single JSP idea ? ( Which I really can't ! )

I am thanking you again,
g
David H Nebinger
RE: Redirect to custom jsp after login (NOT DEFAULT LANDING PAGE!)
18 de agosto de 2012 11:13
Respuesta

David H Nebinger

Community Moderator

Ranking: Liferay Legend

Mensajes: 11478

Fecha de incorporación: 1 de septiembre de 2006

Mensajes recientes

Guenter Baumgart:
Regarding your recommendations or Liferay best practice hints : the actual problem is that our portlet needs to be moved out of a portlet, because we're having a real complex application running. A mobile app builder which runs a mobile app simulator inside for different devices and platforms at the same time (no iframes). Liferay's base css and more specifically, AUI is disturbing or app(http://xapp-studio.com/documents/10197/0/latestXAS.jpg?t=1345044285979).

In the last 4 months we had a VERY hard time to get it running as regular portlet but we'll give it up and prefer to spent our time on the product instead of getting it into Liferay at any cost. We really wished we could have both running at the same time as Liferay has wonderful features to add community or support related portlets to our app !


Well, you're either inside of Liferay or you're not. If you can't run inside of Liferay, then you're creating a servlet. And as a servlet, that would mean that you are outside of all of the stuff that Liferay provides, such as authentication, permissions-based viewing, etc. Possibly you could use Spring Security w/ a security filter that possibly checks whether you've logged into Liferay or not, but I don't know if you'd have visibility on that since you're in a different application context (different sessions, etc.). You'd probably have to set a cookie on the Liferay side after login, then check for the cookie in your servlet. A post login action would be used for the cookie setting (use a temp cookie that is valid only for the browser session), but you may lose control of the logout process (since you really don't have to log out).

Anyway, you wouldn't have to do a redirect, per se, just a link bound w/ the URL to hit your servlet.

I am having still problems with your example ("The post login...") :

Then post login you are simply navigating to a portal page (which is something the portal supports) that has your portlet on it.


Can you explain this please in another way ? Or did you assume that I've to give up the single JSP idea ? ( Which I really can't ! )


Navigating within the portal to a page that contains your portlets is just a matter of using the friendly path. When you define what it is in portal-ext.properties or use a post login action to find the landing page, you use the Liferay friendly path. So if you have /web/guest/my-friendly-url-page, this is what the portal is capable of handling for the built-in landing page support.
Guenter Nobody
RE: Redirect to custom jsp after login (NOT DEFAULT LANDING PAGE!)
18 de agosto de 2012 11:37
Respuesta

Guenter Nobody

Ranking: Regular Member

Mensajes: 119

Fecha de incorporación: 27 de enero de 2012

Mensajes recientes

I'll try my best !

So finally its true that : /home?p_p_state=maximized&p_p_mode=view&saveLastPath=0&_58_struts_action=%2Flogin%2Flogin&p_p_id=58&p_p_lifecycle=0&_58_redirect=%2FXApp-portlet%2Fxas.jsp%3FappId%3Dwebapp%26uuid%3D11166763-e89c-44ba-a7-4e9f4fdf97a9

isn't redirecting because its not within a real Liferay context...I thought its a bug and I am going to try "fix" it before your way.

The different session problem isn't a problem at all, I could find the right settings in the props (shared vars).

Thank you again for the insights. I am realizing more and more about Liferay : "Nobody said its getting easy" emoticon

g
Guenter Nobody
RE: Redirect to custom jsp after login (NOT DEFAULT LANDING PAGE!)
19 de agosto de 2012 10:38
Respuesta

Guenter Nobody

Ranking: Regular Member

Mensajes: 119

Fecha de incorporación: 27 de enero de 2012

Mensajes recientes

Well,
according to this piece of code, my redirect parameter should have been used ! I guess I did something wrong with the url then, ?
 1
 2ThemeDisplay themeDisplay = (ThemeDisplay)request.getAttribute(
 3            WebKeys.THEME_DISPLAY);
 4
 5        if (PropsValues.AUTH_LOGIN_DISABLED) {
 6            response.sendRedirect(
 7                themeDisplay.getPathMain() +
 8                    PropsValues.AUTH_LOGIN_DISABLED_PATH);
 9
10            return null;
11        }
12
13        String login = ParamUtil.getString(request, "login");
14        String password = request.getParameter("password");
15        boolean rememberMe = ParamUtil.getBoolean(request, "rememberMe");
16        String authType = ParamUtil.getString(request, "authType");
17
18        if (Validator.isNotNull(login) && Validator.isNotNull(password)) {
19            LoginUtil.login(
20                request, response, login, password, rememberMe, authType);
21        }
22
23        HttpSession session = request.getSession();
24
25        if ((session.getAttribute("j_username") != null) &&
26            (session.getAttribute("j_password") != null)) {
27
28            if (PropsValues.PORTAL_JAAS_ENABLE) {
29                return mapping.findForward("/portal/touch_protected.jsp");
30            }
31            else {
32                response.sendRedirect(themeDisplay.getPathMain());
33
34                return null;
35            }
36        }
37
38        String redirect = PortalUtil.getSiteLoginURL(themeDisplay);
39
40        if (Validator.isNull(redirect)) {
41            redirect = PropsValues.AUTH_LOGIN_URL;
42        }
43
44        if (Validator.isNull(redirect)) {
45            PortletURL portletURL = PortletURLFactoryUtil.create(
46                request, PortletKeys.LOGIN, themeDisplay.getPlid(),
47                PortletRequest.RENDER_PHASE);
48
49            portletURL.setWindowState(getWindowState(request));
50            portletURL.setPortletMode(PortletMode.VIEW);
51
52            portletURL.setParameter("saveLastPath", "0");
53            portletURL.setParameter("struts_action", "/login/login");
54
55            redirect = portletURL.toString();
56        }
57
58        if (PropsValues.COMPANY_SECURITY_AUTH_REQUIRES_HTTPS) {
59            String portalURL = PortalUtil.getPortalURL(request);
60
61            String portalURLSecure = PortalUtil.getPortalURL(request, true);
62
63            if (!portalURL.equals(portalURLSecure)) {
64                redirect = StringUtil.replaceFirst(
65                    redirect, portalURL, portalURLSecure);
66            }
67        }
68
69        String loginRedirect = ParamUtil.getString(request, "redirect");
70
71        if (Validator.isNotNull(loginRedirect)) {
72            if (PrefsPropsUtil.getBoolean(
73                    themeDisplay.getCompanyId(), PropsKeys.CAS_AUTH_ENABLED,
74                    PropsValues.CAS_AUTH_ENABLED)) {
75
76                redirect = loginRedirect;
77            }
78            else {
79                String loginPortletNamespace = PortalUtil.getPortletNamespace(
80                    PropsValues.AUTH_LOGIN_PORTLET_NAME);
81
82                String loginRedirectParameter =
83                    loginPortletNamespace + "redirect";
84
85                redirect = HttpUtil.setParameter(
86                    redirect, "p_p_id", PropsValues.AUTH_LOGIN_PORTLET_NAME);
87                redirect = HttpUtil.setParameter(
88                    redirect, "p_p_lifecycle", "0");
89                redirect = HttpUtil.setParameter(
90                    redirect, loginRedirectParameter, loginRedirect);
91            }
92        }
93
94        response.sendRedirect(redirect);