2017-09-26 44 views
2

我有一个资源,这是一个安全的,如果我删除身份验证,它似乎工作,但没有安全,那么有什么意义?将参数传递给一个安全的dropwizard资源

这里是我的代码:

@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,他们刚刚举行了一个名为“消息”的字符串 - 他们实际上是相同的,但是这仅仅是一个锻炼,我想为了学习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.; 

回答

0

auth manual读取明确 -

如果你想使用@Auth注入的自定义主要类型到您的 资源。

因此,你必须确保添加以下到您Service扩展io.dropwizard.Application

@Override 
public void run(SomeConfigThatExtendsConfiguration config, Environment environment) throws Exception { 
    .... 
    environment.jersey().register(new AuthValueFactoryProvider.Binder<>(User.class)); 
} 
+1

立即修好了!!!!谢谢!! :) – MickeyThreeSheds

+0

@MickeyThreeSheds很高兴知道。 :) – nullpointer

相关问题