How to Optionally Protect a Resource with Custom Dropwizard Filter
<p>I'm using Dropwizard 0.9.2 and I want to create a resource that requires no authentication for GET and requires basic authentication for POST.</p>

<p>I have tried</p>

<pre><code>@Path("/protectedPing")
@Produces(MediaType.TEXT_PLAIN)
public class ProtectedPing {

@GET
public String everybody() {

    return "pingpong";
}

@PermitAll
@POST
public String authenticated(){
    return "secret pingpong";
}
</code></pre>

<p>with</p>

<pre><code>CachingAuthenticator&lt;BasicCredentials, User&gt; ca = new CachingAuthenticator&lt;&gt;(environment.metrics(), ldapAuthenticator, cbSpec);
AdminAuthorizer authorizer = new AdminAuthorizer();
BasicCredentialAuthFilter&lt;User&gt; bcaf = new BasicCredentialAuthFilter.Builder&lt;User&gt;().setAuthenticator(ca).setRealm("test-oauth").setAuthorizer(authorizer).buildAuthFilter();
environment.jersey().register(bcaf);
environment.jersey().register(RolesAllowedDynamicFeature.class);
environment.jersey().register(new AuthValueFactoryProvider.Binder&lt;&gt;(User.class));
environment.jersey().register(new ProtectedPing());
</code></pre>

<p>This seems to result in all requests to "/protectedPing" requiring basic auth.</p>

<p>In Dropwizard 0.9.2 the documentation says to create a custom filter if I have a resource that is optionally protected.  I'm assuming I need to do that, but I don't know where to start, or if that I what I actually need to do.</p>