Axon.ivy 7.0 - the Digital Business Platform - is out now...

Can you explain how to call a REST Service which is secured by NTLM?

asked 09.10 at 06:03

SupportIvyTeam's gravatar image

SupportIvyTeam ♦♦
accept rate: 81%

1) Add the library jersey-apache-connector-*.jar to your project. You can find this library in the public maven repository:

2) Implement a NTLM feature which will add the credentials to each request:


import org.apache.http.auth.AuthScope;
import org.apache.http.auth.NTCredentials;
import org.apache.http.client.CredentialsProvider;
import org.apache.http.impl.client.BasicCredentialsProvider;
import org.glassfish.jersey.apache.connector.ApacheClientProperties;

public class NtlmFeature implements Feature {

    private static String USER = "your-username";
    private static String PASSWORD = "your-password";
    private static String WORKSTATION = null;
    private static String DOMAIN = null;

    public boolean configure(FeatureContext context) {
        CredentialsProvider credentialsProvider = new BasicCredentialsProvider();
        NTCredentials ntCredentials = new NTCredentials(USER, PASSWORD, WORKSTATION, DOMAIN);
        credentialsProvider.setCredentials(AuthScope.ANY, ntCredentials);, credentialsProvider);
        return true;


3) Add the tomcat plugin to the project. This plugin holds the Jersey Client Libraries which will be needed in step 4.

  • Convert the project as plugin-project (Java Perspective > Right Click on the Project > Configure > Convert to Plugin-Projects ...)
  • Go to Tab Dependencies and add the tomcat plugin (simply type tomcat)

4) Implement the call. In this scenario you must create the rest client on your own and you can't use the Ivy Rest Clients (


import org.glassfish.jersey.apache.connector.ApacheConnectorProvider;
import org.glassfish.jersey.client.ClientConfig;

import ch.ivyteam.ivy.environment.Ivy;

public class NtlmClient {

    private static String baseUrl = "http://localhost/ntlmProtectedRessource";

    public static void callNtlmProtectedRestService() {
        Client client = ClientBuilder.newClient(createConfig());
        client.register(new NtlmFeature());
        WebTarget target =;
        Response response = target.request(MediaType.APPLICATION_JSON_TYPE).get();
        Ivy.log().info("HTTP Status Code: " + response.getStatus());

    private static ClientConfig createConfig() {
        ClientConfig clientConfig = new ClientConfig();
        clientConfig.connectorProvider(new ApacheConnectorProvider());
        return clientConfig;


Outlook: The customization of a rest client will be improved. So that you can use also in this scenario the rest client call steps.


answered 09.10 at 06:20

Alex%20Suter's gravatar image

Alex Suter ♦♦
accept rate: 83%

edited 09.10 at 06:29

Your answer
toggle preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here



Answers and Comments

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text]( "Title")
  • image?![alt text](/path/img.jpg "Title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported



Asked: 09.10 at 06:03

Seen: 34 times

Last updated: 09.10 at 06:29