I was writing my own custom portlet for login process and I thought that as long as I call LoginUtil.login (from portal-impl.jar.) it will log me in. Then I realized that you can't have custom portlets using portal-impl.jar.
I think you can do it the ext plugin way, which I haven't tried.
But the following worked for me.
You can still use the service/method calls in portal-impl.jar from your custom portlets using PortalClassInvoker (from portal-service.jar located in tomcat/lib/ext), as follows (Thanks to Gordon Augat for telling me about this)
1MethodKey key = new MethodKey("com.liferay.portlet.login.util.LoginUtil", "login", HttpServletRequest.class, HttpServletResponse.class, String.class, String.class, boolean.class, String.class);
2PortalClassInvoker.invoke(false, key, new Object[] { PortalUtil.getHttpServletRequest(portletRequest), PortalUtil.getHttpServletResponse(portletResponse), username, password false, null});
after this redirect to,
1
2ThemeDisplay().getPathMain()
I don't want to go into details but, there is some classloader hierarchy/visibility magic happening here.
But, I had to do couple of more things to make it work.
1. set this in external portal properties file. I think it depends on what you are using to create custom portlets. I was using Vaadin and if I had this to true, the login process was invalidating the session, which was making my vaadin application freak out on me.
1
2session.enable.phishing.protection=false
Even after that my login didn't work. The LoginUtil.login method was being called correctly but I am still getting the login screen.
2.in liferay-portlet.xml, set the following. It took me couple of days to figure this out.
1
2 <private-session-attributes>false</private-session-attributes>
**NOTE: Liferay expects the <tags> in liferay-portlet.xml in certain order, otherwise it is barfing on me.
The Login process was like this, LoginUtil.login does its work and the com.liferay.portal.servlet.MainServlet.loginUser was making the login stick for the session by looking for some attributes ("j_remoteuser", "j_username" and few others) set by LoginUtil.login. The problem I had with my process was , when I call the LoginUtil.login method, it is setting lots of stuff in session object (gets from the request object I was sending) The session it was setting all of those was a PORTLETSESSION instance and MainServlet is looking into PORTALSESSION. So, I had to make sure that there is no private portlet session for my custom login portlet and have it use the portal session.
And that worked for me.
Hope that helps
Please sign in to flag this as inappropriate.