Fórum

Extending LifeRay Login using Custom Portlet within Plugin-SDK

Steve Gao, modificado 15 Anos atrás.

Extending LifeRay Login using Custom Portlet within Plugin-SDK

New Member Postagens: 2 Data de Entrada: 22/04/09 Postagens Recentes
Hey everybody,

I have a technical question regarding creating a custom login portlet within the plugin-sdk environment.

I know this topic has been discussed to death and I have looked through a lot of the existing threads already.

Here is why our scenario is different:
We are working on a project where all of our portlets are created within the plugin-sdk environment. We have a rigid environment for each of our portlets, e.g. we use Spring MVC Portlets, Velocity, iBATIS, etc. So our portlets are using a different system from LifeRay's JSP/Struts/...

Our Portlet Environment:
* LifeRay 5.1.4
* Spring MVC Portlet (note this is different from Spring MVC)
* Velocity
* ...

Our Objective:
Create a login portlet that replicates LifeRay's standard login process but then does additional steps (e.g. inserts session data and initiates calls to web services from third-party systems).

Alternatives I have looked into:
1. Plugin Hooks:
http://www.liferay.com/web/guest/community/wiki/-/wiki/Main/Portal+Hook+Plugins
2. Using EXT environment:
http://www.liferay.com/web/guest/community/wiki/-/wiki/Main/Customizing+the+portal+login+page
http://www.liferay.com/web/guest/community/wiki/-/wiki/Main/Customizing+the+default+page+after+login
http://www.liferay.com/web/guest/community/wiki/-/wiki/Main/Customizing%20the%20portal%20login%20page#section-Customizing+the+portal+login+page-Advanced

Both of the above solutions revolve around "hooking" into the existing login process using the properties shown below, which are defined in portel.properties (you override them in portal-ext.properties or using the hooks mechanism):
#
# Login event
#
login.events.pre=com.liferay.portal.events.LoginPreAction
login.events.post=com.liferay.portal.events.LoginPostAction,com.liferay.portal.events.DefaultLandingPageAction

This would be fine for us except for these reasons:
1. We need to change the look and feel of the login page, but we use a system that is different from LifeRay's default JSP/Struts. We use Velocity with Spring MVC Portlet plus additional frameworks.
2. We need localization which we are implementing using our chosen frameworks.

Essentially we would like to have our login process sitting in our own portlet where we have more control over it.

Attempted Solution:
I decided to use a solution of calling LifeRay's login portlet from within our own portlet. For LifeRay 5.1.4 that means leveraging com.liferay.portal.action.LoginAction. This was discussed in Ray Augé's blog article "Creating custom login front end":
http://www.liferay.com/web/rauge/blog/-/blogs/creating-custom-login-front-end?_33_redirect=%2Fweb%2Fguest%2Fcommunity%2Fblogs%3Fp_p_id%3D77%26p_p_lifecycle%3D1%26p_p_state%3Dnormal

Issue:
I have managed to successfully integrate and call com.liferay.portal.action.LoginAction and other auxiliary LifeRay portal classes from within our portlet (sitting in the plugin-sdk environment). I can successfully build and deploy my custom login portlet.

However, when I go through the login process, upon completion LifeRay does not seem to realize the user is logged in. Doing some debugging I know that the standard LifeRay cookies are being set and the session contains the user data. But LifeRay does not recognize that the user is logged in (e.g. the top navigation does not update to say "Welcome <user>!" or have the signed in options).

