Forums de discussion
Validate password from a custom portlet
Hal Seldon, modifié il y a 9 années.
Validate password from a custom portlet
Junior Member Publications: 34 Date d'inscription: 20/09/13 Publications récentes
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, modifié il y a 9 années.
RE: Validate password from a custom portlet (Réponse)
Liferay Legend Publications: 2416 Date d'inscription: 22/12/10 Publications récentes
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, modifié il y a 9 années.
RE: Validate password from a custom portlet
Junior Member Publications: 34 Date d'inscription: 20/09/13 Publications récentes
Is there any equivalent method that allows me to use Portal password validation? I hate having duplicate code
venka reddy, modifié il y a 9 années.
RE: Validate password from a custom portlet
Regular Member Publications: 231 Date d'inscription: 23/03/11 Publications récentes
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, modifié il y a 9 années.
RE: Validate password from a custom portlet
Liferay Master Publications: 875 Date d'inscription: 07/01/11 Publications récentes
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, modifié il y a 9 années.
RE: Validate password from a custom portlet
Junior Member Publications: 34 Date d'inscription: 20/09/13 Publications récentes
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, modifié il y a 9 années.
RE: Validate password from a custom portlet (Réponse)
Liferay Legend Publications: 14914 Date d'inscription: 02/09/06 Publications récentes
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, modifié il y a 9 années.
RE: Validate password from a custom portlet
Junior Member Publications: 34 Date d'inscription: 20/09/13 Publications récentes
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, modifié il y a 9 années.
RE: Validate password from a custom portlet
Liferay Legend Publications: 14914 Date d'inscription: 02/09/06 Publications récentes
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, modifié il y a 9 années.
RE: Validate password from a custom portlet (Réponse)
Junior Member Publications: 34 Date d'inscription: 20/09/13 Publications récentes
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, modifié il y a 9 années.
RE: Validate password from a custom portlet
Liferay Legend Publications: 14914 Date d'inscription: 02/09/06 Publications récentes
Glad to help!
Arunjyoti Banik, modifié il y a 9 années.
RE: Validate password from a custom portlet
Junior Member Publications: 74 Date d'inscription: 26/08/14 Publications récentesHal 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, modifié il y a 9 années.
RE: Validate password from a custom portlet
Liferay Legend Publications: 14914 Date d'inscription: 02/09/06 Publications récentes
MethodKey is the container for a method definition that you are planning to invoke.
Arunjyoti Banik, modifié il y a 9 années.
RE: Validate password from a custom portlet
Junior Member Publications: 74 Date d'inscription: 26/08/14 Publications récentes
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, modifié il y a 8 années.
RE: Validate password from a custom portlet
Liferay Legend Publications: 2416 Date d'inscription: 22/12/10 Publications récentes
I think you should have read the entire thread before posting that link. That link doesn't actually solve the original posters issue.