users@jersey.java.net

Re: [Jersey] Jersey and (dynamic) basic authentication?

From: Casper Bang <casper_at_jbr.dk>
Date: Thu, 26 Mar 2009 01:51:45 +0100

Ok turned out it was easy enough, filed here for the sake of people
searching this in the future. Inside the <servlet> tag, add the
init-param's:

        <init-param>
            <param-name>com.sun.jersey.config.property.packages</param-name>

<param-value>com.sun.jersey.samples.contacts.server;com.sun.jersey.samples.contacts.server.auth</param-value>
        </init-param>

        <init-param>

<param-name>com.sun.jersey.spi.container.ContainerRequestFilters</param-name>

<param-value>com.sun.jersey.samples.contacts.server.auth.SecurityFilter</param-value>
        </init-param>

        <init-param>

<param-name>com.sun.jersey.spi.container.ResourceFilters</param-name>

<param-value>com.sun.jersey.api.container.filter.RolesAllowedResourceFilterFactory</param-value>
        </init-param>

/Casper


2009/3/25 Casper Bang <casper_at_jbr.dk>

> Thanks, that's a good example. Although I am not really able to make the
> per request filter work with Tomcat. I guess I would somehow need to
> register this in my web.xml to mimic what's done to the stand-alone Grizzly
> setup:
>
> initParams.put("com.sun.jersey.config.property.packages",
> "com.sun.jersey.samples.contacts.server;" +
> "com.sun.jersey.samples.contacts.server.auth");
> initParams.put(ResourceConfig.PROPERTY_CONTAINER_REQUEST_FILTERS,
> SecurityFilter.class.getName());
> initParams.put(ResourceConfig.PROPERTY_RESOURCE_FILTER_FACTORIES,
> RolesAllowedResourceFilterFactory.class.getName());
>
> Would a kind soul familiar with Grizzly know how to do the same for Tomcat?
>
> Thanks,
> Casper
>
>