Ask Questions and Find Answers
Important:
Ask is now read-only. You can review any existing questions and answers, but not add anything new.
But - don't panic! While ask is no more, we've replaced it with discuss - the new Liferay Discussion Forum! Read more here here or just visit the site here:
discuss.liferay.com
RE: Liferay 7.2.1, redirect to update_password after password expiration
Hi all,
I'm using Liferay Community Edition Portal 7.2.1 CE GA2 (with DB migration from 6.2) and I need help in change password expiration behaviour.
I set a new password policy in portal with password expiration and I assign a single user to this policy to test the behaviour.
Liferay warn correctly about password expiration, but redirect on login page with the warning
Error: Your password has expired. Please contact an administrator to reset your password.
I would like to redirect the user to update_password page without admin intervention.
I try to search in blog, but I don't found any help.
Is it possible? How can I do this?
Hi,
You may need to do this by setting user.setPasswordReset() to True, this would force user to change the password.This would require creating a Service Wrapper for UserLocalService and override the doCheckPasswordExpired(..) method accordingly.
You can refer below for creating service wrapper
https://help.liferay.com/hc/en-us/articles/360029144671-Overriding-Liferay-Services-Service-Wrappers-
HI, I tried your suggestion and follow the istructions. The module is deployed (Active in gogo shell), ma method is not overridden.
This is a very simple class to test checkPasswordExpired.
Where I do it wrong?
package mypackage.serviceoverride;
import com.liferay.portal.kernel.service.UserLocalServiceWrapper;
import com.liferay.portal.kernel.service.ServiceWrapper;
import org.osgi.service.component.annotations.Component;
import org.osgi.service.component.annotations.Reference;
import com.liferay.portal.kernel.service.UserLocalService;
import com.liferay.portal.kernel.model.User;
@Component(
immediate = true,
property = {
},
service = ServiceWrapper.class
)
public class UserLocalServiceOverride extends UserLocalServiceWrapper {
public UserLocalServiceOverride() {
super(null);
}
@Override
public void checkPasswordExpired(User user)
throws com.liferay.portal.kernel.exception.PortalException {
System.out.println("TEST");
super.checkPasswordExpired(user);
}
@Reference(unbind = "-")
private void serviceSetter(UserLocalService userLocalService) {
setWrappedService(userLocalService);
}
}
Hi ,
Implementation looks fine, you can try overriding authenticateByScreenName or authenticateByEmailAddress as per your Auth Type.
Hi,
thank you for your answer.
I will have a look and I will update the thread.
Hi,
You can refer below , this may help you.
https://liferay.dev/blogs/-/blogs/redirect-to-password-reset-on-password-expiration
Hi Mohammed Yasin thank you so much for your answer, it's what I was looking for.
I was going to update this thread because I found a different solution, but yours is cleaner.
I write it here, just for information. In the authenticateByScreenName method I catch the Password expired exception and I repeat the authentication.
@Override
public int authenticateByScreenName(
long companyId, java.lang.String screenName,
java.lang.String password,
java.util.Map<java.lang.String, java.lang.String[]> headerMap,
java.util.Map<java.lang.String, java.lang.String[]> parameterMap,
java.util.Map<java.lang.String, java.lang.Object> resultsMap)
throws com.liferay.portal.kernel.exception.PortalException {
int result = -1;
try {
result = super.authenticateByScreenName(
companyId, screenName, password, headerMap, parameterMap,
resultsMap);
} catch (PasswordExpiredException e){
User user = UserLocalServiceUtil.fetchUserByScreenName(companyId, screenName);
user.setPasswordModifiedDate(new Date());
user.setPasswordReset(true);
UserLocalServiceUtil.updateUser(user);
result = super.authenticateByScreenName(
companyId, screenName, password, headerMap, parameterMap,
resultsMap);
}
return result;
}
Powered by Liferay™