Forums de discussion
[Resolved] Custom Post Login Redirect
Thomas Berg, modifié il y a 14 années.
[Resolved] Custom Post Login Redirect
Regular Member Publications: 131 Date d'inscription: 07/09/09 Publications récentes
Hi,
I've been developing a HOOK that runs a custom PostLoginAction class on the event "login.events.post", using Liferay 5.2.3 (Tomcat-bundle)
I think i've read most of the countless "Redirect after login" - questions that's been posted in the forums but haven't been able to get this working.
In my class CustomPostLogin, i've got the following code:
My hook also includes a portal.properties with the following setting:
However, when running the code I get this exception:
I also noticed that when using the alternate constructor for com.liferay.portal.struts.LastPath
i get a NullPointerException:
This became a lenghty post but hopefully informative. Is this some sort of bug or have I done something stupid :-)
Thanks for reading
/ Thomas
I've been developing a HOOK that runs a custom PostLoginAction class on the event "login.events.post", using Liferay 5.2.3 (Tomcat-bundle)
I think i've read most of the countless "Redirect after login" - questions that's been posted in the forums but haven't been able to get this working.
In my class CustomPostLogin, i've got the following code:
Map<string, string[]> params = new HashMap<string, string[]>();
params.put("p_l_id", new String[] {"PUB.1.1"});
LastPath lastPath = new LastPath(StringPool.BLANK, "/web/guest/some-page", params);
session.setAttribute(WebKeys.LAST_PATH, lastPath);
</string,></string,>
My hook also includes a portal.properties with the following setting:
auth.forward.by.last.path=true
However, when running the code I get this exception:
java.lang.ClassCastException: com.liferay.portal.struts.LastPath cannot be cast to com.liferay.portal.struts.LastPath
com.liferay.portal.struts.PortalRequestProcessor.getLastPath(PortalRequestProcessor.java:407)
com.liferay.portal.struts.PortalRequestProcessor.process(PortalRequestProcessor.java:146)
org.apache.struts.action.ActionServlet.process(ActionServlet.java:1196)
org.apache.struts.action.ActionServlet.doGet(ActionServlet.java:414)
javax.servlet.http.HttpServlet.service(HttpServlet.java:617)
com.liferay.portal.servlet.MainServlet.callParentService(MainServlet.java:608)
com.liferay.portal.servlet.MainServlet.service(MainServlet.java:846)
javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
com.liferay.portal.kernel.servlet.BaseFilter.processFilter(BaseFilter.java:154)
com.liferay.portal.servlet.filters.secure.SecureFilter.processFilter(SecureFilter.java:282)
com.liferay.portal.kernel.servlet.BaseFilter.doFilter(BaseFilter.java:91)
com.liferay.portal.kernel.servlet.BaseFilter.processFilter(BaseFilter.java:154)
com.liferay.portal.sharepoint.SharepointFilter.processFilter(SharepointFilter.java:193)
com.liferay.portal.kernel.servlet.BaseFilter.doFilter(BaseFilter.java:91)
com.liferay.portal.kernel.servlet.BaseFilter.processFilter(BaseFilter.java:154)
com.liferay.portal.servlet.filters.virtualhost.VirtualHostFilter.doFilter(VirtualHostFilter.java:148)
com.liferay.portal.kernel.servlet.BaseFilter.processFilter(BaseFilter.java:154)
com.liferay.portal.servlet.filters.threadlocalcache.ThreadLocalCacheFilter.processFilter(ThreadLocalCacheFilter.java:55)
com.liferay.portal.kernel.servlet.BaseFilter.doFilter(BaseFilter.java:91)
com.liferay.portal.kernel.servlet.BaseFilter.processFilter(BaseFilter.java:154)
com.liferay.portal.kernel.servlet.BaseFilter.doFilter(BaseFilter.java:94)
org.tuckey.web.filters.urlrewrite.UrlRewriteFilter.doFilter(UrlRewriteFilter.java:738)
I also noticed that when using the alternate constructor for com.liferay.portal.struts.LastPath
LastPath lastPath = new LastPath(StringPool.BLANK, "/web/guest/some-page");
i get a NullPointerException:
19:51:15,734 ERROR MainServlet:794 - com.liferay.portal.kernel.events.ActionException: java.lang.NullPointerException
com.liferay.portal.kernel.events.ActionException: java.lang.NullPointerException
at se.miun.portal.account.CustomPostLogin.run(CustomPostLogin.java:139)
at com.liferay.portal.kernel.events.InvokerAction.run(InvokerAction.java:52)
at com.liferay.portal.events.EventsProcessorImpl.processEvent(EventsProcessorImpl.java:92)
at com.liferay.portal.events.EventsProcessorImpl.process(EventsProcessorImpl.java:79)
at com.liferay.portal.events.EventsProcessorUtil.process(EventsProcessorUtil.java:64)
at com.liferay.portal.servlet.MainServlet.service(MainServlet.java:789)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at com.liferay.portal.kernel.servlet.BaseFilter.processFilter(BaseFilter.java:154)
at com.liferay.portal.servlet.filters.secure.SecureFilter.processFilter(SecureFilter.java:282)
at com.liferay.portal.kernel.servlet.BaseFilter.doFilter(BaseFilter.java:91)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at com.liferay.portal.kernel.servlet.BaseFilter.processFilter(BaseFilter.java:154)
at com.liferay.portal.sharepoint.SharepointFilter.processFilter(SharepointFilter.java:193)
at com.liferay.portal.kernel.servlet.BaseFilter.doFilter(BaseFilter.java:91)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at com.liferay.portal.kernel.servlet.BaseFilter.processFilter(BaseFilter.java:154)
at com.liferay.portal.servlet.filters.virtualhost.VirtualHostFilter.doFilter(VirtualHostFilter.java:148)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at com.liferay.portal.kernel.servlet.BaseFilter.processFilter(BaseFilter.java:154)
at com.liferay.portal.servlet.filters.threadlocalcache.ThreadLocalCacheFilter.processFilter(ThreadLocalCacheFilter.java:55)
at com.liferay.portal.kernel.servlet.BaseFilter.doFilter(BaseFilter.java:91)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at com.liferay.portal.kernel.servlet.BaseFilter.processFilter(BaseFilter.java:154)
at com.liferay.portal.kernel.servlet.BaseFilter.doFilter(BaseFilter.java:94)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.tuckey.web.filters.urlrewrite.UrlRewriteFilter.doFilter(UrlRewriteFilter.java:738)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:433)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:128)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:286)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:845)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:583)
at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:447)
at java.lang.Thread.run(Thread.java:619)
Caused by: java.lang.NullPointerException
at java.util.HashMap.<init>(HashMap.java:223)
at java.util.LinkedHashMap.<init>(LinkedHashMap.java:195)
at com.liferay.portal.struts.LastPath.<init>(LastPath.java:47)
at com.liferay.portal.struts.LastPath.<init>(LastPath.java:39)
at se.miun.portal.account.CustomPostLogin.run(CustomPostLogin.java:130)
... 45 more
</init></init></init></init>
This became a lenghty post but hopefully informative. Is this some sort of bug or have I done something stupid :-)
Thanks for reading
/ Thomas
Shagul Khaja, modifié il y a 14 années.
RE: Custom Post Login Redirect
Liferay Master Publications: 758 Date d'inscription: 27/09/07 Publications récentes
Hi Thomas,
LastPath.java is in portal-impl. Any class in portal-impl is not meant to be used in plugins.
You may have to do this in the Ext environment.
Best Regards,
Shagul
LastPath.java is in portal-impl. Any class in portal-impl is not meant to be used in plugins.
You may have to do this in the Ext environment.
Best Regards,
Shagul
Thomas Berg, modifié il y a 14 années.
RE: Custom Post Login Redirect
Regular Member Publications: 131 Date d'inscription: 07/09/09 Publications récentes
Hi Shagul,
Thanks for your reply.
I'm not including portal-impl.jar in my hook but have referenced tomcat/webapps/ROOT/WEB-INF/lib/portal-impl.jar as an external jar on the build-path and set it as a dependency in liferay-plugin-package.properties.
But of course, you're right, by using a hook (plugin) there will be another class-loader involved. I really like the idea of not touching the core of Liferay, using only plugins. I'll have to think of some other solution to this. Thanks again for your answer
Best regards
Thomas
Thanks for your reply.
I'm not including portal-impl.jar in my hook but have referenced tomcat/webapps/ROOT/WEB-INF/lib/portal-impl.jar as an external jar on the build-path and set it as a dependency in liferay-plugin-package.properties.
But of course, you're right, by using a hook (plugin) there will be another class-loader involved. I really like the idea of not touching the core of Liferay, using only plugins. I'll have to think of some other solution to this. Thanks again for your answer
Best regards
Thomas
Nicolas Grolleau, modifié il y a 14 années.
RE: Custom Post Login Redirect
Junior Member Publications: 90 Date d'inscription: 12/11/09 Publications récentes
I think you should make your plugin run in the server classpath.
try to add a context.xml file in docroot\META-INF:
That's what's done in sample-struts-liferay-portlet to be able to use liferay struts in plugin.
But this works only for tomcat.
Or you'll have to wait for next version of liferay to be able to replace struts actions in hooks.
try to add a context.xml file in docroot\META-INF:
<Context>
<Loader
loaderClass="com.liferay.support.tomcat.loader.PortalClassLoader"
/>
</Context>
That's what's done in sample-struts-liferay-portlet to be able to use liferay struts in plugin.
But this works only for tomcat.
Or you'll have to wait for next version of liferay to be able to replace struts actions in hooks.
Shagul Khaja, modifié il y a 14 années.
RE: Custom Post Login Redirect
Liferay Master Publications: 758 Date d'inscription: 27/09/07 Publications récentes
Hi Thomas,
Most of the ext is coming to the plugins in the next release/trunk. Take a look at the below forum post.
EXT vs Plugins
Also in the latest/trunk you will not be able to include portal-impl.jar as a dependency as you did in your current liferay-plugin-package.properties. Ant build script will fail.
Take a look at the below ticket.
Prevent inclusion of portal-impl.jar in plugins
The idea is to make is easy to extend and easy to revert by just undeploying the plugins.
Hope this helps.
-Shagul
Most of the ext is coming to the plugins in the next release/trunk. Take a look at the below forum post.
EXT vs Plugins
Also in the latest/trunk you will not be able to include portal-impl.jar as a dependency as you did in your current liferay-plugin-package.properties. Ant build script will fail.
Take a look at the below ticket.
Prevent inclusion of portal-impl.jar in plugins
The idea is to make is easy to extend and easy to revert by just undeploying the plugins.
Hope this helps.
-Shagul
Thomas Berg, modifié il y a 14 années.
RE: Custom Post Login Redirect
Regular Member Publications: 131 Date d'inscription: 07/09/09 Publications récentes
Nicolas:
Thanks for your suggestion. I tried including context.xml but got the same result.
Anyway, I managed to get the needed functionality by doing a simple redirect instead of using LastPath. Problem solved :-)
Shagul:
That sounds great, could be the final piece of the plugins puzzle!
I'm itching do implement customizations but have been reluctant to using the extension environment.
So, thanks for helping and for sharing awesome news :-)
Thanks for your suggestion. I tried including context.xml but got the same result.
Anyway, I managed to get the needed functionality by doing a simple redirect instead of using LastPath. Problem solved :-)
Shagul:
That sounds great, could be the final piece of the plugins puzzle!
I'm itching do implement customizations but have been reluctant to using the extension environment.
So, thanks for helping and for sharing awesome news :-)
Tomasz Grysztar, modifié il y a 13 années.
RE: Custom Post Login Redirect
Junior Member Publications: 29 Date d'inscription: 06/05/09 Publications récentes
Even though you already resolved your problem, you may be interested in my solution - I managed to use the LastPath class from the hook plugin this way:
Class classLastPath = PortalClassLoaderUtil.getClassLoader().loadClass("com.liferay.portal.struts.LastPath");
Constructor constructorLastPath = classLastPath.getConstructor(new Class[] {String.class, String.class, Map.class});
session.setAttribute(WebKeys.LAST_PATH, constructorLastPath.newInstance(new Object[] {context, path, params}));