« Zurück zu Custom Post-login...

Customizing the default page after login

How do I specify which page a newly logged in user gets redirected to?

How do I redirect my users to the page they were just looking at.. after they login? #

All you need to do is set the following value in your portal-ext.properties file:

auth.forward.by.last.path=true

Also make sure that there is no landing page defined. Remove lines with

default.landing.page.path

How do I redirect my users to a specific page (or community).. after they login? #

4.3.x and on #

If your "redirect rule" is very simple.. such as "after login, redirect all users to page '/web/guest/home'", then you just need to add 2 values to your properties file:

auth.forward.by.last.path=true
default.landing.page.path=/web/guest/home

If you want to include more complex logic, you will need to modify the DefaultLandingPageAction.java file

DefaultLandingPageAction.java #

In portal.properties, notice the property login.events.post, after LoginPostAction is called, DefaultLandingPageAction is also called.

    login.events.post=com.liferay.portal.events.LoginPostAction,com.liferay.portal.events.DefaultLandingPageAction

This class "DefaultLandingPageAction.java" has been created for you here:

/portal-impl/src/com/liferay/portal/events/DefaultLandingPageAction.java

Liferay is setup to read two properties, AUTH_FORWARD_BY_LAST_PATH and DEFAULT_LANDING_PAGE_PATH. To do more complex redirect logic, we are basically setting a property to tell Liferay to send the newly logged in user to the page specified in path, the page he was just looking at. BUT.. before we do this, we override the value of path. Now we have complete control over where to send the user.

For more complex redirect logic we just need to pull the necessary values to get our desired path, then override the path variable.

You can look at this code snippet to help get you started on how to pull the desired information:

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

		User user = themeDisplay.getUser();

		long userId = themeDisplay.getUserId();

		List userGroups = UserGroupLocalServiceUtil.getUserUserGroups(userId);

Finally, override this path variable

		String path = PropsUtil.get(PropsUtil.DEFAULT_LANDING_PAGE_PATH);

4.2.x and before #

take a look at the bottom of the LoginPostAction.java file. at the bottom of the run method is some code that has been commented out:

portal-ejb\src\com\liferay\portal\events\LoginPostAction.java:

         // To manually set a path for the user to forward to, edit
         // portal.properties and set auth.forward.by.last.path to true.

         /*Map params = new HashMap();

         params.put("p_l_id", new String[] {"PRI.3.1"});

         LastPath lastPath = new LastPath("/c", "/portal/layout", params);

         ses.setAttribute(WebKeys.LAST_PATH, lastPath);*/

If you switch the "auth.forward.by.last.path" variable to "true", then after you login, it will redirect you to the url you were just at before you logged in.. which is stored in the variable "lastPath".

Soo.. lets say that you wanted to redirect certain users to certain pages. If you changed that "lastPath" value.. you now control what page the newly logged in user would get redirected to. You could get the logged in user info via:

PortalUtil.getUserId(req)

and then query the database based on that userid to get other info.

On a side note, if you were to do this quickly, you can just uncomment the code and add your own logic to set the lastPath variable at the end of the LoginPostAction method, but a cleaner way would be to put these modifications elsewhere.

1. create a new class, and in the run() method, put in your code. This class will have the same structure as LoginPostAction, except that it only contains the new code (the code that was commented out).

2. Then change the value in "portal.properties" by editting your "portal-ext.properties" file so that it will also hit your newly created class.

3. Add your own class to the "login.events.post" line so that it looks something like:

