<?xml version="1.0" encoding="utf-8"?>
<rss xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title>Answers to: How to call a NTLM protected REST Service</title><link>https://answers.axonivy.com/questions/2904/how-to-call-a-ntlm-protected-rest-service</link><description>&lt;p&gt;Can you explain how to call a REST Service which is secured by NTLM?&lt;/p&gt;</description><atom:link href="https://answers.axonivy.com/questions/2904/how-to-call-a-ntlm-protected-rest-service" rel="self"></atom:link><language>en</language><lastBuildDate>Wed, 25 Oct 2017 09:08:01 -0400</lastBuildDate><item><title>Comment by Reguel Wermelinger on Alex Suter's answer</title><link>https://answers.axonivy.com/questions/2904/how-to-call-a-ntlm-protected-rest-service#2930</link><description>&lt;p&gt;This approach works in Axon.ivy 7.0 LTS and newer. 6.3 and maybe other Leading Edge versions have to be patched as follows: &lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;open the &lt;code&gt;/plugins/ch.ivyteam.tomcat.XYZ.jar&lt;/code&gt; of the Designer with 7-ZIP.&lt;/li&gt;
&lt;li&gt;Modify the &lt;code&gt;META-INF/Manifest.MF&lt;/code&gt;. Extend the 'Export-Package: ' entry with an additional classpath &lt;code&gt;org.glassfish.jersey.client.spi&lt;/code&gt; . Update the JAR with your modified Manifest.&lt;/li&gt;
&lt;li&gt;Start the Designer binary with &lt;code&gt;-clean&lt;/code&gt; to enforce that the plugin MANIFST.MF will be read&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;&lt;img alt="alt text" src="https://answers.axonivy.com/upfiles/tomcatClasspathExtension63_GNfs8R1.png"&gt;&lt;/p&gt;</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">Reguel Wermelinger</dc:creator><pubDate>Wed, 25 Oct 2017 09:08:01 -0400</pubDate><guid>https://answers.axonivy.com/questions/2904/how-to-call-a-ntlm-protected-rest-service#2930</guid></item><item><title>Answer by Alex Suter</title><link>https://answers.axonivy.com/questions/2904/how-to-call-a-ntlm-protected-rest-service/2905</link><description>&lt;p&gt;1)
Add the library &lt;code&gt;jersey-apache-connector-*.jar&lt;/code&gt; to your project. You can find this library in the public maven repository:
&lt;a href="https://mvnrepository.com/artifact/org.glassfish.jersey.connectors/jersey-apache-connector"&gt;https://mvnrepository.com/artifact/org.glassfish.jersey.connectors/jersey-apache-connector&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;2)
Implement a NTLM feature which will add the credentials to each request:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;import javax.ws.rs.core.Feature;
import javax.ws.rs.core.FeatureContext;

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;

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

}
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;3) Add the tomcat plugin to the project. This plugin holds the Jersey Client Libraries which will be needed in step 4.&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Convert the project as plugin-project (Java Perspective &amp;gt; Right Click on the Project &amp;gt; Configure &amp;gt; Convert to Plugin-Projects ...)&lt;/li&gt;
&lt;li&gt;Open META-INF/MANIFEST.MF&lt;/li&gt;
&lt;li&gt;Go to Tab Dependencies and add the tomcat plugin (simply type tomcat)&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;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 (Ivy.rest().client(..)):&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;import javax.ws.rs.client.Client;
import javax.ws.rs.client.ClientBuilder;
import javax.ws.rs.client.WebTarget;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;

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 = client.target(baseUrl);
        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;
    }

}
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;strong&gt;Axon.ivy 7.1 and later&lt;/strong&gt;:
Starting with Axon.ivy 7.1 a Feature called &lt;em&gt;&lt;a href="https://developer.axonivy.com/doc/7.1.latest/DesignerGuideHtml/ivy.configuration.html#ivy-rest-client"&gt;NtlmAuthenticationFeature&lt;/a&gt;&lt;/em&gt; will be provided, that simplifies the calling of NTLM protected web services.&lt;/p&gt;</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">Alex Suter</dc:creator><pubDate>Mon, 09 Oct 2017 06:20:44 -0400</pubDate><guid>https://answers.axonivy.com/questions/2904/how-to-call-a-ntlm-protected-rest-service/2905</guid></item></channel></rss>