Forums

Home » Liferay Portal » English » 3. Development

Combination View Flat View Tree View
Threads [ Previous | Next ]
toggle
Extending LifeRay Login using Custom Portlet within Plugin-SDK Steve Gao April 22, 2009 4:11 PM
RE: Extending LifeRay Login using Custom Portlet within Plugin-SDK Jim Klo April 22, 2009 5:28 PM
RE: Extending LifeRay Login using Custom Portlet within Plugin-SDK Steve Gao April 23, 2009 11:23 AM
RE: Extending LifeRay Login using Custom Portlet within Plugin-SDK Jim Klo April 29, 2009 3:18 PM
RE: Extending LifeRay Login using Custom Portlet within Plugin-SDK ankit yakkundi February 27, 2011 9:28 PM
RE: Extending LifeRay Login using Custom Portlet within Plugin-SDK stephan t May 4, 2011 2:13 AM
RE: Extending LifeRay Login using Custom Portlet within Plugin-SDK Mathieu Hicauber May 4, 2011 2:25 AM
RE: Extending LifeRay Login using Custom Portlet within Plugin-SDK mark w ambler June 8, 2009 4:08 PM
RE: Extending LifeRay Login using Custom Portlet within Plugin-SDK mark w ambler June 10, 2009 8:19 AM
RE: Extending LifeRay Login using Custom Portlet within Plugin-SDK Jefferson Chaves Gomes February 19, 2010 11:45 AM
RE: Extending LifeRay Login using Custom Portlet within Plugin-SDK Abdelrahman Mohamed El Ghanam November 1, 2010 4:04 AM
RE: Extending LifeRay Login using Custom Portlet within Plugin-SDK Bruno Vidal July 20, 2009 8:01 AM
RE: Extending LifeRay Login using Custom Portlet within Plugin-SDK lv yulin November 1, 2010 7:26 PM
RE: Extending LifeRay Login using Custom Portlet within Plugin-SDK Abdelrahman Mohamed El Ghanam November 2, 2010 3:02 AM
RE: Extending LifeRay Login using Custom Portlet within Plugin-SDK Mathieu Hicauber January 26, 2011 12:04 AM
RE: Extending LifeRay Login using Custom Portlet within Plugin-SDK Mathieu Hicauber January 26, 2011 12:21 AM
RE: Extending LifeRay Login using Custom Portlet within Plugin-SDK alex 2292 February 11, 2011 2:16 AM
RE: Extending LifeRay Login using Custom Portlet within Plugin-SDK Rohit Salecha May 4, 2011 5:34 AM
RE: Extending LifeRay Login using Custom Portlet within Plugin-SDK Srikanth Reddy Sanivarapu January 7, 2012 4:50 AM
RE: Extending LifeRay Login using Custom Portlet within Plugin-SDK vijay k March 9, 2012 8:46 AM
RE: Extending LifeRay Login using Custom Portlet within Plugin-SDK Mohit Krishna January 23, 2013 3:15 AM
Steve Gao
Extending LifeRay Login using Custom Portlet within Plugin-SDK
April 22, 2009 4:11 PM
Answer

Steve Gao

Rank: New Member

Posts: 2

Join Date: April 22, 2009

Recent Posts

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?
Attachment

Attachment

Attachments: LoginCompare1.jpg (22.1k), LoginCompare2.jpg (24.2k)
Jim Klo
RE: Extending LifeRay Login using Custom Portlet within Plugin-SDK
April 22, 2009 5:28 PM
Answer

Jim Klo

Rank: Junior Member

Posts: 75

Join Date: November 7, 2008

Recent Posts

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
RE: Extending LifeRay Login using Custom Portlet within Plugin-SDK
April 23, 2009 11:23 AM
Answer

Steve Gao

Rank: New Member

Posts: 2

Join Date: April 22, 2009

