Hi Roman,

That sounds like a good solution. Thanks for following up!

Best regards,
Jérôme Louvel
--
Restlet ~ Founder and Lead developer ~ http://www.restlet.org
Noelios Technologies ~ Co-founder ~ http://www.noelios.com
 

-----Message d'origine-----
De : Roman Geus [mailto:[EMAIL PROTECTED] 
Envoyé : mercredi 13 août 2008 16:34
À : [email protected]
Objet : Re: Setting a Filter for a JAX-RS resource class or application

Hi again

It seems, that the following idea solves my problem.

Instantiate a subclass of JaxRsApplication, that overrides the 
createRoot() method, which installs the (Spnego)Filter.

> class ExampleApplication extends JaxRsApplication {
>     Filter filter;
>
>     public ExampleApplication(Filter filter) {
>         this.filter = filter;
>     }
>
>     @Override
>     public Restlet createRoot() {
>         if (filter != null) {
>             filter.setNext(super.createRoot());
>             return filter;
>         } else
>             return super.createRoot();
>     }
>
> }
Best regards,
Roman


Roman Geus wrote:
> Hello all
>
> I'll try to explain what I want to acomplish: Basically I would like 
> to integrate Bruno Harbulot's SPNEGO authentication filter into a 
> simple JAX-RS server.
>
> I cannot use application.setGuard(...) since authentication is 
> implemented as a Filter instead of a Guard.
>
> Here is the main class:
>
> public class ExampleServer {
>
>    public static void main(String[] args) throws Exception {
>        // create Component (as ever for Restlet)
>        Component comp = new Component();
>        Server server = comp.getServers().add(Protocol.HTTP, 8182);
>
>        // create JAX-RS runtime environment
>        JaxRsApplication application = new 
> JaxRsApplication(comp.getContext());
>
>        // Authentication filter derived from Bruno Harbulot's code
>        // How can I activate this filter?
>        SpnegoFilter filter = new SpnegoFilter();
>
>        // attach ApplicationConfig
>        application.add(new ExampleAppConfig());
>
>        // Attach the application to the component and start it
>        comp.getDefaultHost().attach(application);
>        comp.start();
>
>        System.in.read();
>        comp.stop();
>    }
> }
>
> The ApplicationConfig class:
>
> public class ExampleAppConfig extends ApplicationConfig {
>
>    public Set<Class<?>> getResourceClasses() {
>        Set<Class<?>> rrcs = new HashSet<Class<?>>();
>        rrcs.add(EasyRootResource.class);
>        return rrcs;
>    }
> }
>
> The RAX-RS Resource class:
>
> @Path("easy")
> public class EasyRootResource {
>    @Context
>    SecurityContext sc;
>
>    @GET
>    @Produces("text/html")
>    public String getHtml() {
>        return "<html><head></head><body>\n"
>                + "This is an easy resource (as html text).\n"
>                + "</body></html>";
>    }
> }
>
> The SPNEGO filter: 
>
http://git.kato.mvc.mcc.ac.uk/bruno/spnegofilter.git/?a=blob_plain;f=src/mai
n/java/uk/ac/manchester/rcs/bruno/spnegofilter/SpnegoFilter.java;hb=HEAD 
>
>
>
> Thanks,
> Roman
>
> Jerome Louvel wrote:
>> Hi Roman,
>>
>> Could you share with us a code sample that we can look at and help you
>> complete?
>>
>> Best regards,
>> Jérôme Louvel
>> -- 
>> Restlet ~ Founder and Lead developer ~ http://www.restlet.org
>> Noelios Technologies ~ Co-founder ~ http://www.noelios.com
>>
>>
>> -----Message d'origine-----
>> De : Roman Geus [mailto:[EMAIL PROTECTED] Envoyé : lundi 11 août 
>> 2008 17:05
>> À : [email protected]
>> Objet : Setting a Filter for a JAX-RS resource class or application
>>
>> Hi all
>>
>> I would like to set a Filter for a JAX-RS resource or application and 
>> I can't seem to find out how to do it properly.
>>
>> Can anybody help me with this?
>>
>> Thanks,
>> Roman
>>
>> -- 
>> Roman Geus
>> Paul Scherrer Institut
>> AIT
>> Scientific Computing
>> 5232 Villigen PSI
>> Switzerland
>>
>> Tel: +41 56 310 54 85
>> Fax: +41 56 310 36 49
>>
>> e-Mail: [EMAIL PROTECTED]
>>
>>   
>

Reply via email to