Android and IIS server Authentication

Source: Internet
Author: User

1) Basic Verification:

1 /**2 * Take pictures from the server3      * 4      * @paramURL5      * @return6      */7      Public voidGethttpbitmap (FinalString URL) {8         NewThread (NewRunnable () {9              Public voidrun () {TenBitmap Bitmap =NULL; One                 Try { AHttpGet HttpPost =Newhttpget (URL); -Defaulthttpclient httpClient =Newdefaulthttpclient (); -                     //Basic Identity Verification theBasiccredentialsprovider bcp =NewBasiccredentialsprovider (); -String userName = "UserName"; -String password = "Password"; -Authscope Authscope =NewAuthscope (authscope.any); + bcp.setcredentials (Authscope, - New Usernamepasswordcredentials (userName, password)); +  A Httpclient.setcredentialsprovider (bcp); at                     
Basic Authentication Ends
HttpResponse HttpResponse =Httpclient.execute (httppost); -ANDROID.UTIL.LOG.I ("", "=====>" +httpresponse.getstatusline (). Getstatuscode ()); -ANDROID.UTIL.LOG.I ("", "=====>" +httpresponse.getentity (). Getcontentlength ()); -InputStream is =httpresponse.getentity (). getcontent (); -Bitmap =Bitmapfactory.decodestream (IS); - is.close (); in}Catch(Exception e) { - e.printstacktrace (); to } + - GetResult (bitmap); the } * }). Start (); $}
1 byte [] Encodedpassword = (userName + ":" + password). getBytes (); 2 httppost.addheader ("Authorization", "Base" + base64.encodetostring (Encodedpassword, base64.no_wrap);

2) NTLM authentication:

1  //Register NTLM auth scheme2Httpclient.getauthschemes (). Register ("NTLM",Newntlmschemefactory ());3 Httpclient.getcredentialsprovider (). SetCredentials (4                             //Limit the credentials only to the specified domain and port5                             NewAuthscope (Authscope.any_host, authscope.any_port),6                             //specify credentials, most of the time was User/pass is needed7                             NewNtcredentials (userName, Password, "", "")8);

Direct replacement//basic verification to use

Use Jcifs-1.3.17.jar (available for download to HTTPS://GITHUB.COM/MASCONSULT/ANDROID-NTLM)

1  Public classNtlmschemefactoryImplementsauthschemefactory2 {3 @Override4      Publicauthscheme newinstance (httpparams params)5     {6         return NewNtlmscheme (Newjcifsengine ());7     }8}
1  Public classJcifsengineImplementsNtlmengine {2 3     Private Static Final intType_1_flags =ntlmflags.ntlmssp_negotiate_564|ntlmflags.ntlmssp_negotiate_1285|ntlmflags.ntlmssp_negotiate_ntlm26|ntlmflags.ntlmssp_negotiate_always_sign7|Ntlmflags.ntlmssp_request_target;8 9 @OverrideTen      Publicstring generatetype1msg (string domain, string workstation) One             throwsntlmengineexception { A         FinalType1message Type1message =Newtype1message (Type_1_flags, - domain, workstation); -         returnBase64.encode (Type1message.tobytearray ()); the     } -  - @Override -      Publicstring Generatetype3msg (string username, string password, + string domain, string workstation, String challenge) -             throwsntlmengineexception { + type2message type2message; A  at         Try { -Type2message =NewType2message (Base64.decode (Challenge)); -}Catch(FinalIOException Exception) { -             Throw NewNtlmengineexception ("Error in type2 message", exception); -         } -  in         Final intType2flags =type2message.getflags (); -         Final intType3flags =Type2flags to& (0xFFFFFFFF ^ (Ntlmflags.ntlmssp_target_type_domain |ntlmflags.ntlmssp_target_type_server)); +         FinalType3message Type3message =Newtype3message (Type2message, - password, domain, username, workstation, type3flags); the         returnBase64.encode (Type3message.tobytearray ()); *     } $}

Android and IIS server Authentication

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.