确保您在 build.gradle 中具有对门户内核的依赖项
dependencies {
compile 'com.liferay.portal:com.liferay.portal.kernel:2.0.0'
我使用 Blade-cli 制作了一个 screenNameValidator,您可以在https://github.com/bruinen/liferay-blade-samples/tree/master/liferay-workspace/modules/blade.screenname.validator看到该项目
import com.liferay.portal.kernel.security.auth.ScreenNameValidator;
import org.osgi.service.component.annotations.Component;
import java.util.Locale;
@Component(
immediate = true,
property = {"service.ranking:Integer=100"},
service = ScreenNameValidator.class
)
public class CustomScreenNameValidator implements ScreenNameValidator {
@Override
public String getAUIValidatorJS() {
return "function(val) {return !(val.indexOf(\"admin\") !==-1)}";
}
@Override
public String getDescription(Locale locale) {
return "The screenName contains reserved words";
}
@Override
public boolean validate(long companyId, String screenName) {
return !screenName.contains("admin");
}
}