Foros de discusión

land URL when login - Liferay(+CAS) not like other webapps

Bernardo Riveira Faraldo, modificado hace 14 años.

land URL when login - Liferay(+CAS) not like other webapps

Regular Member Mensajes: 135 Fecha de incorporación: 30/10/08 Mensajes recientes
let me explain our problem; with any other (well designed) userpassword-protected webapp we work with, there are 2 possible things to do when the user gets into the portal:

1) if the user enters the portal without a specific URI, just using "http://myportal.com", then it should go to a default web page; this is what we want and we have made it touching portal-ext.properties with

auth.forward.by.last.path=true
default.landing.page.path=/liferay/group/blablah

so, when an user enters the portal with "myportal.com", he is being redirected to "myportal.com/liferay/group/blablah".


2) when the user enters the portal with a complete URI like

http://myportal.com/liferay/group/ANOTHERGROUP

then, he should see that page he requested

OK, where's the problem? We use CAS-JASIG, the complete liferay portal is protected (this being an intranet site), so this is what happens:

1) if the user enters the portal without a specific URI, just using "http://myportal.com", he has to enter (in a CAS form) his username and password and then he's being redirected to "myportal.com/liferay/group/blablah" (the "default.landing.page.path")

2) if the user enters the portal with a complete URI like "http://myportal.com/liferay/group/ANOTHERGROUP", then he has to enter (in a CAS form) his username and password and then he's being redirected to "myportal.com/liferay/group/blablah" (the "default.landing.page.path"), so he does not hit what he wanted in the first time ("http://myportal.com/liferay/group/ANOTHERGROUP")

Don't know if this also happens in non-CAS installations, but, is there any way to solve it? If not, it is broken, as if for example you use emails with links to specific URLs of the portal they will not work, as the user is always redirected to the default landing page.

I know that there is a way to redefine (with java) this first page scenario, but I'm afraid it is not only Liferays fault but the CAS adaptor.

Thanks in advance
Bernardo


### EDITED: ok, if this is not the first time they go to the intranet, then they are redirected to the LAST PAGE they visited, which is NOT very web-like (I mean, it is a strange behaviour to web users, where the URL is "god" and you should always see what you asked for), that is because of "auth.forward.by.last.path=true", but we have to enter that so "default.landing.page.path" works (althought I don't know why, as they should not be related)
Bernardo Riveira Faraldo, modificado hace 14 años.

RE: land URL when login - Liferay(+CAS) not like other webapps

Regular Member Mensajes: 135 Fecha de incorporación: 30/10/08 Mensajes recientes
as nobody threw any light on this (in my opinion) serius misdesign of liferay, at least the flexibility the customizacion of Actions has allowed us to solve it...

we have implemented a LoginPreAction that sees a "redirect" parameter; that parameter is the URL the user first wanted to see, so we just put that value into the HTTP Session (using a servlet session attribute)

then in a new DefaultLandingPageAction class we check wether we have that session value and use it as "last path" so the user goes to where she wanted to go in the first time!

also, we added code to that new DefaultLandingPageAction class to check the organizations the user belongs to, so in effect we have now multiple default landing paths, (portal-ext.properties only allows for one path to be specified and we wanted to move the users to the private pages of the organization they belong to)

as with every other thing in liferay, this is not specially difficult, once you know how it works!!!
thumbnail
Jamie L Sammons, modificado hace 14 años.

RE: land URL when login - Liferay(+CAS) not like other webapps

Junior Member Mensajes: 33 Fecha de incorporación: 18/11/08 Mensajes recientes
I don't suppose you could share the code for that? I am having the same issue with CAS and Liferay.
Bernardo Riveira Faraldo, modificado hace 14 años.

RE: land URL when login - Liferay(+CAS) not like other webapps

