1

我正在尝试覆盖一个DefaultScreenNameValidator实现ScreenNameValidator接口的类。为此,我复制了该类并将其放入另一个模块中。我所做的一项更改是在注释中,如下所示:-

@Component(
        property = {
                "service.ranking:Integer=500"
                }

    )

我使用它成功构建。但是当我尝试部署项目时,我得到了错误java.lang.NoClassDefFoundError: com/liferay/portal/kernel/security/auth/ScreenNameValidator。你能建议我如何消除这个错误吗?提前谢谢..

4

2 回答 2

2

ScreenNameValidator我想知道,创建一个也实现接口的模块并在其中定义您的自定义逻辑不是更好吗?然后你可以简单地告诉 Liferay 使用该验证器而不是DefaultScreenNameValidator.

例如,一个简约的实现:

import com.liferay.portal.kernel.security.auth.ScreenNameValidator;

import org.osgi.service.component.annotations.Component;

@Component(
    immediate = true,
    service = ScreenNameValidator.class
)
public class CustomScreenNameValidator implements ScreenNameValidator {

    @Override
    public boolean validate(long companyId, String screenName) {
        // Your custom logic
    }
}
于 2016-11-10T15:56:46.707 回答
0

确保您在 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");
    }
}
于 2016-11-16T18:34:31.000 回答