掲示板

[EXT - HOOK] Liferay 6 and external web services

12年前 に Antonio Benvenuto によって更新されました。

[EXT - HOOK] Liferay 6 and external web services

New Member 投稿: 12 参加年月日: 11/06/19 最新の投稿
Hi all

I'm using Liferay 6 portal in my project.

My back-end business services are exposed as web services.
Is there a way to integrate liferay authentication system with my custom AUTHENTICATION web-service?

Thank you for suggestiions!
Antonio
thumbnail
12年前 に Jan Gregor によって更新されました。

RE: [EXT - HOOK] Liferay 6 and external web services

Regular Member 投稿: 224 参加年月日: 10/10/20 最新の投稿
Hi Antonio,

I am sure there is a way, but you need to specify your requirements more in details. Do you need to integrate your authentication for user login ? There is a standard interface providing developer to implement custom authentication mechanisms, which will be used for user login process.

Regards,
Jan.
12年前 に Antonio Benvenuto によって更新されました。

RE: [EXT - HOOK] Liferay 6 and external web services

New Member 投稿: 12 参加年月日: 11/06/19 最新の投稿
Hi Jan

I want to integrate liferay login with my custom authentication service exposed as web-service.
So I'm developing an ext-plugin,implementing my own Authenticator:


public class CustomAuthenticator implements Authenticator{

	
	//companyId,emailAddress,password,headerMap,parameterMap
	public int authenticateByEmailAddress(long arg0, String arg1, String arg2,Map<string, string[]> arg3, Map<string, string[]> arg4) throws AuthException {
		System.out.println("############ [Custom Authenticator]  authenticateByEmailAddress");
		return SUCCESS;
	}

	//companyId,screenName,password,headerMap,parameterMap
	public int authenticateByScreenName(long arg0, String arg1, String arg2,Map<string, string[]> arg3, Map<string, string[]> arg4) throws AuthException {
		System.out.println("############ [Custom Authenticator]  authenticateByScreenName");
		return SUCCESS;
	}
	
	//companyId,userId,password,headerMap,parameterMap
	public int authenticateByUserId(long arg0, long arg1, String arg2,Map<string, string[]> arg3, Map<string, string[]> arg4) throws AuthException {
		System.out.println("############ [Custom Authenticator] authenticateByUserId");
		return SUCCESS;
	}
	
}
</string,></string,></string,></string,></string,></string,>


portal-ext.properties


auth.pipeline.enable.liferay.check=false  
auth.pipeline.pre=it.company.application.liferay.custom.auth.CustomAuthenticator


This is what I have done.
Now i Have a problem: trying to login into liferay , I can see the System.out.println("") of my custom Authenticator,in the console (so it is correctly called) ,but login fails, despite all methods of autenhticator return SUCCESS.

Any suggest is appreciated emoticon
thumbnail
12年前 に David H Nebinger によって更新されました。

RE: [EXT - HOOK] Liferay 6 and external web services

Liferay Legend 投稿: 14919 参加年月日: 06/09/02 最新の投稿
Users still need to be in the Liferay database in order to satisfy various database internals.

Is the user that you're trying to authenticate as in the Liferay database?
12年前 に Antonio Benvenuto によって更新されました。

RE: [EXT - HOOK] Liferay 6 and external web services

New Member 投稿: 12 参加年月日: 11/06/19 最新の投稿
User doesn't exist in the liferay login.
Is this mandatory?

"auth.pipeline.enable.liferay.check=false" is not to tell liferay to skip this step (liferay check)?
if not is there a solution/work around to solve the issue?

Thank you!
thumbnail
12年前 に David H Nebinger によって更新されました。

RE: [EXT - HOOK] Liferay 6 and external web services

Liferay Legend 投稿: 14919 参加年月日: 06/09/02 最新の投稿
Yes, it is still mandatory.

The user id, from Liferay's user table, is a key value for portlet preferences, personal page customizations, org/community/group/team membership, any user generated content (forum posts, wiki comments, document/image upload, etc).
12年前 に Antonio Benvenuto によって更新されました。

RE: [EXT - HOOK] Liferay 6 and external web services

New Member 投稿: 12 参加年月日: 11/06/19 最新の投稿
Thank you for your interesting suggest David!

So,I'm trying to programmatically insert user into liferay when my CUSTOM AUTH SERVICE validate user:


public class CustomAuthenticator implements Authenticator{

    .......
   
    //companyId,userId,password,headerMap,parameterMap
   public int authenticateByEmailAddress(long arg0, String arg1, String arg2,Map<string, string[]> arg3, Map<string, string[]> arg4) throws AuthException {
        System.out.println("############ [Custom Authenticator] authenticateByUserId");
		int result;
		
		// Call to CUSTOM AUTH SERVICE 
		boolean IsUserAuthenticated = CustomAuthService.authorize(arg1,arg2);
		
		// If user is correctly authenticated,create a new user into liferay and return SUCCESS
		// TODO: Check if user alredy exists into liferay,then,if not,insert new one
		if(IsUserAuthenticated)
		{
			User user = new User()
			user.setFirstName("Fred");
			user.setLastName("Flinstone");
			user.setEmail(arg1);
			user.setPassword(arg2);
			user.setActive(true);
			UserLocalServiceUtil.addUser(user);
			result = SUCCESS;
		}
		else
		{
			result = FAILURE;
		}
		
        return result;
    }
	.......
}
</string,></string,>


Despite I'm inserting user into liferay db I'm not be able to correctly login!

P.s.:
Looking at the above code you can see user statically inserted (yes...he is always Fred Flinstone...).
If I try to login twice,on the second attempt liferay shows me an exception because foreign key constraints fails inserting same user:
so I think user is correctly inserted into lifearay db;but if i try to go to Control Center to see liferay's users I can't see "Fred Flinstone".

What am I doing wrong?

Thank you!
thumbnail
12年前 に David H Nebinger によって更新されました。

RE: [EXT - HOOK] Liferay 6 and external web services

Liferay Legend 投稿: 14919 参加年月日: 06/09/02 最新の投稿
Okay, you should only be adding a user if they do not exist already.

Second, the screen name for the second "Fred Flinstone" is probably also being set to "fflinstone" (I think that's how the screenname is generated) and the second add is probably failing.

Third, any user added not through the control panel is probably not indexed yet which is why you don't see them. Go to the control panel, to the server area, and reindex all indexes; that should make flinstone show up in the users list.