Upgrade Notes for Dropwizard 0.9.x
Migrating Auth
Any custom types representing a user need to implement the
PrincipalinterfaceIn your
Application#runaddenvironment.jersey().register(RolesAllowedDynamicFeature.class);
Create an Authorizer
public class ExampleAuthorizer implements Authorizer<User> { @Override public boolean authorize(User user, String role) { return user.getName().equals("good-guy") && role.equals("ADMIN"); } }
Create an
AuthFilterusing yourAuthenticatorandAuthorizerfinal BasicCredentialAuthFilter<User> userBasicCredentialAuthFilter = new BasicCredentialAuthFilter.Builder<User>() .setAuthenticator(new ExampleAuthenticator()) .setRealm("SUPER SECRET STUFF") .setAuthorizer(new ExampleAuthorizer()) .buildAuthFilter();
Register
AuthDynamicFeaturewith yourAuthFilterenvironment.jersey().register(new AuthDynamicFeature(userBasicCredentialAuthFilter));
Register the
AuthValueFactoryProvider.Binderso with your custom user type if you have oneenvironment.jersey().register(new AuthValueFactoryProvider.Binder(User.class));
Annotate resources methods that already have
@Authwith@RolesAllowed("admin")where admin is a role$ curl 'testUser:secret@localhost:8080/protected' Hey there, testUser. You know the secret!
UnwrapValidatedValue Changes
With the upgrade to Hibernate Validator 5.2.1.Final, the behavior of @UnwrapValidatedValue has slightly changed.
In some situations, the annotation is now unnecessary.
However, when inference is not possible and is ambiguous where the constraint annotation applies, a runtime exception is thrown.
This is only a problem when dealing with constraints that can apply to both the wrapper and inner type like @NotNull.
The fix is to explicitly set false or true for @UnwrapValidatedValue
For instance if you previously had code like:
@GET
public String heads(@QueryParam("cheese") @NotNull IntParam secretSauce) {
Where @NotNull is meant to apply to wrapper type of IntParam and not the inner type of
Integer (as IntParam will never yield a null integer).
Hibernate Validator doesn’t know this, but it does know that @NotNull can be applied to both IntParam and Integer,
so in Dropwizard 0.9.x the previous code will now fail and must be changed to
@GET
public String heads(@QueryParam("cheese") @NotNull @UnwrapValidatedValue(false) IntParam secretSauce) {
For more information on the behavior changes, see accompanying table for automatic value unwrapping
Logging bootstrap
If you configured console logging in your tests with a utility method shipped with Dropwizard,
you should replace calls of LoggingFactory.bootstrap to BootstrapLogging.bootstrap.