Bonjour,

Je cherche à me connecter à un serveur Exchange en NTLM, à travers l'API d'Apache. Cependant, ça ne fonctionne pas et j'obtiens l'erreur :
You do not have permission to view this directory or page using the credentials that you supplied because your Web browser is sending a WWW-Authenticate header field that the Web server is not configured to accept
Le problème ne vient pas du serveur, il fonctionne et répond correctement si je n'utilise pas Java.

Mon code est le suivant :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
     DefaultHttpClient httpClient = new DefaultHttpClient();
 
     httpClient.getParams().setParameter(AuthPNames.TARGET_AUTH_PREF, Arrays.asList(AuthPolicy.NTLM));
     httpClient.getAuthSchemes().register(AuthPolicy.NTLM, new NTLMSchemeFactory());
     httpClient.getCredentialsProvider().setCredentials(new AuthScope(this.host, this.port), new NTCredentials(username, password,workstation,domain));
 
     HttpPost httppost = new HttpPost(this.exchangeEwsUrl);
 
     ContentProducer cp = new ContentProducer() {
 
          @Override
          public void writeTo(OutputStream outstream) throws IOException {
                Writer writer = new OutputStreamWriter(outstream, "UTF-8");
                writer.write("" + createItem);
                writer.flush();
          }
     };
     HttpEntity entity1 = new EntityTemplate(cp);
 
     Header ctype = new BasicHeader("Content-Type", "text/xml; charset=UTF-8");
     Header soapAction = new BasicHeader("SOAPAction", "\"http://schemas.microsoft.com/exchange/services/2006/messages/GetFolder\"");
 
     httppost.setHeaders(new Header[]{ctype, soapAction});
 
     httppost.setEntity(entity1);
 
     HttpContext localContext = new BasicHttpContext();
     HttpResponse response1 = httpclient.execute(httppost,localContext);
 
     AuthState proxyAuthState = (AuthState) localContext.getAttribute(ClientContext.PROXY_AUTH_STATE);
 
     System.out.println("Proxy auth state: " + proxyAuthState.getAuthScope());
     System.out.println("Proxy auth scheme: " + proxyAuthState.getAuthScheme());
     System.out.println("Proxy auth credentials: " + proxyAuthState.getCredentials());
 
     AuthState targetAuthState = (AuthState) localContext.getAttribute(ClientContext.TARGET_AUTH_STATE);
 
     System.out.println("Target auth state: " + targetAuthState.getAuthScope());
     System.out.println("Target auth scheme: " + targetAuthState.getAuthScheme());
     System.out.println("Target auth credentials: " + targetAuthState.getCredentials());
Le log que je sors me donne :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
Proxy auth state: null
Proxy auth scheme: null
Proxy auth credentials: null
Target auth state: NTLM <any realm>@mail.*******.com:443
Target auth scheme: ntlm
Target auth credentials: null
La partie proxy me semble normale mais la partie Target me semble complètement fausse, le port est censé être 993 et non pas 443 et les credentials sont null.

Quelqu'un pourrait-il m'aider ?

Merci d'avance