我正在为 nexus 编写一个自定义过滤器来进行身份验证。当我通过编写类似于源代码的过滤器模块添加过滤器时。我得到了一个guice提供异常。我不知道真正的原因是什么。它只是说空指针异常。
Sisu - Problem adding: org.sonatype.guice.bean.locators.LazyBeanEntry@7bb3bc to: org.apache.shiro.web.filter.mgt.DefaultFilterChainManager@5b460d via: org.sonatype.security.web.guice.SecurityWebModule$FilterChainManagerProvider@1d31aaa
com.google.inject.ProvisionException: Guice provision errors:
1) Error in custom provider, java.lang.NullPointerException
at org.sonatype.guice.bean.binders.LocatorWiring
while locating org.sonatype.nexus.security.filter.authc.PasswordDecryptor
for field at org.sonatype.nexus.security.filter.authc.NexusSecureHttpAuthenticationFilter.passwordDecryptor(NexusSecureHttpAuthenticationFilter.java:20)
while locating net.collab.iaf.sso.authentication.rest.CTFAuthenticationFilter
at file:/media/blackhole/temp/nexus/nexus-bundle-template-2.6.1-SNAPSHOT-bundle/nexus-bundle-template-2.6.1-SNAPSHOT/../sonatype-work/nexus/plugin-repository/authentication-0.0.1-SNAPSHOT/authentication-0.0.1-SNAPSHOT.jar!/
at file:/media/blackhole/temp/nexus/nexus-bundle-template-2.6.1-SNAPSHOT-bundle/nexus-bundle-template-2.6.1-SNAPSHOT/../sonatype-work/nexus/plugin-repository/authentication-0.0.1-SNAPSHOT/authentication-0.0.1-SNAPSHOT.jar!/
while locating javax.servlet.Filter annotated with @com.google.inject.name.Named(value=authcBasic)
1 error
at com.google.inject.internal.InjectorImpl$2.get(InjectorImpl.java:1006) [sisu-guice-3.1.4.jar:3.1.4]
我的自定义过滤器模块与我上面在链接中提供的源代码文件相同,只有 authcBasic 和 authcNxBasic 的过滤器。在这里,我有一个名为 CTFAuthenticationFilter 而不是 NexusSecureHttpAuthenticationFilter 的自定义过滤器。请给出一些解决这个问题的方向。我的过滤器模块的片段如下
@Override
protected void configure() {
requireBinding(FilterChainResolver.class);
logger.info("I am inside collabnetsso");
bindAuthcFilter("authcBasic", false, "Sonatype Nexus Repository Manager API");
bindAuthcFilter("authcNxBasic", true, "Sonatype Nexus Repository Manager API (specialized auth)");
}
private void bindAuthcFilter(String name, boolean fakeAuthSchem, String applicationName) {
logger.info("I am inside collabnetsso authc module");
CTFAuthenticationFilter filter = new CTFAuthenticationFilter();
filter.setApplicationName(applicationName);
filter.setFakeAuthScheme(Boolean.toString(fakeAuthSchem));
bindNamedFilter(name, filter);
}
这看起来很奇怪,因为它只是偶尔发生。如果它连续发生两次,在这 2 次中我的身份验证不会发生。但是,如果我重新启动,异常消失,它开始像魅力一样工作,身份验证会根据需要发生。这让人怀疑,nexus 中是否发生了任何竞争情况?或者是谷歌 guice 期望某些东西,而这有时是不可用的。