Regular Member Mensajes: 135 Fecha de incorporación: 30/10/08 Mensajes recientes
OF COURSE, there it goes... without warranty of any kind emoticon (to use opensource code like liferay and not showing up our code is not only illegal, but uneducated emoticon this is code copied and pasted from opensourced classes, so I suppose in compliance with the license it should be algo opensourced... emoticon

please don't use this as it comes, as THIS IS what we need, but maybe not what you need!

in the loginpreaction we save the "redirect" parameter in the session (if present)


package com.mundor.la3.liferay;

import com.liferay.portal.kernel.events.Action;                             
                                                                                                                                        
import javax.servlet.http.HttpServletRequest;                        
import javax.servlet.http.HttpServletResponse;                       
                                                                     
public class La3LoginPreAction extends Action {                   
                                                                     
    public void run(HttpServletRequest req, HttpServletResponse res) {                                     

    	// nos pillamos el parámetro redirect, es donde quería ir el cliente inicialmente
    	String redirect = req.getParameter("redirect");
    	if (redirect!=null && !("".equals(redirect))) {
    		// lo metemos en la sesión para usarlo en La3DefaultLandingPageAction
    		req.getSession().setAttribute("LA3_REDIRECT", redirect);
    	}
    }  
}


then in the new DefaultLandingPageAction we use that value; the code I put below here is somewhat more "convoluted" as it makes another change we needed... this is the pseudocode:

- if the user entered a full URL (we now because of the LA3_REDIRECT value we saved in the session) then she goes there!

- else, we look at their organizations; (we have more than one); our private organization pages should work as homepages for their users, and there is a "main" organization, so if a user belongs to more than one org, he should go there as first option, (that's why we check if the user organization first page is the same as the global DefaultLandingPage value; if true, the first page the user sees is that one; else, she is redirected to one of the organizations she is member of (we just get the last one)

- else, (should never happen) she goes to the lastpath as configured


package com.mundor.la3.liferay;

/**
 * Personalización para llegar hasta las organizaciones de un usuario
 */

import com.liferay.portal.kernel.events.Action;
import com.liferay.portal.kernel.util.StringPool;
import com.liferay.portal.kernel.util.Validator;
import com.liferay.portal.model.Organization;
import com.liferay.portal.model.User;
import com.liferay.portal.struts.LastPath;
import com.liferay.portal.util.PortalUtil;
import com.liferay.portal.util.PropsKeys;
import com.liferay.portal.util.PropsValues;
import com.liferay.portal.util.WebKeys;

import java.util.Enumeration;
import java.util.HashMap;
import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;


public class La3DefaultLandingPageAction extends Action {

	public void run(HttpServletRequest request, HttpServletResponse response) {
		
    	//_mostrar_datos_peticion(request);    	
		
    	HttpSession session = request.getSession();
    	
    	// esta es la DefaultLandingPage de portal-ext.properties: 
		String pathDefaultLandingPage = PropsValues.DEFAULT_LANDING_PAGE_PATH;
    	
    	// primero vemos si no llegamos aqui con una URL a la que ir
    	
    	String redirect=(String)session.getAttribute("LA3_REDIRECT");
    	
    	if (redirect!=null && !("".equals(redirect))) {
    		
    		// el usuario llega a la3 con una URL completa, por lo que debemos
    		// ir a esa..
    		LastPath lastPath = new LastPath(
					StringPool.BLANK, redirect, new HashMap<string, string[]>()) ;   		
			session.setAttribute(WebKeys.LAST_PATH, lastPath);
			_log.info("redireccion detectada en La3LoginPreAction - " + redirect + " modificamos lastPath");
			
    	} else {

    		// localizamos organizaciones a las que pertenece el usuario
    		
    		try {
    			User usr = PortalUtil.getUser(request);
    			List<organization> orgs = usr.getOrganizations();
    			boolean usarPathDefecto = false;
    			String ultimoPath = null;
    			 
    			for (Organization org : orgs) {
    				ultimoPath = "/liferay/group" + org.getGroup().getFriendlyURL();    				
    				_log.info("usuario pertenece a organizacion '"  + org.getName() + "' con URL privada " + ultimoPath);
    				if (pathDefaultLandingPage.startsWith(ultimoPath)) {
    					// el usuario pertenece a la org. principal, 
    					// así que nos salimos ya y que vaya a esa
    					usarPathDefecto = true;
    					_log.info("es la misma organizacion de la URL de DefaultLandingPage");
    				} 
    			}
    			
    			// ahora, si no encontró la organización por defecto y tenemos al menos otra
    			// vamos a esa otra (nos quedamos realmente con la última del bucle
    			
    			if (!usarPathDefecto &amp;&amp; ultimoPath!=null) {
    				//vamos a esa...
    				LastPath lastPath = new LastPath(
    						StringPool.BLANK, ultimoPath, new HashMap<string, string[]>());    					
    				session.setAttribute(WebKeys.LAST_PATH, lastPath);
    				_log.info("redirigiendo usuario a portada de organizacion con URL privada " + ultimoPath);
    				
    			} else {
    				
    	    		// comportamiento por defecto de liferay con defaultlandingpage...
        			
    				if (Validator.isNotNull(pathDefaultLandingPage)) {
    					LastPath lastPath = new LastPath(
    						StringPool.BLANK, pathDefaultLandingPage, new HashMap<string, string[]>());
    					
    					session.setAttribute(WebKeys.LAST_PATH, lastPath);
    					_log.info("redirigiendo usuario a DefaultLandingPage " + pathDefaultLandingPage);    					
    				}    				
    			}
    				
    			
    		} catch (Exception e) {
				// TODO: handle exception    			
    			e.printStackTrace();
			}
    	}
	}

	private static Log _log = LogFactory.getLog(La3DefaultLandingPageAction.class);

    private static void _mostrar_datos_peticion(HttpServletRequest req) {
    	_log.info("############################################");
        Enumeration pNames = req.getParameterNames();                
        while(pNames.hasMoreElements()) {                            
            String name = (String)pNames.nextElement();                                                                                   
            _log.info("parametro " + name + " = " + req.getParameter(name));        
        }                                                            
        _log.info("contextpath = " + req.getContextPath());        
        _log.info("URI = " + req.getRequestURI());        
        _log.info("querystring = " + req.getQueryString());        
        
        Enumeration hNames = req.getHeaderNames();                
        while(hNames.hasMoreElements()) {                            
            String name = (String)hNames.nextElement();                                                                                   
            _log.info("header " + name + " = " + req.getHeader(name));        
        }
        
        Enumeration aNames = req.getAttributeNames();
        while (aNames.hasMoreElements()) {
        	String name = (String)aNames.nextElement();
        	_log.info("atributo " + name + " = " + req.getHeader(name));
        }
        _log.info("############################################");               
    	
    }
	
}</string,></string,></organization></string,>
Bernardo Riveira Faraldo, modificado hace 14 años.

RE: land URL when login - Liferay(+CAS) not like other webapps

Regular Member Mensajes: 135 Fecha de incorporación: 30/10/08 Mensajes recientes
also, you have to empty the "service url" form field in LifeRay CAS configuration! (if not, you will always be redirected to the same page as the "redirect" parameter is not used..

look at the attached picture

Archivos adjuntos:

thumbnail
Jamie L Sammons, modificado hace 14 años.

RE: land URL when login - Liferay(+CAS) not like other webapps

Junior Member Mensajes: 33 Fecha de incorporación: 18/11/08 Mensajes recientes
Awesome! Thanks for posting that. I'll give it a try and see how it goes.
Bernardo Riveira Faraldo, modificado hace 14 años.

RE: land URL when login - Liferay(+CAS) not like other webapps

Regular Member Mensajes: 135 Fecha de incorporación: 30/10/08 Mensajes recientes
BTW, you can safely trim the "_mostrar_datos_peticion(HttpServletRequest req)" function, as I used it just for debugging purposes (it just throws the parameters, session variables and the like to the log)
Anónimo, modificado hace 14 años.

RE: land URL when login - Liferay(+CAS) not like other webapps

Mensaje: 1
Hi guys,

is it possible the the user will be redirected to the page it came from if the user came from liferay... and if they log in to cas directly they will be redirect to a certain page...


thanks in advance sorry for my poor english,



Bernardo Riveira Faraldo:
OF COURSE, there it goes... without warranty of any kind emoticon (to use opensource code like liferay and not showing up our code is not only illegal, but uneducated emoticon this is code copied and pasted from opensourced classes, so I suppose in compliance with the license it should be algo opensourced... emoticon

please don't use this as it comes, as THIS IS what we need, but maybe not what you need!

in the loginpreaction we save the "redirect" parameter in the session (if present)


package com.mundor.la3.liferay;

import com.liferay.portal.kernel.events.Action;                             
                                                                                                                                        
import javax.servlet.http.HttpServletRequest;                        
import javax.servlet.http.HttpServletResponse;                       
                                                                     
public class La3LoginPreAction extends Action {                   
                                                                     
    public void run(HttpServletRequest req, HttpServletResponse res) {                                     

    	// nos pillamos el parámetro redirect, es donde quería ir el cliente inicialmente
    	String redirect = req.getParameter("redirect");
    	if (redirect!=null &amp;&amp; !("".equals(redirect))) {
    		// lo metemos en la sesión para usarlo en La3DefaultLandingPageAction
    		req.getSession().setAttribute("LA3_REDIRECT", redirect);
    	}
    }  
}


then in the new DefaultLandingPageAction we use that value; the code I put below here is somewhat more "convoluted" as it makes another change we needed... this is the pseudocode:

- if the user entered a full URL (we now because of the LA3_REDIRECT value we saved in the session) then she goes there!

- else, we look at their organizations; (we have more than one); our private organization pages should work as homepages for their users, and there is a "main" organization, so if a user belongs to more than one org, he should go there as first option, (that's why we check if the user organization first page is the same as the global DefaultLandingPage value; if true, the first page the user sees is that one; else, she is redirected to one of the organizations she is member of (we just get the last one)

- else, (should never happen) she goes to the lastpath as configured


package com.mundor.la3.liferay;

/**
 * Personalización para llegar hasta las organizaciones de un usuario
 */

import com.liferay.portal.kernel.events.Action;
import com.liferay.portal.kernel.util.StringPool;
import com.liferay.portal.kernel.util.Validator;
import com.liferay.portal.model.Organization;
import com.liferay.portal.model.User;
import com.liferay.portal.struts.LastPath;
import com.liferay.portal.util.PortalUtil;
import com.liferay.portal.util.PropsKeys;
import com.liferay.portal.util.PropsValues;
import com.liferay.portal.util.WebKeys;

import java.util.Enumeration;
import java.util.HashMap;
import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;


public class La3DefaultLandingPageAction extends Action {

	public void run(HttpServletRequest request, HttpServletResponse response) {
		
    	//_mostrar_datos_peticion(request);    	
		
    	HttpSession session = request.getSession();
    	
    	// esta es la DefaultLandingPage de portal-ext.properties: 
		String pathDefaultLandingPage = PropsValues.DEFAULT_LANDING_PAGE_PATH;
    	
    	// primero vemos si no llegamos aqui con una URL a la que ir
    	
    	String redirect=(String)session.getAttribute("LA3_REDIRECT");
    	
    	if (redirect!=null &amp;&amp; !("".equals(redirect))) {
    		
    		// el usuario llega a la3 con una URL completa, por lo que debemos
    		// ir a esa..
    		LastPath lastPath = new LastPath(
					StringPool.BLANK, redirect, new HashMap<string, string[]>()) ;   		
			session.setAttribute(WebKeys.LAST_PATH, lastPath);
			_log.info("redireccion detectada en La3LoginPreAction - " + redirect + " modificamos lastPath");
			
    	} else {

    		// localizamos organizaciones a las que pertenece el usuario
    		
    		try {
    			User usr = PortalUtil.getUser(request);
    			List<organization> orgs = usr.getOrganizations();
    			boolean usarPathDefecto = false;
    			String ultimoPath = null;
    			 
    			for (Organization org : orgs) {
    				ultimoPath = "/liferay/group" + org.getGroup().getFriendlyURL();    				
    				_log.info("usuario pertenece a organizacion '"  + org.getName() + "' con URL privada " + ultimoPath);
    				if (pathDefaultLandingPage.startsWith(ultimoPath)) {
    					// el usuario pertenece a la org. principal, 
    					// así que nos salimos ya y que vaya a esa
    					usarPathDefecto = true;
    					_log.info("es la misma organizacion de la URL de DefaultLandingPage");
    				} 
    			}
    			
    			// ahora, si no encontró la organización por defecto y tenemos al menos otra
    			// vamos a esa otra (nos quedamos realmente con la última del bucle
    			
    			if (!usarPathDefecto &amp;&amp; ultimoPath!=null) {
    				//vamos a esa...
    				LastPath lastPath = new LastPath(
    						StringPool.BLANK, ultimoPath, new HashMap<string, string[]>());    					
    				session.setAttribute(WebKeys.LAST_PATH, lastPath);
    				_log.info("redirigiendo usuario a portada de organizacion con URL privada " + ultimoPath);
    				
    			} else {
    				
    	    		// comportamiento por defecto de liferay con defaultlandingpage...
        			
    				if (Validator.isNotNull(pathDefaultLandingPage)) {
    					LastPath lastPath = new LastPath(
    						StringPool.BLANK, pathDefaultLandingPage, new HashMap<string, string[]>());
    					
    					session.setAttribute(WebKeys.LAST_PATH, lastPath);
    					_log.info("redirigiendo usuario a DefaultLandingPage " + pathDefaultLandingPage);    					
    				}    				
    			}
    				
    			
    		} catch (Exception e) {
				// TODO: handle exception    			
    			e.printStackTrace();
			}
    	}
	}

	private static Log _log = LogFactory.getLog(La3DefaultLandingPageAction.class);

    private static void _mostrar_datos_peticion(HttpServletRequest req) {
    	_log.info("############################################");
        Enumeration pNames = req.getParameterNames();                
        while(pNames.hasMoreElements()) {                            
            String name = (String)pNames.nextElement();                                                                                   
            _log.info("parametro " + name + " = " + req.getParameter(name));        
        }                                                            
        _log.info("contextpath = " + req.getContextPath());        
        _log.info("URI = " + req.getRequestURI());        
        _log.info("querystring = " + req.getQueryString());        
        
        Enumeration hNames = req.getHeaderNames();                
        while(hNames.hasMoreElements()) {                            
            String name = (String)hNames.nextElement();                                                                                   
            _log.info("header " + name + " = " + req.getHeader(name));        
        }
        
        Enumeration aNames = req.getAttributeNames();
        while (aNames.hasMoreElements()) {
        	String name = (String)aNames.nextElement();
        	_log.info("atributo " + name + " = " + req.getHeader(name));
        }
        _log.info("############################################");               
    	
    }
	
}</string,></string,></organization></string,>
Bernardo Riveira Faraldo, modificado hace 14 años.

RE: land URL when login - Liferay(+CAS) not like other webapps

Regular Member Mensajes: 135 Fecha de incorporación: 30/10/08 Mensajes recientes
Sorry, I'm not sure what your needs are :-? It seems related to what we have made, but...
thumbnail
garry b baal, modificado hace 14 años.

RE: land URL when login - Liferay(+CAS) not like other webapps

New Member Mensajes: 3 Fecha de incorporación: 27/04/09 Mensajes recientes
Bernardo Riveira Faraldo:
Sorry, I'm not sure what your needs are :-? It seems related to what we have made, but...


Hi,


I have cas server and liferay server... my liferay uses cas to login here's some senario hope it will make it clear

I am in the [liferay]/web/guest/sample1 then I login I should be redirected to [liferay]/web/guest/sample1(assuming a successful login)

this works fine if I set auth.forward.by.last.path to true (with return me from where I logging)

the issue is when I login directly in Cas [cas]/login
I am redirecting to [liferay]/user/[username]/home (which we don't user to there private page after login)
if we set default.landing.page.path=/web/guest/home this will solve the issue not allowing the user to go to there private page

but auth.forward.by.last.path will not work any more we will not return form what page we came from..


basically

we want user to return to the last path where they click sign in( liferay pages), now if the user logs-in directly in cas server (assuming they know the url) we want them to be redirected to /web/guest/home after login.

I don't how and where to fix this issue.. any suggestions?

thank Bernardo, thanks everyone in advance,