I added some screenshots of what I run my local LifeRay server with both login portlets running (our custom Login portlet vs. LifeRay's login portlet). In LoginCompare1.jpg you can see our custom login at the top and LifeRay's login at the bottom. In the screenshot I have just logged in using our custom portlet and you can see that LifeRay does not recognize that the user is logged in.

In LoginCompare2.jpg, I have just logged in successfully using LifeRay's login portlet. LifeRay recognizes that the user is logged in and renders the view accordingly.

I feel like I am getting really close to getting this working, but I am missing some additional method calls, etc. to hook into LifeRay.

Does anyone know what I might be missing?
thumbnail
Jim Klo, modificado 15 Anos atrás.

RE: Extending LifeRay Login using Custom Portlet within Plugin-SDK

Junior Member Postagens: 75 Data de Entrada: 07/11/08 Postagens Recentes
I'm actually doing something akin to this under 5.1.1 (patched to support hooks), however I'm doing my work in the ext environment, but that shouldn't matter.

I'm not really sure I completely follow what your problem is. Are you able to login with your portlet but the view state isn't recognizing the logged in state? Or is it that if you login with the standard login portlet - your portlet doesn't recognize the view state?

My first solution would be to check that you're checking the ThemeDisplay object in your front end to check to see if the user is logged in before rendering the form - but that's the obvious problem.

Can you post your login code. Also are you using any SSO architecture like CAS or OpenSSO? As I've recently discovered myself they work a bit differently.
Steve Gao, modificado 15 Anos atrás.

RE: Extending LifeRay Login using Custom Portlet within Plugin-SDK

New Member Postagens: 2 Data de Entrada: 22/04/09 Postagens Recentes
Hey Jim,

Apologies for my previous long meandering post ... it definitely lost focus near the end. To answer your questions, this post might be a bit lengthy as well. Please bear with me. :-)

Regarding your questions:
> Are you able to login with your portlet but the view state isn't recognizing the logged in state?
Yes, this is the problem. LifeRay is not recognizing change in state. My expectation is that when I sign in using my custom portlet, since it calls LifeRay's LoginAction directly, upon success authentication LifeRay should now recognize that the user is logged in. For example, the top naviation bar should update to provide options for someone who is signed in.

> Or is it that if you login with the standard login portlet - your portlet doesn't recognize the view state?
No, this part is fine. I haven't completed the front-end page for my custom portlet to recognize a change in state yet, so in my screenshot it looks like my portlet didn't recognize the user being logged in. Sorry for the confusion on that part.

> Also are you using any SSO architecture like CAS or OpenSSO?
No, at this point we are not doing anything except the simple default login. We have it configured to use LDAP authentication (i.e. com.liferay.portal.security.auth.LDAPAuth).

> Can you post your login code.
Here is my code, I'll try to make this as concise as possible. Note that I am using JDK 1.5 + Spring MVC Portlet, so I am using annotations within my controller class.

Within my AccountLoginController I have:

1. My action handler method (to handle an ActionRequest to login):


   /* default action handler, Spring knows it is an action handler based on the existence of the ActionRequest parameter */
	@RequestMapping 
	public void action(ActionRequest actionRequest, ActionResponse actionResponse, Map<string,object> model) throws Exception {
		log.info(" ---------------------- Action Request ---------------------- ");

               /* This is a hack, in com.liferay.portlet.login.action.ViewAction class, which initiates login process 
                * a parameter named "cmd" is expected, this value cannot be null, so I put in the value it is looking for */
		String cmd = actionRequest.getParameter(Constants.CMD);
		if (cmd == null)
			cmd = "update";
		
		if (cmd.equals("forgot-password")) {
			HttpServletRequest request = PortalUtil.getHttpServletRequest(
				actionRequest);

			try {
				if (PropsValues.CAPTCHA_CHECK_PORTAL_SEND_PASSWORD) {
					CaptchaUtil.check(actionRequest);
				}

				LoginAction.sendPassword(request);

				SessionMessages.add(request, "request_processed");
			}
			catch (Exception e) {
				if (e instanceof CaptchaTextException ||
					e instanceof NoSuchUserException ||
					e instanceof SendPasswordException ||
					e instanceof UserEmailAddressException) {

					SessionErrors.add(request, e.getClass().getName());
				}
				else {
					PortalUtil.sendError(e, actionRequest, actionResponse);
				}
			}
		}
		else {
			ThemeDisplay themeDisplay =
				(ThemeDisplay)actionRequest.getAttribute(WebKeys.THEME_DISPLAY);

			if (actionRequest.getRemoteUser() != null) {
				actionResponse.sendRedirect(themeDisplay.getPathMain());
			}
			else if (Validator.isNotNull(cmd)) {
				try {
					login(themeDisplay, actionRequest, actionResponse);
				}
				catch (Exception e) {
					if (e instanceof AuthException) {
						Throwable cause = e.getCause();

						if (cause instanceof PasswordExpiredException ||
							cause instanceof UserLockoutException) {

							SessionErrors.add(
								actionRequest, cause.getClass().getName());
						}
						else {
							SessionErrors.add(
								actionRequest, e.getClass().getName());
						}
					}
					else if (e instanceof CookieNotSupportedException ||
							 e instanceof NoSuchUserException ||
							 e instanceof PasswordExpiredException ||
							 e instanceof UserEmailAddressException ||
							 e instanceof UserIdException ||
							 e instanceof UserLockoutException ||
							 e instanceof UserPasswordException ||
							 e instanceof UserScreenNameException) {

						SessionErrors.add(
							actionRequest, e.getClass().getName());
					}
					else {
						PortalUtil.sendError(e, actionRequest, actionResponse);
					}
				}
			}
		}		
	}
