掲示板
Customize the email validation
7年前 に Clint Wilde によって更新されました。
Customize the email validation
Junior Member 投稿: 39 参加年月日: 13/03/05 最新の投稿
Hi,
I need to customize the way Liferay handles email validation for when a new user is created.
I've already added:
to my portal-ext.properties and after restarting Tomcat, I can see the property in the control panel reflected correctly, see attachment below.
However, when I create a new user, the default Validator is still getting invoked.
Is there anything else I need to do to ensure the LiberalEmailAddressValidator is used instead?
Thanks, as always.
Clint
I need to customize the way Liferay handles email validation for when a new user is created.
I've already added:
users.email.address.validator=com.liferay.portal.security.auth.LiberalEmailAddressValidator
to my portal-ext.properties and after restarting Tomcat, I can see the property in the control panel reflected correctly, see attachment below.
However, when I create a new user, the default Validator is still getting invoked.
com.liferay.portal.kernel.exception.UserEmailAddressException$MustValidate: Email name address mytestemail@mailinator.com! must validate with com.liferay.portal.kernel.security.auth.DefaultEmailAddressValidator
at com.liferay.portal.service.impl.UserLocalServiceImpl.validateEmailAddress(UserLocalServiceImpl.java:6641)
at com.liferay.portal.service.impl.UserLocalServiceImpl.validate(UserLocalServiceImpl.java:6545)
at com.liferay.portal.service.impl.UserLocalServiceImpl.addUserWithWorkflow(UserLocalServiceImpl.java:961)
Is there anything else I need to do to ensure the LiberalEmailAddressValidator is used instead?
Thanks, as always.
Clint
添付ファイル:
7年前 に David H Nebinger によって更新されました。
RE: Customize the email validation (回答)
Liferay Legend 投稿: 14919 参加年月日: 06/09/02 最新の投稿
So actually that property is deprecated now. It will not be read from portal-ext.properties any more.
Instead, you create an OSGi component that implements the EmailAddressValidator interface and is implemented as a proper OSGi component service.
Be sure to use a service ranking so your implementation takes precedence over the default.
Note that unlike the old LiberalEmailAddressValidator, the version shipped in LR7 is simply:
So even if it was hitting the class you wanted, it no longer has the effect it used to.
Instead, you create an OSGi component that implements the EmailAddressValidator interface and is implemented as a proper OSGi component service.
Be sure to use a service ranking so your implementation takes precedence over the default.
Note that unlike the old LiberalEmailAddressValidator, the version shipped in LR7 is simply:
public class LiberalEmailAddressValidator extends DefaultEmailAddressValidator {
@Override
public boolean validate(long companyId, String emailAddress) {
return Validator.isNotNull(emailAddress);
}
}
So even if it was hitting the class you wanted, it no longer has the effect it used to.
7年前 に Clint Wilde によって更新されました。
RE: Customize the email validation
Junior Member 投稿: 39 参加年月日: 13/03/05 最新の投稿
Thanks David, this is exactly what I was looking for, and it worked perfectly.
I had to research how to add the service ranking, and this is how I did it, in case others are looking for the same solution. Here is my full EmailValidator:
I had to research how to add the service ranking, and this is how I did it, in case others are looking for the same solution. Here is my full EmailValidator:
@Component(immediate = true, service = EmailAddressValidator.class, property = { "service.ranking:Integer=100" })
public class AgentEmailValidator implements EmailAddressValidator {
private static Logger LOG = LoggerFactory.getLogger(AgentAuthService.class);
@Activate
protected void activate() {
LOG.debug("Activating " + getClass().getSimpleName());
}
@Override
public boolean validate(long companyId, String emailAddress) {
boolean isValid = false;
// other specific business logic here
if (!Validator.isEmailAddress(emailAddress) || emailAddress.startsWith("postmaster@")
|| emailAddress.startsWith("root@")) {
isValid = false;
} else {
isValid = true;
}
return isValid;
}
}