users@jersey.java.net

[Jersey] How to deploy secured (SSL) root resource containing not secured sub-resource methods?

From: <justphilmusic_at_googlemail.com>
Date: Thu, 19 Apr 2012 09:54:52 +0000 (GMT)

Hello everybody!

I'm about to run some tests with the "https-clientserver-grizzly"
Jersey example and I'm struggling with the following use case.

I've got a root resource (similar to the one from the example) that
should mainly be accessible through HTTPS (with client cert auth
enabled). But this root resource also contains a sub-resource method
that should be accessible publicly without client cert auth and plain
HTTP.

But I don't see a way to accomplish this, because according to the
server startup code (Server.java in the example) Grizzly's HttpServer
instance is started with the "secure" flag set to "true". So, there's
no possibility to tell Jersey that some sub-resources should be not
secured. You can see the server startup code below.


I appreciate all hints regarding the problem!

Thanks in advance,
Phil






// Grizzly ssl configuration
        SSLContextConfigurator sslContext = new
SSLContextConfigurator();
        
        // set up security context
        sslContext.setKeyStoreFile("./keystore_server"); // contains
server keypair
        sslContext.setKeyStorePass("asdfgh");
        sslContext.setTrustStoreFile("./truststore_server"); //
contains client certificate
        sslContext.setTrustStorePass("asdfgh");

        try {

            webServer = GrizzlyServerFactory.createHttpServer(
                    getBaseURI(),
                    null,
                    true,
                    new
SSLEngineConfigurator(sslContext).setClientMode(false).setNeedClientAut
h(true)
            );

            // start Grizzly embedded server //
            System.out.println("Jersey app started. Try out " +
BASE_URI + "\nHit CTRL + C to stop it...");
            context.deploy(webServer);
            webServer.start();

        } catch (Exception ex) {
            System.out.println(ex.getMessage());
        }