Foros de discusión

Redirect to custom jsp after login (NOT DEFAULT LANDING PAGE!)

Guenter Baumgart, modificado hace 11 años.

Redirect to custom jsp after login (NOT DEFAULT LANDING PAGE!)

Regular Member Mensajes: 119 Fecha de incorporación: 27/01/12 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
thumbnail
Sagar A Vyas, modificado hace 11 años.

RE: Redirect to custom jsp after login

Liferay Master Mensajes: 679 Fecha de incorporación: 17/04/09 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.

##
## Default Landing Page
##

    #
    # Set the default landing page path for logged in users relative to the
    # server path. This is the page users are automatically redirected to after
    # logging in. For example, if you want the default landing page to be
    # http://localhost:8080/web/guest/login, set this to /web/guest/login. To
    # activate this feature, set auth.forward.by.last.path to true. To customize
    # the behavior, see com.liferay.portal.events.DefaultLandingPageAction in
    # the "login.events.post" property above.
    #
    default.landing.page.path=
    #default.landing.page.path=/web/guest/login


Hope this help.

Thanks,
Sagar Vyas
Guenter Baumgart, modificado hace 11 años.

RE: Redirect to custom jsp after login

Regular Member Mensajes: 119 Fecha de incorporación: 27/01/12 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.
thumbnail
Amit Doshi, modificado hace 11 años.

RE: Redirect to custom jsp after login

Liferay Master Mensajes: 550 Fecha de incorporación: 29/12/10 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

Archivos adjuntos:

Guenter Baumgart, modificado hace 11 años.

RE: Redirect to custom jsp after login

Regular Member Mensajes: 119 Fecha de incorporación: 27/01/12 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 !!
thumbnail
Sagar A Vyas, modificado hace 11 años.

RE: Redirect to custom jsp after login

Liferay Master Mensajes: 679 Fecha de incorporación: 17/04/09 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 Baumgart, modificado hace 11 años.

RE: Redirect to custom jsp after login

Regular Member Mensajes: 119 Fecha de incorporación: 27/01/12 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.
thumbnail
Sagar A Vyas, modificado hace 11 años.

RE: Redirect to custom jsp after login

Liferay Master Mensajes: 679 Fecha de incorporación: 17/04/09 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 Baumgart, modificado hace 11 años.

RE: Redirect to custom jsp after login

Regular Member Mensajes: 119 Fecha de incorporación: 27/01/12 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
thumbnail
David H Nebinger, modificado hace 11 años.

RE: Redirect to custom jsp after login (NOT DEFAULT LANDING PAGE!)

Liferay Legend Mensajes: 14915 Fecha de incorporación: 2/09/06 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 Baumgart, modificado hace 11 años.

RE: Redirect to custom jsp after login (NOT DEFAULT LANDING PAGE!)

Regular Member Mensajes: 119 Fecha de incorporación: 27/01/12 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
thumbnail
David H Nebinger, modificado hace 11 años.

RE: Redirect to custom jsp after login (NOT DEFAULT LANDING PAGE!)

Liferay Legend Mensajes: 14915 Fecha de incorporación: 2/09/06 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 Baumgart, modificado hace 11 años.

RE: Redirect to custom jsp after login (NOT DEFAULT LANDING PAGE!)

Regular Member Mensajes: 119 Fecha de incorporación: 27/01/12 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 Baumgart, modificado hace 11 años.

RE: Redirect to custom jsp after login (NOT DEFAULT LANDING PAGE!)

Regular Member Mensajes: 119 Fecha de incorporación: 27/01/12 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, ?

ThemeDisplay themeDisplay = (ThemeDisplay)request.getAttribute(
			WebKeys.THEME_DISPLAY);

		if (PropsValues.AUTH_LOGIN_DISABLED) {
			response.sendRedirect(
				themeDisplay.getPathMain() +
					PropsValues.AUTH_LOGIN_DISABLED_PATH);

			return null;
		}

		String login = ParamUtil.getString(request, "login");
		String password = request.getParameter("password");
		boolean rememberMe = ParamUtil.getBoolean(request, "rememberMe");
		String authType = ParamUtil.getString(request, "authType");

		if (Validator.isNotNull(login) && Validator.isNotNull(password)) {
			LoginUtil.login(
				request, response, login, password, rememberMe, authType);
		}

		HttpSession session = request.getSession();

		if ((session.getAttribute("j_username") != null) &&
			(session.getAttribute("j_password") != null)) {

			if (PropsValues.PORTAL_JAAS_ENABLE) {
				return mapping.findForward("/portal/touch_protected.jsp");
			}
			else {
				response.sendRedirect(themeDisplay.getPathMain());

				return null;
			}
		}

		String redirect = PortalUtil.getSiteLoginURL(themeDisplay);

		if (Validator.isNull(redirect)) {
			redirect = PropsValues.AUTH_LOGIN_URL;
		}

		if (Validator.isNull(redirect)) {
			PortletURL portletURL = PortletURLFactoryUtil.create(
				request, PortletKeys.LOGIN, themeDisplay.getPlid(),
				PortletRequest.RENDER_PHASE);

			portletURL.setWindowState(getWindowState(request));
			portletURL.setPortletMode(PortletMode.VIEW);

			portletURL.setParameter("saveLastPath", "0");
			portletURL.setParameter("struts_action", "/login/login");

			redirect = portletURL.toString();
		}

		if (PropsValues.COMPANY_SECURITY_AUTH_REQUIRES_HTTPS) {
			String portalURL = PortalUtil.getPortalURL(request);

			String portalURLSecure = PortalUtil.getPortalURL(request, true);

			if (!portalURL.equals(portalURLSecure)) {
				redirect = StringUtil.replaceFirst(
					redirect, portalURL, portalURLSecure);
			}
		}

		String loginRedirect = ParamUtil.getString(request, "redirect");

		if (Validator.isNotNull(loginRedirect)) {
			if (PrefsPropsUtil.getBoolean(
					themeDisplay.getCompanyId(), PropsKeys.CAS_AUTH_ENABLED,
					PropsValues.CAS_AUTH_ENABLED)) {

				redirect = loginRedirect;
			}
			else {
				String loginPortletNamespace = PortalUtil.getPortletNamespace(
					PropsValues.AUTH_LOGIN_PORTLET_NAME);

				String loginRedirectParameter =
					loginPortletNamespace + "redirect";

				redirect = HttpUtil.setParameter(
					redirect, "p_p_id", PropsValues.AUTH_LOGIN_PORTLET_NAME);
				redirect = HttpUtil.setParameter(
					redirect, "p_p_lifecycle", "0");
				redirect = HttpUtil.setParameter(
					redirect, loginRedirectParameter, loginRedirect);
			}
		}

		response.sendRedirect(redirect);