Recent Posts

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):

 1
 2   /* default action handler, Spring knows it is an action handler based on the existence of the ActionRequest parameter */
 3    @RequestMapping
 4    public void action(ActionRequest actionRequest, ActionResponse actionResponse, Map<String,Object> model) throws Exception {
 5        log.info(" ---------------------- Action Request ---------------------- ");
 6
 7               /* This is a hack, in com.liferay.portlet.login.action.ViewAction class, which initiates login process
 8                * a parameter named "cmd" is expected, this value cannot be null, so I put in the value it is looking for */
 9        String cmd = actionRequest.getParameter(Constants.CMD);
10        if (cmd == null)
11            cmd = "update";
12       
13        if (cmd.equals("forgot-password")) {
14            HttpServletRequest request = PortalUtil.getHttpServletRequest(
15                actionRequest);
16
17            try {
18                if (PropsValues.CAPTCHA_CHECK_PORTAL_SEND_PASSWORD) {
19                    CaptchaUtil.check(actionRequest);
20                }
21
22                LoginAction.sendPassword(request);
23
24                SessionMessages.add(request, "request_processed");
25            }
26            catch (Exception e) {
27                if (e instanceof CaptchaTextException ||
28                    e instanceof NoSuchUserException ||
29                    e instanceof SendPasswordException ||
30                    e instanceof UserEmailAddressException) {
31
32                    SessionErrors.add(request, e.getClass().getName());
33                }
34                else {
35                    PortalUtil.sendError(e, actionRequest, actionResponse);
36                }
37            }
38        }
39        else {
40            ThemeDisplay themeDisplay =
41                (ThemeDisplay)actionRequest.getAttribute(WebKeys.THEME_DISPLAY);
42
43            if (actionRequest.getRemoteUser() != null) {
44                actionResponse.sendRedirect(themeDisplay.getPathMain());
45            }
46            else if (Validator.isNotNull(cmd)) {
47                try {
48                    login(themeDisplay, actionRequest, actionResponse);
49                }
50                catch (Exception e) {
51                    if (e instanceof AuthException) {
52                        Throwable cause = e.getCause();
53
54                        if (cause instanceof PasswordExpiredException ||
55                            cause instanceof UserLockoutException) {
56
57                            SessionErrors.add(
58                                actionRequest, cause.getClass().getName());
59                        }
60                        else {
61                            SessionErrors.add(
62                                actionRequest, e.getClass().getName());
63                        }
64                    }
65                    else if (e instanceof CookieNotSupportedException ||
66                             e instanceof NoSuchUserException ||
67                             e instanceof PasswordExpiredException ||
68                             e instanceof UserEmailAddressException ||
69                             e instanceof UserIdException ||
70                             e instanceof UserLockoutException ||
71                             e instanceof UserPasswordException ||
72                             e instanceof UserScreenNameException) {
73
74                        SessionErrors.add(
75                            actionRequest, e.getClass().getName());
76                    }
77                    else {
78                        PortalUtil.sendError(e, actionRequest, actionResponse);
79                    }
80                }
81            }
82        }       
83    }


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:

 1
 2    protected void login(
 3            ThemeDisplay themeDisplay, ActionRequest actionRequest,
 4            ActionResponse actionResponse)
 5        throws Exception {
 6
 7        /* Use com.liferay.portal.util.PortalUtil to get access to
 8         * HttpServletRequest and HttpServletResponse objects */
 9
10        HttpServletRequest request = PortalUtil.getHttpServletRequest(
11            actionRequest);
12        HttpServletResponse response = PortalUtil.getHttpServletResponse(
13            actionResponse);
14
15        String login = ParamUtil.getString(actionRequest, "txtEmail");
16        String password = ParamUtil.getString(actionRequest, "txtPassword");
17        boolean rememberMe = ParamUtil.getBoolean(actionRequest, "rememberMe");
18
19        LoginAction.login(request, response, login, password, rememberMe);
20
21        if (PropsValues.PORTAL_JAAS_ENABLE) {
22            actionResponse.sendRedirect(
23                themeDisplay.getPathMain() + "/portal/protected");
24        }
25        else {
26            String redirect = ParamUtil.getString(actionRequest, "redirect");
27
28            if (Validator.isNotNull(redirect)) {
29                actionResponse.sendRedirect(redirect);
30            }
31            else {
32                actionResponse.sendRedirect(themeDisplay.getPathMain());
33            }
34        }
35        log.info("Login process complete ... ");
36    }


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.
Jim Klo
RE: Extending LifeRay Login using Custom Portlet within Plugin-SDK
April 29, 2009 3:18 PM
Answer

Jim Klo

Rank: Junior Member

Posts: 75

Join Date: November 7, 2008

Recent Posts

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.
mark w ambler
RE: Extending LifeRay Login using Custom Portlet within Plugin-SDK
June 8, 2009 4:08 PM
Answer

mark w ambler

Rank: New Member

Posts: 2

Join Date: June 8, 2009

Recent Posts

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
RE: Extending LifeRay Login using Custom Portlet within Plugin-SDK
June 10, 2009 8:19 AM
Answer

mark w ambler

Rank: New Member

Posts: 2

Join Date: June 8, 2009

Recent Posts

Ok...after some pain I think I have found my problem. All I did was comment out the
1<!--<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.
Bruno Vidal
RE: Extending LifeRay Login using Custom Portlet within Plugin-SDK
July 20, 2009 8:01 AM
Answer

Bruno Vidal

Rank: New Member

Posts: 5

Join Date: July 20, 2009