</string,object>


The above method is almost a literal copy of processAction() method within com.liferay.portlet.login.action.ViewAction. At this point my goal is to replicate LifeRay's existing login process without adding any new logic.

2. Here is the method that the action handler calls:


	protected void login(
			ThemeDisplay themeDisplay, ActionRequest actionRequest,
			ActionResponse actionResponse)
		throws Exception {

		/* Use com.liferay.portal.util.PortalUtil to get access to 
		 * HttpServletRequest and HttpServletResponse objects */

		HttpServletRequest request = PortalUtil.getHttpServletRequest(
			actionRequest);
		HttpServletResponse response = PortalUtil.getHttpServletResponse(
			actionResponse);

		String login = ParamUtil.getString(actionRequest, "txtEmail");
		String password = ParamUtil.getString(actionRequest, "txtPassword");
		boolean rememberMe = ParamUtil.getBoolean(actionRequest, "rememberMe");

		LoginAction.login(request, response, login, password, rememberMe);

		if (PropsValues.PORTAL_JAAS_ENABLE) {
			actionResponse.sendRedirect(
				themeDisplay.getPathMain() + "/portal/protected");
		}
		else {
			String redirect = ParamUtil.getString(actionRequest, "redirect");

			if (Validator.isNotNull(redirect)) {
				actionResponse.sendRedirect(redirect);
			}
			else {
				actionResponse.sendRedirect(themeDisplay.getPathMain());
			}
		}
		log.info("Login process complete ... ");
	}


This method is almost a literal copy of the login() method from com.liferay.portlet.login.action.ViewAction. You can see that I hook into LoginAction by calling LoginAction.login().

Is there another piece of logic that I am missing perhaps? Some configuration problems?

It might also be a problem that our custom portlets do not use Struts for Portlet implementation. So even though I am leveraging LoginAction, it behaves in a Struts oriented way. Although just looking at the logic flow within both com.liferay.portlet.login.action.ViewAction and LoginAction, it would seem like my version should be okay.
thumbnail
Jim Klo, modificado 14 Anos atrás.

RE: Extending LifeRay Login using Custom Portlet within Plugin-SDK

Junior Member Postagens: 75 Data de Entrada: 07/11/08 Postagens Recentes
Sorry, I've been offline a bit...

Everything looks okay from what I can tell - to be honest, I'm not very well versed in Spring Framework... so I'm not the expert there.

I know that with struts, depending upon whether you extend a PortletAction vs a Struts Action you need to make sure your custom login class path is set in portal.properties, auth.public.paths if extending a struts Action, otherwise you run into permission denied when trying to post.
thumbnail
ankit yakkundi, modificado 13 Anos atrás.

RE: Extending LifeRay Login using Custom Portlet within Plugin-SDK

Regular Member Postagens: 221 Data de Entrada: 05/03/10 Postagens Recentes
hi..
i read the above steps.
i have created a struts application into a portlet.
this portlet checks the user in the ldap server and redirects the page accordingly.
whatever occurs happens in the portlet itself.
i want to make this portlet as a sign portlet ie when user clicks on the sign in link my portlet should be shown.
i have done that by creating a portal-ext.properties file in the classes folder of root.
now what i want is that when the user is authenticated and authorized it has to work as login portlet ie behaviour should be portal and not for a that portlet only..

please help...

any idea or suggestions are welcome..
thanks in advance...
stephan t, modificado 12 Anos atrás.

RE: Extending LifeRay Login using Custom Portlet within Plugin-SDK

Junior Member Postagens: 48 Data de Entrada: 19/10/10 Postagens Recentes
Hi folks,

