Spring Rest template with http client for NTLM authentication

拥有回忆 提交于 2019-12-11 02:38:32

问题


We have a web service deployed in IIS server which authenticate based on NTLM authentication.

When i try to access the web service by passing username and password in httpCleint UserNamePasswordCredentials, am getting warnings as

NTLM authentication error: Credentials cannot be used for NTLM authentication: org.apache.http.auth.UsernamePasswordCredentials

Please clarify how to user http client with spring rest template to pass the NTLM authentication with user name and password.

Note:Though am getting the warning message, am also getting response.


回答1:


Just define the following class.

public class NtlmAuthenticator extends Authenticator {

        private final String username;
        private final char[] password;

        public NtlmAuthenticator(final String username, final String password) {
            super();
            this.username = username;
            this.password = password.toCharArray();
        }

        @Override
        public PasswordAuthentication getPasswordAuthentication() {
            return (new PasswordAuthentication(username, password));
        }
    }

then add the following code.Thats it.It started working.

NtlmAuthenticator authenticator = new NtlmAuthenticator(userName,
                    password);
            Authenticator.setDefault(authenticator);


来源:https://stackoverflow.com/questions/29840639/spring-rest-template-with-http-client-for-ntlm-authentication

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!