Recent Posts

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
Jefferson Chaves Gomes
RE: Extending LifeRay Login using Custom Portlet within Plugin-SDK
February 19, 2010 11:45 AM
Answer

Jefferson Chaves Gomes

Rank: New Member

Posts: 23

Join Date: November 16, 2009

Recent Posts

Mark w ambler...

Thanks so much!!!

You resolved my issue too.

emoticon

it's the correct way
1<!--<instanceable>true</instanceable>-->
Abdelrahman Mohamed El Ghanam
RE: Extending LifeRay Login using Custom Portlet within Plugin-SDK
November 1, 2010 4:04 AM
Answer

Abdelrahman Mohamed El Ghanam

Rank: Junior Member

Posts: 41

Join Date: September 30, 2010

Recent Posts

I know its a little bit late, but how did you import the LoginUtil into your portlet ??
lv yulin
RE: Extending LifeRay Login using Custom Portlet within Plugin-SDK
November 1, 2010 7:26 PM
Answer

lv yulin

Rank: New Member

Posts: 3

Join Date: October 10, 2010

Recent Posts

1<portlet>
2        <portlet-name>login_ext</portlet-name>
3        <icon>/images/common/icon.png</icon>
4        <!--<instanceable>true</instanceable>-->
5        <instanceable>false</instanceable>
6        <header-portlet-css>/css/reliefnetwork.css</header-portlet-css>
7        <css-class-wrapper>login-portlet</css-class-wrapper>
8    </portlet>


it does't see the same to me! helphelphelphelphelphelphelphelphelp
Abdelrahman Mohamed El Ghanam
RE: Extending LifeRay Login using Custom Portlet within Plugin-SDK
November 2, 2010 3:02 AM
Answer

Abdelrahman Mohamed El Ghanam

Rank: Junior Member

Posts: 41

Join Date: September 30, 2010

Recent Posts

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.
Mathieu Hicauber
RE: Extending LifeRay Login using Custom Portlet within Plugin-SDK
January 26, 2011 12:04 AM
Answer

Mathieu Hicauber

Rank: Junior Member

Posts: 79

Join Date: December 22, 2010

Recent Posts

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.
Mathieu Hicauber
RE: Extending LifeRay Login using Custom Portlet within Plugin-SDK
January 26, 2011 12:21 AM
Answer

Mathieu Hicauber

Rank: Junior Member

Posts: 79

Join Date: December 22, 2010

Recent Posts

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
RE: Extending LifeRay Login using Custom Portlet within Plugin-SDK
February 11, 2011 2:16 AM
Answer

alex 2292

Rank: New Member

Posts: 14

Join Date: February 7, 2011

Recent Posts

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
ankit yakkundi
RE: Extending LifeRay Login using Custom Portlet within Plugin-SDK
February 27, 2011 9:28 PM
Answer

ankit yakkundi

Rank: Regular Member

Posts: 221

Join Date: March 4, 2010

Recent Posts

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
RE: Extending LifeRay Login using Custom Portlet within Plugin-SDK
May 4, 2011 2:13 AM
Answer

stephan t

Rank: Junior Member

Posts: 48

Join Date: October 19, 2010

Recent Posts

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
Mathieu Hicauber
RE: Extending LifeRay Login using Custom Portlet within Plugin-SDK
May 4, 2011 2:25 AM
Answer

Mathieu Hicauber

Rank: Junior Member

Posts: 79

Join Date: December 22, 2010

Recent Posts

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.
Rohit Salecha
RE: Extending LifeRay Login using Custom Portlet within Plugin-SDK
May 4, 2011 5:34 AM
Answer

Rohit Salecha

Rank: Junior Member

Posts: 50

Join Date: February 20, 2011

Recent Posts

Check this out

http://liferaydemystified.blogspot.com/
Srikanth Reddy Sanivarapu
RE: Extending LifeRay Login using Custom Portlet within Plugin-SDK
January 7, 2012 4:50 AM
Answer

Srikanth Reddy Sanivarapu

Rank: Regular Member

Posts: 193

Join Date: November 14, 2008

Recent Posts

Guys,

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

ANY HELP
vijay k
RE: Extending LifeRay Login using Custom Portlet within Plugin-SDK
March 9, 2012 8:46 AM
Answer

vijay k

Rank: New Member

Posts: 4

Join Date: March 5, 2012

Recent Posts

Follow this link http://www.liferay.com/community/forums/-/message_boards/message/12912154. That solution worked for me.
Mohit Krishna
RE: Extending LifeRay Login using Custom Portlet within Plugin-SDK
January 23, 2013 3:15 AM
Answer

Mohit Krishna

Rank: New Member

Posts: 2

Join Date: December 18, 2012

Recent Posts

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.