I'm struggling with about the same problem.
I'm using Liferay 6. I created an ext plug-in to implement a service delegate to directly use Liferay's LoginUtil using the same Spring mechanism Liferay uses for its services. And I created a separate portlet plug-in using this service.
All is functioning well: request comes into portlet, I end up in the LoginUtil.login method and the stuff get's executed, at least in the debugger without any errors or exceptions.
However, what it NOT does is registering the cookies in the browser and I don't know why. Result: I'm not signed in after I execute LoginUtil.login when it gets called from my portlet. Setting the instanceble flag as mentioned above doesn't work.

Can anybody help here, please?

@Bla Bla let me know if you need more information about the service delegate to use LoginUtil from wihtin your portlet

Cheers
stephan
thumbnail
Bla Bla, modificado 12 Anos atrás.

RE: Extending LifeRay Login using Custom Portlet within Plugin-SDK

Junior Member Postagens: 79 Data de Entrada: 22/12/10 Postagens Recentes
stephan t:

@Bla Bla let me know if you need more information about the service delegate to use LoginUtil from wihtin your portlet


hi Stephan

Thank you for your offer but I finally gave up and ended coding my own class implementing com.liferay.portal.security.auth.Authenticator in a hook plugin. This method is working perfectly.

Sorry I can't help for your problem.

Mathieu.
mark w ambler, modificado 14 Anos atrás.

RE: Extending LifeRay Login using Custom Portlet within Plugin-SDK

New Member Postagens: 2 Data de Entrada: 08/06/09 Postagens Recentes
Did you ever resolve this issue. I've been having trouble trying to create a custom login portlet that updates the view state also. The account logs in without issue based on the log entries created, but no update to the view state.
mark w ambler, modificado 14 Anos atrás.

RE: Extending LifeRay Login using Custom Portlet within Plugin-SDK

New Member Postagens: 2 Data de Entrada: 08/06/09 Postagens Recentes
Ok...after some pain I think I have found my problem. All I did was comment out the
<!--<instanceable>true</instanceable>-->
in liferay-portlet.xml. Seems NetBeans portal pack sets that value to true as default when creating the project (probably the right default for most portlets). Its always the small stuff that gets me. I hope this helps someone else that might be having this issue with custom login portlets.
thumbnail
Jefferson Chaves Gomes, modificado 14 Anos atrás.

RE: Extending LifeRay Login using Custom Portlet within Plugin-SDK

New Member Postagens: 23 Data de Entrada: 16/11/09 Postagens Recentes
Mark w ambler...

Thanks so much!!!

You resolved my issue too.

emoticon

it's the correct way
<!--<instanceable>true</instanceable>-->
thumbnail
Abdelrahman Mohamed El Ghanam, modificado 13 Anos atrás.

RE: Extending LifeRay Login using Custom Portlet within Plugin-SDK

Junior Member Postagens: 41 Data de Entrada: 30/09/10 Postagens Recentes
I know its a little bit late, but how did you import the LoginUtil into your portlet ??
Bruno Vidal, modificado 14 Anos atrás.

RE: Extending LifeRay Login using Custom Portlet within Plugin-SDK

New Member Postagens: 5 Data de Entrada: 20/07/09 Postagens Recentes
Steve, did you get to solve this issue? I was trying to do the same thing you described and got exactly the same problem. Could you give me some help?

Thanks
lv yulin, modificado 13 Anos atrás.

RE: Extending LifeRay Login using Custom Portlet within Plugin-SDK

New Member Postagens: 3 Data de Entrada: 11/10/10 Postagens Recentes
<portlet>
		<portlet-name>login_ext</portlet-name>
		<icon>/images/common/icon.png</icon>
		<!--<instanceable>true</instanceable>-->
		<instanceable>false</instanceable>
		<header-portlet-css>/css/reliefnetwork.css</header-portlet-css>
		<css-class-wrapper>login-portlet</css-class-wrapper>
	</portlet>


it does't see the same to me! helphelphelphelphelphelphelphelphelp
thumbnail
Abdelrahman Mohamed El Ghanam, modificado 13 Anos atrás.

RE: Extending LifeRay Login using Custom Portlet within Plugin-SDK

Junior Member Postagens: 41 Data de Entrada: 30/09/10 Postagens Recentes
Are you using liferay 6.0, because till now i didn't find any way to use the login mechanism of liferay in any portlet. And most of the people who replied to me directed me to the EXT way :S which i tried to avoid alot.


