Android NTLM authenication made easy

If your android application use any internet resource like a API call or SOAP call ,  behind a corporate proxy you might get a authentication failed message. The issue is because the proxy server is using an authentication mechanism to restrict access. Usually proxies support basic authentication then you can get around with android builtin classes see the sample code

 

If incase the proxy doesnt support basic authentication and do have NTLM authentication support ( Mostly ISA proxy) you cannot get the authentication to work as easy as before. I have been reading some details on ntlm and few open source implementation of it. I came accross jcif library and found few usefull classes and added few android specific helper classes to make a tiny library.

With the library NTLM authentication is made very simple. Only thing you need to know is you domain name , username and password,Proxy server details if any, add the library to your build path and use NTLM class in net.maxters.ntlm package. Use the static method setNTLM with desired HttpClient and authentication parameters.

few variation of the method is also include where you can explicitly specify the scope, user credentials, proxy details, etc. Methods are

 

An example for http get would be like

 

An example for http post would be like

 

{filelink=4}

  • Erik007

    thanks

  • Cameron Charles

    hi, the downlaod link for this ntlm library is broken, any chance of a re-upload???

    • maxter

      Thanks for notification. Link is fixed 🙂

      • Cameron Charles

        That’s great thanks this library is exactly what i’ve  been looking for, can i use it freely? giving credit obviously

        • maxter

          yup, its free 🙂

          • Cameron Charles

            thankyou again, credit will be giving where highly due 

  • AIS

    try this app, solved the proxy settings for web browsers on android devices https://market.android.com/details?id=com.droid.cntlm

  • Kloseen 22

    Thanks

  • Habib

    Great work. Thanks.

  • Steve Sobek

    I am using your NTLM authentication in an internal app at the company I work for. It works great! Is it possible to get the source? I need to satisfy legal, even with an internal app, that there are no open source license files (Apache, LGPL, etc.) we need to include with the app.

    Thanks!

  • androidprogger

    Hi, can i use you libary with this tutorial ? Any example?

    http://weblogs.asp.net/uruit/archive/2011/09/13/accessing-odata-from-android-using-restlet.aspx

    My Problem: My odata webservice is NTLM protected.

  • Tzaro

    I would try your lib. How can I get it? No download link there!?

    • maxters

      click on download at the end of the post

      • mike

        i see login button there and i cannot login also there is no place to register on this website

        • maxters

          sorry about that can you try again . it should work without login now.

  • Tkota

    hi, i am trying to use your library, but the app stop working when i do the client.execute(post),
    i need to use https, your library works for it?

    • maxters

      hi, i havent tested https , i did it long before , right now i dont have access to ntlm protected system as soon as i get one i will post my results

      • Tkota

        Hi, I have try it with a signed https conexion. So maybe that difficult the process.

        And thanks for your time.

  • Maggie77

    Can this be used with a webView? And if so, how?

  • Atik

    This lib is not working for me unfortunately. In browser the authentication is working and when I tried decoding the tokens exchanged during authentication I found that browser is sending token in NTLMSSP and your code sends it as NTLMSSP2. If you could explain me what might be wrong I would be grateful to you. Thanks…

  • SE

    Does not work with https. If I put https url, it ignores it and sends http request

  • Primosz

    I got “The method setNTLM(AbstractHttpClient, String, String, String, AuthScope, HttpHost) from the type NTLM is not visible”
    – after adding jar, and importing it to the class.