users@glassfish.java.net

Re: custom X509TrustManager

From: <glassfish_at_javadesktop.org>
Date: Tue, 08 Jul 2008 07:11:04 PDT

tried -Dcom.sun.enterprise.server.ss.ASQuickStartup with both true and false - same error.

Here is a simple LifecycleListener implementation class:

public class EMELifeCycleListener implements LifecycleListener {

    public void handleEvent(LifecycleEvent event) throws ServerLifecycleException {
        LifecycleEventContext ctx = event.getLifecycleEventContext();
        if (LifecycleEvent.INIT_EVENT == event.getEventType()) {
            ctx.log("EMELifeCycleListener: INIT_EVENT");
            return;
        }
        if (LifecycleEvent.STARTUP_EVENT == event.getEventType()) {
            ctx.log("EMELifeCycleListener: STARTUP_EVENT");
            return;
        }
        if (LifecycleEvent.SHUTDOWN_EVENT == event.getEventType()) {
            ctx.log("EMELifeCycleListener: SHUTDOWN_EVENT");
            return;
        }
        if (LifecycleEvent.TERMINATION_EVENT == event.getEventType()) {
            ctx.log("EMELifeCycleListener: TERMINATE_EVENT");
            return;
        }
     /*Do simple init of my TrustManager no matter which state we are in*/
        init(ctx);
    }

    private static void init(LifecycleEventContext ctx) {
        ctx.log("EMELifeCycleListener: init()");
        try {
            SSLContext context = SSLContext.getInstance("SSL");
            TrustManager[] trustManagerArray = {new EMEX509TrustManager()};
            context.init(null, trustManagerArray, new java.security.SecureRandom());
            HttpsURLConnection.setDefaultSSLSocketFactory(context.getSocketFactory());
        } catch (KeyManagementException ex) {
            ctx.log("EMELifeCycleListener got KeyManagementException" + ex.getMessage());
        } catch (NoSuchAlgorithmException ex) {
            ctx.log("EMELifeCycleListener got NoSuchAlgorithmException" + ex.getMessage());
        }
    }

    private static class EMEX509TrustManager implements X509TrustManager {

        public void checkClientTrusted(X509Certificate[] chain, String authType) throws CertificateException {
        }

        public void checkServerTrusted(X509Certificate[] chain, String authType) throws CertificateException {
        }

        public X509Certificate[] getAcceptedIssuers() {
            return new X509Certificate[0];
        }
    }
}


/mareks
[Message sent by forum member 'mareks' (mareks)]

http://forums.java.net/jive/thread.jspa?messageID=285065