I don't think here they are talking about liferay 6.0.
thumbnail
Bla Bla, modificado 13 Anos atrás.

RE: Extending LifeRay Login using Custom Portlet within Plugin-SDK

Junior Member Postagens: 79 Data de Entrada: 22/12/10 Postagens Recentes
Hi - thanks for your post..as I have to handle the same stuff (custom login portlet + Spring MVC and so).

But - there is a but - I followed Ray's post, but i still can't get access to the LoginUtil class from within my custom LoginPortlet sitting in the SDK environment. Can you tell me how you did achieve this ? cos in his post, Ray states that the portlet must be in the ext environment...

It'd be greatly appreciated if you could clarify this point.

Thank you,

Mathieu.
thumbnail
Bla Bla, modificado 13 Anos atrás.

RE: Extending LifeRay Login using Custom Portlet within Plugin-SDK

Junior Member Postagens: 79 Data de Entrada: 22/12/10 Postagens Recentes
Bla Bla:
Hi - thanks for your post..as I have to handle the same stuff (custom login portlet + Spring MVC and so).

But - there is a but - I followed Ray's post, but i still can't get access to the LoginUtil class from within my custom LoginPortlet sitting in the SDK environment. Can you tell me how you did achieve this ? cos in his post, Ray states that the portlet must be in the ext environment...

It'd be greatly appreciated if you could clarify this point.

Thank you,

Mathieu.


==> no need to say - it's urgent :-)
alex 2292, modificado 13 Anos atrás.

RE: Extending LifeRay Login using Custom Portlet within Plugin-SDK

New Member Postagens: 14 Data de Entrada: 07/02/11 Postagens Recentes
Hi,
I ahve implemented my submit custom spring mvc portlet for custom login like example,
i have inserted the login code in the action method,nut when invoke

actionResponse.sendRedirect(themeDisplay.getPathMain());

I receive the exception error:

10:09:47,716 ERROR [DispatcherPortlet:559] Could not complete request
java.lang.IllegalStateException: Set render parameter has already been called
at com.liferay.portlet.ActionResponseImpl.sendRedirect(ActionResponseImpl.java:47)
...

any ideas?
thank you very much
thumbnail
Rohit Salecha, modificado 12 Anos atrás.

RE: Extending LifeRay Login using Custom Portlet within Plugin-SDK

Junior Member Postagens: 50 Data de Entrada: 21/02/11 Postagens Recentes
Check this out

http://liferaydemystified.blogspot.com/
thumbnail
Srikanth Reddy Sanivarapu, modificado 12 Anos atrás.

RE: Extending LifeRay Login using Custom Portlet within Plugin-SDK

Regular Member Postagens: 203 Data de Entrada: 15/11/08 Postagens Recentes
Guys,

Did any have solution for this problem. Please let me know....this is very urgent for me.........................

ANY HELP
vijay k, modificado 12 Anos atrás.

RE: Extending LifeRay Login using Custom Portlet within Plugin-SDK

New Member Postagens: 4 Data de Entrada: 06/03/12 Postagens Recentes
Follow this link http://www.liferay.com/community/forums/-/message_boards/message/12912154. That solution worked for me.
Mohit Krishna, modificado 11 Anos atrás.

RE: Extending LifeRay Login using Custom Portlet within Plugin-SDK

New Member Postagens: 2 Data de Entrada: 18/12/12 Postagens Recentes
I donno of this wud help....
But works fine

Hi,

It works fine for me.

I mentioned following in portal-ext.properties, note have added ParameterAutoLogin at the end


1auto.login.hooks=com.liferay.portal.security.auth.CASAutoLogin,com.liferay.portal.security.auth.NtlmAutoLogin,com.liferay.portal.security.auth.OpenIdAutoLogin,com.liferay.portal.security.auth.OpenSSOAutoLogin,com.liferay.portal.security.auth.RememberMeAutoLogin,com.liferay.portal.security.auth.SiteMinderAutoLogin,com.liferay.portal.security.auth.ParameterAutoLogin

Restarted the server and hit the following url

http://localhost:8080/web/guest?parameterAutoLoginLogin=test@liferay.com&parameterAutoLoginPassword=test

And i was logged in automatically.