Forums

Home » Liferay Portal » English » 3. Development

Combination View Flat View Tree View
Threads [ Previous | Next ]
toggle
Marco Bencivenni
Custom portlet for user registration
June 22, 2012 4:47 AM
Answer

Marco Bencivenni

Rank: New Member

Posts: 4

Join Date: March 16, 2011

Recent Posts

Dear all,

I've developed my custom registration portlet and it is composed by 2 steps.

The user click on "sign in" link and he will be redirected to a CAS server login page. If the user isn't yet registred in the portal, then the registration phase starts using my registration portlet.

step1 - The portlet gets the user information from CAS, when the user clicks to "next step" button the portlet launches the UserLocalServiceUtil.addUser(...) method and correctly inserts the user in liferay and returns the next step of the registration.

step2 - The user insert other personal information, but at this step the user should be already logged in. Using liferay 6.0.5 the user is correctly logged in, but not using the same portlet in liferay 6.1.0.

In order to have the user logged in into liferay 6.1.0 I try to use UserLocalServiceUtil.authenticateByEmailAddress(...) and LoginUtil.login(...) methods, into the log of portlet the user is correctly authenticated, but not in the portal web page.

Can anyone help me?
Thanks in advance,
Marco B
Hitoshi Ozawa
RE: Custom portlet for user registration
June 23, 2012 11:51 PM
Answer

Hitoshi Ozawa

Rank: Liferay Legend

Posts: 7949

Join Date: March 23, 2010

Recent Posts

In order to have the user logged in into liferay 6.1.0 I try to use UserLocalServiceUtil.authenticateByEmailAddress(...) and LoginUtil.login(...) methods, into the log of portlet the user is correctly authenticated, but not in the portal web page.


What do you it's correctly authenticated in the log but not in the web page? Do you mean there's a message in the log file saying that it's being authenticated correctly but the user is not able to log in?
Marco Bencivenni
RE: Custom portlet for user registration
June 25, 2012 1:46 AM
Answer

Marco Bencivenni

Rank: New Member

Posts: 4

Join Date: March 16, 2011

Recent Posts

Dear Hitoshi,

the problem is that I'd like to have the user already logged when his registration is finished in automatically way, instead of asking the user to insert his credential.
The logs say that the user is logged, but in the web page is not so:
These are the functions that I use to obtain some logs:

Map<String, String[]> parameterMap = request.getParameterMap();
Map<String, Object> resultsMap = new HashMap<String, Object>();
int result = UserLocalServiceUtil.authenticateByEmailAddress(companyId, u.getEmailAddress(), PASSWORD, headerMap, parameterMap, resultsMap);
switch(result){
case Authenticator.SUCCESS: log.debug("User authenticated "); break;
          case Authenticator.DNE: log.debug("User not found "); break;
          default: log.debug("User not authenticated ");
}


And these are the logs produced:

17:58:35,854 DEBUG [Registration - AddUserInfoController] User authenticated

Thanks,
Marco B
Luis Manuel Cruza Roldán
RE: Custom portlet for user registration
October 30, 2012 4:07 PM
Answer

Luis Manuel Cruza Roldán

Rank: New Member

Posts: 2

Join Date: April 25, 2011

Recent Posts

Dear Marco

I hope this reply is in time.

I have worked on a project that integrates Liferay, CAS, custom user login/register portlet and so on but it was for Liferay 5.2.3. Anyway I think this could help you. Liferay login proccess is based on a cookie that your browser stores. CAS authentication is based in a cookie too, the TGT cookie. You must synchronize the existence of this two cookies, Liferay cookie and CAS cookie. The first one says that you have an open session in Liferay and you are user "Your user in Liferay", the second one says that you have been authenticated successfully with username "your username" but no more.

I think you should folloe these steps:

1. Show registration form, so you could get basic user information and you could add this user in Liferay and the system you are using as CAS authentication backend.
2. Use this basic data to authenticate against CAS from your portlet, you could use an http client. What you have to get in this step is CAS TGT cookie in your browser so you are logged in your CAS system. If registration form is part of your CAS Server webapp I think you could get CAS TGT from this application so you could skip this step.
3. Use this basic data to authenticate against Liferay and reproduce the cookie that Liferay generates. If you get this done then you are completelly authenticated (in CAS) and identify (in Liferay), I mean, you are logged in and you are user X in Liferay.
4. Complete user registration by second form where user can complete his details.

In summary, you have to check if you have both cookies in your browser. If don't, you are not authenticated completelly.

By the way, UserLocalServiceUtil.authenticateByEmailAddress(...) can be used to check user credentials but this method does not generate any cookie, you have to do it by hand.

Good luck.


Marco Bencivenni:
Dear Hitoshi,

the problem is that I'd like to have the user already logged when his registration is finished in automatically way, instead of asking the user to insert his credential.
The logs say that the user is logged, but in the web page is not so:
These are the functions that I use to obtain some logs:

Map<String, String[]> parameterMap = request.getParameterMap();
Map<String, Object> resultsMap = new HashMap<String, Object>();
int result = UserLocalServiceUtil.authenticateByEmailAddress(companyId, u.getEmailAddress(), PASSWORD, headerMap, parameterMap, resultsMap);
switch(result){
case Authenticator.SUCCESS: log.debug("User authenticated "); break;
          case Authenticator.DNE: log.debug("User not found "); break;
          default: log.debug("User not authenticated ");
}


And these are the logs produced:

17:58:35,854 DEBUG [Registration - AddUserInfoController] User authenticated

Thanks,
Marco B