Foren
Validate password from a custom portlet
Hal Seldon, geändert vor 9 Jahren.
Validate password from a custom portlet
Junior Member Beiträge: 34 Beitrittsdatum: 20.09.13 Neueste Beiträge
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, geändert vor 9 Jahren.
RE: Validate password from a custom portlet (Antwort)
Liferay Legend Beiträge: 2416 Beitrittsdatum: 22.12.10 Neueste Beiträge
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, geändert vor 9 Jahren.
RE: Validate password from a custom portlet
Junior Member Beiträge: 34 Beitrittsdatum: 20.09.13 Neueste Beiträge
Is there any equivalent method that allows me to use Portal password validation? I hate having duplicate code
venka reddy, geändert vor 9 Jahren.
RE: Validate password from a custom portlet
Regular Member Beiträge: 231 Beitrittsdatum: 23.03.11 Neueste Beiträge
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, geändert vor 9 Jahren.
RE: Validate password from a custom portlet
Liferay Master Beiträge: 875 Beitrittsdatum: 07.01.11 Neueste Beiträge
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, geändert vor 9 Jahren.
RE: Validate password from a custom portlet
Junior Member Beiträge: 34 Beitrittsdatum: 20.09.13 Neueste Beiträge
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, geändert vor 9 Jahren.
RE: Validate password from a custom portlet (Antwort)
Liferay Legend Beiträge: 14919 Beitrittsdatum: 02.09.06 Neueste Beiträge
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, geändert vor 9 Jahren.
RE: Validate password from a custom portlet
Junior Member Beiträge: 34 Beitrittsdatum: 20.09.13 Neueste Beiträge
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, geändert vor 9 Jahren.
RE: Validate password from a custom portlet
Liferay Legend Beiträge: 14919 Beitrittsdatum: 02.09.06 Neueste Beiträge
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, geändert vor 9 Jahren.
RE: Validate password from a custom portlet (Antwort)
Junior Member Beiträge: 34 Beitrittsdatum: 20.09.13 Neueste Beiträge
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, geändert vor 9 Jahren.
RE: Validate password from a custom portlet
Liferay Legend Beiträge: 14919 Beitrittsdatum: 02.09.06 Neueste Beiträge
Glad to help!
Arunjyoti Banik, geändert vor 9 Jahren.
RE: Validate password from a custom portlet
Junior Member Beiträge: 74 Beitrittsdatum: 26.08.14 Neueste BeiträgeHal 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, geändert vor 9 Jahren.
RE: Validate password from a custom portlet
Liferay Legend Beiträge: 14919 Beitrittsdatum: 02.09.06 Neueste Beiträge
MethodKey is the container for a method definition that you are planning to invoke.
Arunjyoti Banik, geändert vor 9 Jahren.
RE: Validate password from a custom portlet
Junior Member Beiträge: 74 Beitrittsdatum: 26.08.14 Neueste Beiträge
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, geändert vor 8 Jahren.
RE: Validate password from a custom portlet
Liferay Legend Beiträge: 2416 Beitrittsdatum: 22.12.10 Neueste Beiträge
I think you should have read the entire thread before posting that link. That link doesn't actually solve the original posters issue.