Внедрить Jersey-Server с взаимной (2-сторонней) аутентификацией SSL - PullRequest
0 голосов
/ 14 июня 2019

Я использую Jersey Server и хочу поддерживать взаимную (2-стороннюю) аутентификацию клиента SSL.Где настроить взаимную аутентификацию?Приведенный ниже код устанавливает соединение TLS, но не запрашивает сертификат клиента.

    public void start() throws Exception {

        // config server
        ResourceConfig config = new ResourceConfig(Rsi2018Api.class, LocationApi.class);
        Map<String, Object> properties = new HashMap<>();
        properties.put("listener", this);
        config.setProperties(properties);
        config.register(JacksonJsonProvider.class);
        config.register(JacksonFeature.class);
        config.register(new LoggingFeature(java.util.logging.Logger.getLogger(ApplicationLogger.SERVER_LOGGER_NAME),
                Level.INFO,
                LoggingFeature.Verbosity.PAYLOAD_TEXT,
                8192));

        // start server
        SSLContext sslContext = createSSLContext();
        HttpsServer httpsServer = (HttpsServer) JdkHttpServerFactory.createHttpServer(baseUri, config, sslContext, true);

    }

    private SSLContext createSSLContext() throws KeyStoreException, IOException, CertificateException, NoSuchAlgorithmException, UnrecoverableKeyException, KeyManagementException {
        SSLContext sslContext = SSLContext.getInstance("TLS");

        // initialise the keystore
        char[] password = "password".toCharArray();
        KeyStore ks = KeyStore.getInstance("JKS");
        ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
        InputStream fis = classLoader.getResourceAsStream("testkey.jks");

        ks.load(fis, password);

        // setup the key manager factory
        KeyManagerFactory kmf = KeyManagerFactory.getInstance("SunX509");
        kmf.init(ks, password);

        // setup the trust manager factory
        TrustManagerFactory tmf = TrustManagerFactory.getInstance("SunX509");
        tmf.init(ks);

        // setup the HTTPS context and parameters
        sslContext.init(kmf.getKeyManagers(), tmf.getTrustManagers(), null);
        return sslContext;
    }
...