Dropwizard/Jersey: Authentication and JSON parameter Dropwizard/Jersey: Authentication and JSON parameter json json

Dropwizard/Jersey: Authentication and JSON parameter


I faced the same problem. In fact this was due to a missing provider in my test configuration.

In your resource unit test in the setUpResources() method, use the method addProvider() to set your authentication provider.

For example:

addProvider(new BasicAuthProvider(<Authenticator>, <CacheBuilderSpec>));


Section 3.3.2.1 notwithstanding, I haven't seen errors like you describe with methods such as the following:

public Response post(    @Auth User user, @Valid Food food, @Context UriInfo uriInfo);public Response post(    @Auth User user, @Valid Food food, @QueryParam String s);public Response post(    @Auth User user, @Valid Food food, BooleanParam b);

So a workaround might be to add an unused @QueryParam or @Context parameter.


Try to swap your methods parameters, from

public void add(@Auth User user, @Valid Food food)

to

public void add(@Valid Food food, @Auth User user)