0

I want to connect to a https jira server using the jersey client (version 1.1.9). How do I need to configure the security options to make use of the REST-API?

I followed these instructions: Accessing secure restful web services using jersey client

But the first link in the answer is broken and I don't know how to configure the truststore and the keystore. Where do I get these files?

Community
  • 1
  • 1
MiScha
  • 31
  • 5

1 Answers1

0

I switched to jersey-client-2.19 and configured the keystore and truststore with the keytool.

    System.setProperty("jsse.enableSNIExtension", "false");

    SslConfigurator sslConfig = SslConfigurator.newInstance()
            .trustStoreFile("C:/Program Files/Java/jre1.8.0_45/lib/security/cacerts.jks")
            .trustStorePassword("somepass")
            .keyStoreFile("C:/Program Files/Java/jre1.8.0_45/lib/security/keystore.jks")
            .keyPassword("somepass");

    SSLContext sslContext = sslConfig.createSSLContext();
    Client client = ClientBuilder.newBuilder().sslContext(sslContext)
            .build();

    HttpAuthenticationFeature feature = HttpAuthenticationFeature.basic(
            JIRA_ADMIN_USERNAME, JIRA_ADMIN_PASSWORD);

    client.register(feature);

    WebTarget webTarget = client.target(JIRA_URL);

    WebTarget projectWebTarget = webTarget.path("project");

    Invocation.Builder invocationBuilder = projectWebTarget
            .request(MediaType.APPLICATION_JSON);

    Response response = invocationBuilder.get();
    System.out.println(response.getStatus());
    System.out.println(response.readEntity(String.class));

Maybe there is a better way to set the properties for the keystore and truststore. So please let me know.

MiScha
  • 31
  • 5