Ruan Ricardo
Ruan Ricardo

Reputation: 1

Call NTLM secured endpoint via Apache Camel

I am creating the following route, which uses NTLM authentication, but 401 is always returned and with the following error

from("direct:start")
    .setHeader(Exchange.HTTP_METHOD, () -> "GET")
    .setHeader(Exchange.HTTP_URI, () -> "https://www.test.com")
    .to("http://host" +
    "?authMethodPriority=NTLM" +
    "&authMethod=NTLM" +
    "&authUsername=user" +
    "&authPassword=pass")
    .log("Response: ${body}");

Error stack

2024-05-20T12:06:11.556-03:00  WARN 24517 --- [pocs] [           main] 
o.a.h.c.h.impl.auth.HttpAuthenticator    : ex-0000000001 Negotiate{FAILED } 
authentication error: No valid credentials provided (Mechanism level: No valid 
credentials provided (Mechanism level: Failed to find any Kerberos tgt))

any suggestions for routes that use NTLM?

I tried using 'authMethod' = NTLM but without success

Upvotes: 0

Views: 111

Answers (1)

Raphi1
Raphi1

Reputation: 573

You need to create a bean and put that bean as the clientBuilder parameter to your call. For example like this

Bean-Code

@Bean(name = "httpClientBuilder")
public HttpClientBuilder httpClientBuilder() {
    CredentialsProvider credsProvider = new BasicCredentialsProvider();
    credsProvider.setCredentials(AuthScope.ANY, new NTCredentials(ntlmUsername, ntlmPassword, "", ""));
    HttpClientBuilder httpClientBuilder = HttpClientBuilder.create();
    httpClientBuilder.setDefaultCredentialsProvider(credsProvider);

    return httpClientBuilder;
}

Note, that you have to put your actual credentials there, and if you need the domain also replace the "" in the constructor of NTCredentials.

Route:

from("direct:start")
    .setHeader(Exchange.HTTP_METHOD, () -> "GET")
    .setHeader(Exchange.HTTP_URI, () -> "https://www.test.com")
    .to("http://host" +
    "?clientBuilder=#httpClientBuilder")
    .log("Response: ${body}");

With the #httpClientBuilder you're referencing the bean by name.

Upvotes: 0

Related Questions