Java 向受保护的dropwizard资源传递参数

Java 向受保护的dropwizard资源传递参数,java,rest,jackson,jersey-2.0,dropwizard,Java,Rest,Jackson,Jersey 2.0,Dropwizard,我有一个资源,它是安全的,如果我删除了身份验证,它似乎可以工作,但是如果没有安全性,那么这有什么意义呢 这是我的密码: @POST @Path("/secured") @Timed @Produces(MediaType.APPLICATION_JSON) @Consumes(MediaType.APPLICATION_JSON) @UnitOfWork @RolesAllowed("mainUser") public Response aliveSecure(@Auth User user,

我有一个资源,它是安全的,如果我删除了身份验证,它似乎可以工作,但是如果没有安全性,那么这有什么意义呢

这是我的密码:

@POST
@Path("/secured")
@Timed
@Produces(MediaType.APPLICATION_JSON)
@Consumes(MediaType.APPLICATION_JSON)
@UnitOfWork
@RolesAllowed("mainUser")
public Response aliveSecure(@Auth User user, CustomRequest test)
{
    CustomResponse resp = new CustomResponse();

    System.out.println(test.getMessage());
    return Response.status(Response.Status.ACCEPTED).entity(resp).build();
}
CustomRequest和CustomResponse类型是非常标准的POJO,它们只包含一个名为“Message”的字符串-它们实际上是相同的,但这只是为了学习DropWizard而尝试完成的一个练习

现在,如果我删除了这里的@Auth内容和@RolesAllowed等-使其成为不安全的,那么该方法将正常执行-但实际上,这是我在尝试启动应用程序时遇到的错误

org.glassfish.jersey.server.model.ModelValidationException: Validation of the application resource model has failed during application initialization.
! [[FATAL] No injection source found for a parameter of type public CustomRequest at index 0.;
条例草案清楚订明—

如果要使用
@Auth
将自定义主体类型注入到 资源

因此,您应确保将以下内容添加到扩展
io.dropwizard.Application

@Override
public void run(SomeConfigThatExtendsConfiguration config, Environment environment) throws Exception {
    ....
    environment.jersey().register(new AuthValueFactoryProvider.Binder<>(User.class));
}
@覆盖
public void运行(SomeConfigThatExtendsConfiguration配置,环境)引发异常{
....
register(新的AuthValueFactoryProvider.Binder(User.class));
}

@Mickeythreeds很高兴知道。:)