且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

Android的Windows身份验证

更新时间:2023-12-02 10:21:58

好了,所以我做的第一件事就是导入的 JCIFS 库。它的一个罐子,你从该链接下载。

Okay so the first thing I did was to import the JCIFS library. Its a jar you download from that link.

我需要做的下一件事是导入JCIFSEngine类和NTLMSchemeFactory类到您的项目。

The next thing I needed to do was to import the JCIFSEngine class and NTLMSchemeFactory class into your project.

于是最后这个方法建立你了HTTPClient:

Then finally this method builds your HTTPClient:

//I know it is deprecated but there is no other way to implement NTLM thus far.
    private static DefaultHttpClient setupHttpClient (String username, String password) {
        DefaultHttpClient httpclient = new DefaultHttpClient();
        // register ntlm auth scheme
        httpclient.getAuthSchemes().register("ntlm", new NTLMSchemeFactory());
        httpclient.getCredentialsProvider().setCredentials(
                // Limit the credentials only to the specified domain and port
                new AuthScope(AuthScope.ANY_HOST, AuthScope.ANY_PORT),
                // Specify credentials, most of the time only user/pass is needed
                new NTCredentials(username, password, "", "")
        );
        return httpclient;
    }

我的连接与改造完成,所以我只是附上这个使用了HTTPClient以下行来改造:

My connections are done with Retrofit so I just attach this HTTPClient to retrofit using the following line:

retrofitAdapterBuilder.setClient(new ApacheClient(setupHttpClient(username, password)));

这为我工作至今偶虽然这是非常糟糕的是Android有对此没有本地支持。

This worked for me thus far even-though it is really bad that Android has no native support for this.