OF COURSE, there it goes... without warranty of any kind

(to use opensource code like liferay and not showing up our code is not only illegal, but uneducated

this is code copied and pasted from opensourced classes, so I suppose in compliance with the license it should be algo opensourced...

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)
1
2package com.mundor.la3.liferay;
3
4import com.liferay.portal.kernel.events.Action;
5
6import javax.servlet.http.HttpServletRequest;
7import javax.servlet.http.HttpServletResponse;
8
9public class La3LoginPreAction extends Action {
10
11 public void run(HttpServletRequest req, HttpServletResponse res) {
12
13 // nos pillamos el parámetro redirect, es donde quería ir el cliente inicialmente
14 String redirect = req.getParameter("redirect");
15 if (redirect!=null && !("".equals(redirect))) {
16 // lo metemos en la sesión para usarlo en La3DefaultLandingPageAction
17 req.getSession().setAttribute("LA3_REDIRECT", redirect);
18 }
19 }
20}
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
1
2package com.mundor.la3.liferay;
3
4/**
5 * Personalización para llegar hasta las organizaciones de un usuario
6 */
7
8import com.liferay.portal.kernel.events.Action;
9import com.liferay.portal.kernel.util.StringPool;
10import com.liferay.portal.kernel.util.Validator;
11import com.liferay.portal.model.Organization;
12import com.liferay.portal.model.User;
13import com.liferay.portal.struts.LastPath;
14import com.liferay.portal.util.PortalUtil;
15import com.liferay.portal.util.PropsKeys;
16import com.liferay.portal.util.PropsValues;
17import com.liferay.portal.util.WebKeys;
18
19import java.util.Enumeration;
20import java.util.HashMap;
21import java.util.List;
22
23import javax.servlet.http.HttpServletRequest;
24import javax.servlet.http.HttpServletResponse;
25import javax.servlet.http.HttpSession;
26
27import org.apache.commons.logging.Log;
28import org.apache.commons.logging.LogFactory;
29
30
31public class La3DefaultLandingPageAction extends Action {
32
33 public void run(HttpServletRequest request, HttpServletResponse response) {
34
35 //_mostrar_datos_peticion(request);
36
37 HttpSession session = request.getSession();
38
39 // esta es la DefaultLandingPage de portal-ext.properties:
40 String pathDefaultLandingPage = PropsValues.DEFAULT_LANDING_PAGE_PATH;
41
42 // primero vemos si no llegamos aqui con una URL a la que ir
43
44 String redirect=(String)session.getAttribute("LA3_REDIRECT");
45
46 if (redirect!=null && !("".equals(redirect))) {
47
48 // el usuario llega a la3 con una URL completa, por lo que debemos
49 // ir a esa..
50 LastPath lastPath = new LastPath(
51 StringPool.BLANK, redirect, new HashMap<String, String[]>()) ;
52 session.setAttribute(WebKeys.LAST_PATH, lastPath);
53 _log.info("redireccion detectada en La3LoginPreAction - " + redirect + " modificamos lastPath");
54
55 } else {
56
57 // localizamos organizaciones a las que pertenece el usuario
58
59 try {
60 User usr = PortalUtil.getUser(request);
61 List<Organization> orgs = usr.getOrganizations();
62 boolean usarPathDefecto = false;
63 String ultimoPath = null;
64
65 for (Organization org : orgs) {
66 ultimoPath = "/liferay/group" + org.getGroup().getFriendlyURL();
67 _log.info("usuario pertenece a organizacion '" + org.getName() + "' con URL privada " + ultimoPath);
68 if (pathDefaultLandingPage.startsWith(ultimoPath)) {
69 // el usuario pertenece a la org. principal,
70 // así que nos salimos ya y que vaya a esa
71 usarPathDefecto = true;
72 _log.info("es la misma organizacion de la URL de DefaultLandingPage");
73 }
74 }
75
76 // ahora, si no encontró la organización por defecto y tenemos al menos otra
77 // vamos a esa otra (nos quedamos realmente con la última del bucle
78
79 if (!usarPathDefecto && ultimoPath!=null) {
80 //vamos a esa...
81 LastPath lastPath = new LastPath(
82 StringPool.BLANK, ultimoPath, new HashMap<String, String[]>());
83 session.setAttribute(WebKeys.LAST_PATH, lastPath);
84 _log.info("redirigiendo usuario a portada de organizacion con URL privada " + ultimoPath);
85
86 } else {
87
88 // comportamiento por defecto de liferay con defaultlandingpage...
89
90 if (Validator.isNotNull(pathDefaultLandingPage)) {
91 LastPath lastPath = new LastPath(
92 StringPool.BLANK, pathDefaultLandingPage, new HashMap<String, String[]>());
93
94 session.setAttribute(WebKeys.LAST_PATH, lastPath);
95 _log.info("redirigiendo usuario a DefaultLandingPage " + pathDefaultLandingPage);
96 }
97 }
98
99
100 } catch (Exception e) {
101 // TODO: handle exception
102 e.printStackTrace();
103 }
104 }
105 }
106
107 private static Log _log = LogFactory.getLog(La3DefaultLandingPageAction.class);
108
109 private static void _mostrar_datos_peticion(HttpServletRequest req) {
110 _log.info("############################################");
111 Enumeration pNames = req.getParameterNames();
112 while(pNames.hasMoreElements()) {
113 String name = (String)pNames.nextElement();
114 _log.info("parametro " + name + " = " + req.getParameter(name));
115 }
116 _log.info("contextpath = " + req.getContextPath());
117 _log.info("URI = " + req.getRequestURI());
118 _log.info("querystring = " + req.getQueryString());
119
120 Enumeration hNames = req.getHeaderNames();
121 while(hNames.hasMoreElements()) {
122 String name = (String)hNames.nextElement();
123 _log.info("header " + name + " = " + req.getHeader(name));
124 }
125
126 Enumeration aNames = req.getAttributeNames();
127 while (aNames.hasMoreElements()) {
128 String name = (String)aNames.nextElement();
129 _log.info("atributo " + name + " = " + req.getHeader(name));
130 }
131 _log.info("############################################");
132
133 }
134
135}
Please sign in to flag this as inappropriate.