login.events.post=com.liferay.portal.events.LoginPostAction,yourclasshere
0 Anhänge
140697 Angesehen
Durchschnitt (1 Stimme)
Die durchschnittliche Bewertung ist 2.0 von max. 5 Sternen.
Kommentare
Antworten im Thread Autor Datum
Test for... Arcko Duan 22. Juli 2008 19:39
I'm on 5.1.1 and this: ... Bob Evans 27. September 2008 13:12
For me it works fine. You have to set the... Paul Voors 30. September 2008 03:36
How do you set the friendly url? I am having... Michael Poznecki 29. Januar 2009 07:05
Hi Michael, I'm looking for the same... please... suresh reddy k 29. Januar 2009 13:32
hi, go to manage pages select the page for... Sachin Pathare 23. April 2009 05:58
Michael, From the 'Communities' admin portlet... Jason Reast-Jones 2. Februar 2009 07:50
Its working fine.. Thanks Ravi Kumar Gupta 1. Juli 2009 03:17
We have implemented a CustomLandingPageAction... Edgar Vonk 24. September 2009 06:17
Did you solve this issue? I have a similar... Andreas Thiel 5. November 2009 07:04
I worked a bit on it. I injected my own... Andreas Thiel 6. November 2009 03:34
Interesting! No, I never found a solution for... Edgar Vonk 18. November 2009 04:23
Two gotchas I found when implementing my own... Peter Connolly 25. September 2009 11:52
I have now been trying to make my own... Armaz Mellati 9. Januar 2011 04:02
Now I got it working. It was kind of my own... Armaz Mellati 9. Januar 2011 12:29
I have the same problem,I need to get the user... mohamed bouker 28. April 2011 09:53
I m doing the same thing using hook ,but... Nitesh Kr Sahay 10. Januar 2012 04:13

Test for http://support.liferay.com/browse/LEP-6816
Gepostet am 22.07.08 19:39.
I'm on 5.1.1 and this:

auth.forward.by.last.path=true
default.landing.page.path=/web/guest/home

is simply not working.

I set default.landing.page.path=/web/10601/home

and it ALWAYS goes to /group/10601/1.

This is holding up our release to production. HELP PLEASE.
Gepostet am 27.09.08 13:12.
For me it works fine.
You have to set the friendly url for the home page /home where your refer to in: "/web/10601/home".
(you can set an friendly url for "10601" to!)
Gepostet am 30.09.08 03:36 als Antwort auf Bob Evans.
How do you set the friendly url? I am having the same problem that Bob did.
Gepostet am 29.01.09 07:05 als Antwort auf Paul Voors.
Hi Michael,

I'm looking for the same... please let me know if you get pointers!!!

Suresh
Gepostet am 29.01.09 13:32 als Antwort auf Michael Poznecki.
Michael,

From the 'Communities' admin portlet either search for your community or click 'All Communities'. On the action menu for the community in question go to 'Manage Pages' Then click the 'Settings' tab, then 'Virtual Host', it's a bit misleading, but that's where you set the Friendly URL.

Jason
Gepostet am 02.02.09 07:50 als Antwort auf Michael Poznecki.
hi,
go to manage pages select the page for which u want, there is a option for friendly URL, change it accordingly

Sachin
Gepostet am 23.04.09 05:58 als Antwort auf suresh reddy k.
Gepostet am 01.07.09 03:17.
We have implemented a CustomLandingPageAction using the description above and this works just fine. We have separate landing pages depending on the role of the user.

However I would also like to be able to redirect users to their landing page whenever they go the root URL of our portal ('/'). The functionality we have now is:
# user logs in
# Liferay redirects user to correct landing page (using our CustomLandingPageAction). e.g.: http://localhost:8080/group/test/home
# user manually changes the URL or follows a bookmark to: http://localhost:8080
# Liferay redirects the user to the _default_ landing page: http://localhost:8080/web/guest (or whatever URL is configured using the default.landing.page.path)

Is there an event or filter somewhere in Liferay that we can use to send users to their landing page when they go to the root URL?
Gepostet am 24.09.09 06:17.
Two gotchas I found when implementing my own landing page forward logic:

1. The code for getting the user info returns null on the line:
ThemeDisplay themeDisplay = (ThemeDisplay)req.getAttribute(WebKeys.THEME_DISPLAY);

I had to get the user information this way instead:

String userIdString = request.getUserPrincipal().getName();
long userId = new Long(userIdString);
User user = UserLocalServiceUtil.getUser(userId);

2. The instructions don't talk about how to deploy the modified DefaultLandingPageAction. You could open portal-impl.jar and replace DefaultLandingPageAction.class. I'm not a big fan of modifying vendor jars. I would recommend opening portal-ext.properties and adding a line like this:

login.events.post=com.liferay.portal.events.LoginPostAction,com.liferay.por­tal.events.MyLandingPageAction

Create a class named MyLandingPageAction (you can look at the source for DefaultLandingPageAction for a sample) and modify accordingly. Jar it up by itself and then drop the jar in tomcat-6.0.18\webapps\ROOT\WEB-INF\lib
Gepostet am 25.09.09 11:52.
Did you solve this issue? I have a similar demand: The company logo, normally placed in the top left, refers to ThemeDisplay.getURLHome(), which is _not_ the page my custom landing page dispatcher selects on login. How to achieve this?

