Authentication Dropwizard身份验证与POST调用失败
我在代码中尝试退出Dropwizard身份验证,但在运行时的POST调用中遇到了一些问题,尽管GET可以正常工作。以下是我在GET调用中使用此选项的方式:Authentication Dropwizard身份验证与POST调用失败,authentication,jersey,dropwizard,Authentication,Jersey,Dropwizard,我在代码中尝试退出Dropwizard身份验证,但在运行时的POST调用中遇到了一些问题,尽管GET可以正常工作。以下是我在GET调用中使用此选项的方式: @Override @GET @Path("/auth") public Response doAuth(@Auth User user) { //do something } 然后在不起作用的Post通话中: @Override @POST @Path("/") public Response createLegalEntity(
@Override
@GET
@Path("/auth")
public Response doAuth(@Auth User user) {
//do something
}
然后在不起作用的Post通话中:
@Override
@POST
@Path("/")
public Response createLegalEntity(@Auth User user, LegalEntity createLegalEntity) {
// do something
}
运行时,它抛出以下错误:
SEVERE: Missing dependency for method public javax.ws.rs.core.Response org.flipkart.api.LegalEntityResource.createLegalEntity(com.yammer.dropwizard.authenticator.User,org.flipkart.model.LegalEntity) at parameter at index 0
我是Dropwizard的新手,无法找出问题的原因
更新
以下是我注册ldap身份验证配置的方式:
final LdapConfiguration ldapConfiguration = configuration.getLdapConfiguration();
Authenticator<BasicCredentials, User> ldapAuthenticator = new CachingAuthenticator<>(
environment.metrics(),
new ResourceAuthenticator(new LdapAuthenticator(ldapConfiguration)),
ldapConfiguration.getCachePolicy());
environment.jersey().register(new AuthDynamicFeature(
new BasicCredentialAuthFilter.Builder<User>()
.setAuthenticator(ldapAuthenticator)
.setRealm("LDAP")
.buildAuthFilter()));
environment.jersey().register(new AuthValueFactoryProvider.Binder<>(User.class));
final LdapConfiguration LdapConfiguration=configuration.getLdapConfiguration();
Authenticator ldapAuthenticator=新的CachingAuthenticator(
environment.metrics(),
新的ResourceAuthenticator(新的LdapAuthenticator(ldapConfiguration)),
ldapConfiguration.getCachePolicy());
environment.jersey().register(新AuthDynamicFeature)(
新建BasicCredentialAuthFilter.Builder()
.setAuthenticator(ldapAuthenticator)
.setRealm(“LDAP”)
.buildAuthFilter());
register(新的AuthValueFactoryProvider.Binder(User.class));
最可能的原因是您没有正确配置身份验证功能。大多数人忘记的一件事是AuthValueFactoryProvider.Binder
。还需要注册此类的实例。如果未注册,这肯定会导致您看到的错误
// If you want to use @Auth to inject a custom Principal type into your resource
environment.jersey().register(new AuthValueFactoryProvider.Binder<>(User.class));
//如果要使用@Auth将自定义主体类型注入到资源中
register(新的AuthValueFactoryProvider.Binder(User.class));
从
另请参见:
- 有关同一问题的Dropwizard问题。您将很好地解释问题的原因