Fórum
Validate password from a custom portlet
Hal Seldon, modificado 9 Anos atrás.
Validate password from a custom portlet
Junior Member Postagens: 34 Data de Entrada: 20/09/13 Postagens Recentes
I would like to check a password inside a custom portlet.
I have seen this in UserLocalServiceImpl:
I have tried to use it in a custom portlet... I could instiantate passwordPolicy, but I have not access to use PwdToolkitUtil.... the error is "The import com.liferay.portal.secutiry.pwd.PwdToolkitUtil. cannot be resolved".
Where is the problem? is there an alternative to check passwords with portal policy from a custom portlet?
I have seen this in UserLocalServiceImpl:
PasswordPolicy passwordPolicy = passwordPolicyLocalService.getDefaultPasswordPolicy(companyId);
PwdToolkitUtil.validate(companyId, 0, password1, password2, passwordPolicy);
I have tried to use it in a custom portlet... I could instiantate passwordPolicy, but I have not access to use PwdToolkitUtil.... the error is "The import com.liferay.portal.secutiry.pwd.PwdToolkitUtil. cannot be resolved".
Where is the problem? is there an alternative to check passwords with portal policy from a custom portlet?
Andew Jardine, modificado 9 Anos atrás.
RE: Validate password from a custom portlet (Resposta)
Liferay Legend Postagens: 2416 Data de Entrada: 22/12/10 Postagens Recentes
That package and class "com.liferay.portal.secutiry.pwd.PwdToolkitUtil" is in the portal-impl jar which is not part of your portlets class loader so you can't access it. You have to use classes (for the portal) that can be found in the portal-service.jar which is loaded in from the global libraries.
Short version, you can't use it. You'll have to write your own class. Good news is that PasswordPolicy is in the portal-service.jar, so that one you can use.
Short version, you can't use it. You'll have to write your own class. Good news is that PasswordPolicy is in the portal-service.jar, so that one you can use.
Hal Seldon, modificado 9 Anos atrás.
RE: Validate password from a custom portlet
Junior Member Postagens: 34 Data de Entrada: 20/09/13 Postagens Recentes
Is there any equivalent method that allows me to use Portal password validation? I hate having duplicate code
venka reddy, modificado 9 Anos atrás.
RE: Validate password from a custom portlet
Regular Member Postagens: 231 Data de Entrada: 23/03/11 Postagens Recentes
Hi,
I have used the following method to check the password.
// If users entered password same as the current password.
status = PasswordTrackerLocalServiceUtil.isSameAsCurrentPassword(userId, currentPassword);
I have used the following method to check the password.
// If users entered password same as the current password.
status = PasswordTrackerLocalServiceUtil.isSameAsCurrentPassword(userId, currentPassword);
Jitendra Rajput, modificado 9 Anos atrás.
RE: Validate password from a custom portlet
Liferay Master Postagens: 875 Data de Entrada: 07/01/11 Postagens Recentes
You can also use below methods to authenticate users.
UserLocalServiceUtil.authenticateByEmailAddress()
UserLocalServiceUtil.authenticateByScreenName()
UserLocalServiceUtil.authenticateByUserId()
You can use any of the above method based on your authentication configuration.
Method will return int value ..
* @return the authentication status.
-1 This can be
com.liferay.portal.security.auth.Authenticator#FAILURE
indicating that the user's credentials are invalid,
1 this can be
com.liferay.portal.security.auth.Authenticator#SUCCESS
indicating a successful login,
or 0
com.liferay.portal.security.auth.Authenticator#DNE} indicating
that a user with that login does not exist.
Hal Seldon, modificado 9 Anos atrás.
RE: Validate password from a custom portlet
Junior Member Postagens: 34 Data de Entrada: 20/09/13 Postagens Recentes
Thanks Jitendra and venka... but I do not want a method to check password to login with existing user.
I want a method that checks if a new password is ok and if it will be validated by the liferay password policy.
I need to create a liferay user, but validating password before calling UserLocalServiceUtil.addUser
Thanks
I want a method that checks if a new password is ok and if it will be validated by the liferay password policy.
I need to create a liferay user, but validating password before calling UserLocalServiceUtil.addUser
Thanks
David H Nebinger, modificado 9 Anos atrás.
RE: Validate password from a custom portlet (Resposta)
Liferay Legend Postagens: 14916 Data de Entrada: 02/09/06 Postagens Recentes
These guys didn't mention that you can use reflection to access classes/methods in the portal context. You can get the portal class loader and use reflection to access an instance, invoke the method, and determine the results.
Normally it is not a good idea as these kind of things will just fail when you do an upgrade (since reflection is light coupling, a change in the actual API does not get reflected until the runtime invocation when you get method not found exceptions).
Normally it is not a good idea as these kind of things will just fail when you do an upgrade (since reflection is light coupling, a change in the actual API does not get reflected until the runtime invocation when you get method not found exceptions).
Hal Seldon, modificado 9 Anos atrás.
RE: Validate password from a custom portlet
Junior Member Postagens: 34 Data de Entrada: 20/09/13 Postagens Recentes
Thanks David for the info.
Can you give me an example about Portal Class Loader to achieve invoke "PwdToolkitUtil.validate(companyId, 0, password1, password2, passwordPolicy)" or another similar example?
And... what do you think is the best option?
1.- Portal Class Loader option?
2.- Duplicate PwdToolkitUtil.validate method in my custom portlet?
Regards
Can you give me an example about Portal Class Loader to achieve invoke "PwdToolkitUtil.validate(companyId, 0, password1, password2, passwordPolicy)" or another similar example?
And... what do you think is the best option?
1.- Portal Class Loader option?
2.- Duplicate PwdToolkitUtil.validate method in my custom portlet?
Regards
David H Nebinger, modificado 9 Anos atrás.
RE: Validate password from a custom portlet
Liferay Legend Postagens: 14916 Data de Entrada: 02/09/06 Postagens Recentes
It's just reflection to invoke a static method in a class.
Invoking the portal's instance would be better as it will have the necessary access to determine current settings, data, etc.
Invoking the portal's instance would be better as it will have the necessary access to determine current settings, data, etc.
Hal Seldon, modificado 9 Anos atrás.
RE: Validate password from a custom portlet (Resposta)
Junior Member Postagens: 34 Data de Entrada: 20/09/13 Postagens Recentes
Hi David
I try this
...and works like a charm.... shared code!
Solved my problem
Thanks again
I try this
PasswordPolicy passwordPolicy = PasswordPolicyLocalServiceUtil.getDefaultPasswordPolicy(companyId);
ClassLoader portalClassLoader = PortalClassLoaderUtil.getClassLoader();
Class<!--?--> pwdToolkitUtilClass = portalClassLoader.loadClass("com.liferay.portal.security.pwd.PwdToolkitUtil");
MethodKey methodKey = new MethodKey(pwdToolkitUtilClass,"validate",long.class,long.class,String.class, String.class, PasswordPolicy.class);
PortalClassInvoker.invoke(true, methodKey, companyId, new Long(0), password, password,passwordPolicy);
...and works like a charm.... shared code!
Solved my problem
Thanks again
David H Nebinger, modificado 9 Anos atrás.
RE: Validate password from a custom portlet
Liferay Legend Postagens: 14916 Data de Entrada: 02/09/06 Postagens Recentes
Glad to help!
Arunjyoti Banik, modificado 9 Anos atrás.
RE: Validate password from a custom portlet
Junior Member Postagens: 74 Data de Entrada: 26/08/14 Postagens RecentesHal Seldon:
Hi David
I try thisPasswordPolicy passwordPolicy = PasswordPolicyLocalServiceUtil.getDefaultPasswordPolicy(companyId); ClassLoader portalClassLoader = PortalClassLoaderUtil.getClassLoader(); Class<!--?--> pwdToolkitUtilClass = portalClassLoader.loadClass("com.liferay.portal.security.pwd.PwdToolkitUtil"); MethodKey methodKey = new MethodKey(pwdToolkitUtilClass,"validate",long.class,long.class,String.class, String.class, PasswordPolicy.class); PortalClassInvoker.invoke(true, methodKey, companyId, new Long(0), password, password,passwordPolicy);
...and works like a charm.... shared code!
Solved my problem
Thanks again
Can you please explain the purpose of MethodKey here?
David H Nebinger, modificado 9 Anos atrás.
RE: Validate password from a custom portlet
Liferay Legend Postagens: 14916 Data de Entrada: 02/09/06 Postagens Recentes
MethodKey is the container for a method definition that you are planning to invoke.
Arunjyoti Banik, modificado 9 Anos atrás.
RE: Validate password from a custom portlet
Junior Member Postagens: 74 Data de Entrada: 26/08/14 Postagens Recentes
I guess any method present in that class, no?? I just have to specify the exact method name.
Actually I was implementing this problem with PasswordTrackerLocalServiceutil as specified above, but I liked your version more, so that it wont be a problem during upgradation. But I am facing constructor undefined problem while writing this piece of code in my processAction method. where should I define this constructor?
Actually I was implementing this problem with PasswordTrackerLocalServiceutil as specified above, but I liked your version more, so that it wont be a problem during upgradation. But I am facing constructor undefined problem while writing this piece of code in my processAction method. where should I define this constructor?
Andew Jardine, modificado 8 Anos atrás.
RE: Validate password from a custom portlet
Liferay Legend Postagens: 2416 Data de Entrada: 22/12/10 Postagens Recentes
I think you should have read the entire thread before posting that link. That link doesn't actually solve the original posters issue.