Currently, I'm thinking about patching init.vm in the theme - this is where $company_url is set -; or to overwrite ThemeDisplay.setURLHome() - I have no clue what side effects this could cause.

Anybody?
Gepostet am 05.11.09 07:04 als Antwort auf Edgar Vonk.
I worked a bit on it.

I injected my own PortalUtil class, replacing PortalImpl, by adding the following lines to ext-spring.xml:

<bean id="com.liferay.portal.util.PortalUtil" class="com.liferay.portal.util.PortalUtil">
<property name="portal">
<bean class="com.vodafone.portal.liferay.MyPortalImpl" />
</property>
</bean>

MyPortalImpl inherits from PortalImpl and overrides the getHomeURL() method:

public class MyPortalImpl extends PortalImpl
{

@Override
public String getHomeURL(HttpServletRequest request) throws PortalException, SystemException
{
String portalURL = getPortalURL(request);
Company company = getCompany(request);
String homeURL = company.getHomeURL();
if (Validator.isNull(homeURL))
{
homeURL = PropsValues.COMPANY_DEFAULT_HOME_URL;
}

// added
HttpSession session = request.getSession(false);
if (session != null)
{
LastPath lp = (LastPath) session.getAttribute("LANDING_PAGE");
if (lp != null)
{
String specificHomeURL = lp.getPath();
if (Validator.isNotNull(specificHomeURL))
{
homeURL = specificHomeURL;
}
}
}
// end

return portalURL + getPathContext() + homeURL;
}
}

Works like a charm - unitl now ;-)

Could someone validate this approach? Is it feasible? Any sideeffects I did not encounter yet? Would it make sense to extend the "home URL" concept/strategy of Liferay in this regard (user specific home page takes precedence over company home page, takes precedence over default company home page)?
Gepostet am 06.11.09 03:34 als Antwort auf Andreas Thiel.
Interesting! No, I never found a solution for our problem. Quite bizarre because it seems to me almost everybody would have this issue.

Anyway, your solution sounds pretty good. How did you package this stuff? Where is the ext-spring.xml you are talking about?
Gepostet am 18.11.09 04:23 als Antwort auf Andreas Thiel.
I have now been trying to make my own DefaultLandingPageAction to work for several hours, but it just doesn't matter what I set the path to. No matter the value of the path set to the session by this code, it has no effect. I still get redirected to the 'guest' community.

LastPath lastPath = new LastPath(
StringPool.BLANK,
path,
new HashMap<String, String[]>());
HttpSession session = request.getSession();
session.setAttribute(WebKeys.LAST_PATH, lastPath);

I am starting to think I am facing a bug in 6.0.5.

Has anybody got this working on 6.0.5 ?

Regards,
Armaz (in very bad mood)
Gepostet am 09.01.11 04:02.
Now I got it working. It was kind of my own fault.
I missed this one :
auth.forward.by.last.path=true
I had it set to false.

Now that I got here, I can summarize my experience :
- first I had a lot of problems making it work as an ext-plugin. I just had to give up, since the classloader just ignored my class and used the original one. I had to do it as Peter suggested. I made my own class and put it beside the original one in the source-code of the LR-portal. So I made a jar of the resulting Class file and put it in the lib directory under ROOT.

- So I got to the other problem that everyone else have pointed out, there is no WebKeys.THEME_DISPLAY in the session emoticon. Very irritating since I planed to use it in a call like this
group.getPathFriendlyURL(privateLayout, themeDisplay)
My workaround is hardcoding that part of the path ("/group").

- My last problem was the one I started this post with.

Good luck to other who are to walk this path.

Regards,
Armaz
Gepostet am 09.01.11 12:29 als Antwort auf Armaz Mellati.
I have the same problem,I need to get the user 's custum attribute by doing :
User us=PortalUtil.getUser(request);
String default =us.getExpandoBridge().getAttribute("nameofattr");
string path="/web/"+default;
but i can't get the expandobridge from session can you help me
Gepostet am 28.04.11 09:53 als Antwort auf Armaz Mellati.
I m doing the same thing using hook ,but classloader ignored my classes...
what can i do for this?........
Gepostet am 10.01.12 04:13 als Antwort auf mohamed bouker.