且构网

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

Java客户端应用程序无法使用NT凭据连接到SharePoint

更新时间:2023-11-14 10:17:58

' Access + denied 。+ +开幕前+文件+中+本+位置%2C +你+必备+第一+浏览+至+在+网络+现场+和+选择+在+期权+到+登录+自动"


试一试。


Here is the code,

       

CredentialsProvider credsProvider = new BasicCredentialsProvider();
credsProvider.setCredentials(
            new AuthScope(AuthScope.ANY),
            new NTCredentials("username", "password", "http://localhost", "ASIAPACIFIC"));

CloseableHttpClient httpclient = HttpClients.custom()
            .setDefaultCredentialsProvider(credsProvider)
            .build();
HttpGet httpget = new HttpGet("https://xyz.sharepoint.com/teams/xyz/_api/web");
httpget.setHeader(HttpHeaders.CONTENT_TYPE, "application/json");
httpget.setHeader(HttpHeaders.ACCEPT, "application/json;odata=verbose");
CloseableHttpResponse response = httpclient.execute(httpget);
System.out.println(response.toString());

output:

HttpResponseProxy{HTTP/1.1 403 Forbidden [Cache-Control: private, max-age=0, Transfer-Encoding: chunked, Content-Type: application/json;odata=verbose;charset=utf-8, Expires: Sun, 24 Feb 2019 09:48:26 GMT, Last-Modified: Mon, 11 Mar 2019 08:48:26 GMT, P3P: CP="ALL IND DSP COR ADM CONo CUR CUSo IVAo IVDo PSA PSD TAI TELo OUR SAMo CNT COM INT NAV ONL PHY PRE PUR UNI", X-SharePointHealthScore: 6, X-Forms_Based_Auth_Required: https://hpe.sharepoint.com/_forms/default.aspx?ReturnUrl=/_layouts/15/error.aspx&Source=%2f_vti_bin%2fclient.svc%2fweb, X-Forms_Based_Auth_Return_Url: https://xyz.sharepoint.com/_layouts/15/error.aspx, X-MSDAVEXT_Error: 917656; Access+denied.+Before+opening+files+in+this+location%2c+you+must+first+browse+to+the+web+site+and+select+the+option+to+login+automatically., DATASERVICEVERSION: 3.0, X-AspNet-Version: 4.0.30319, X-IDCRL_AUTH_PARAMS_V1: IDCRL Type="BPOSIDCRL", EndPoint="/teams/xyz/_vti_bin/idcrl.svc/", RootDomain="sharepoint.com", Policy="MBI", SPRequestGuid: d2e1c79e-50e0-8000-f629-22b6b605d5da, request-id: d2e1c79e-50e0-8000-f629-22b6b605d5da, MS-CV: nsfh0uBQAID2KSK2tgXV2g.0, Strict-Transport-Security: max-age=31536000, X-FRAME-OPTIONS: SAMEORIGIN, X-Powered-By: ASP.NET, MicrosoftSharePointTeamServices: 16.0.0.8627, X-Content-Type-Options: nosniff, X-MS-InvokeApp: 1; RequireReadOnly, X-MSEdge-Ref: Ref A: 818E839C1B5D446D939128A3C6B82B03 Ref B: MAA01EDGE0209 Ref C: 2019-03-11T08:48:26Z, Date: Mon, 11 Mar 2019 08:48:26 GMT] ResponseEntityProxy{[Content-Type: application/json;odata=verbose;charset=utf-8,Chunked: true]}}
HTTP/1.1 403 Forbidden

Could you please let me know what is the wrong?

'Access+denied.+Before+opening+files+in+this+location%2c+you+must+first+browse+to+the+web+site+and+select+the+option+to+login+automatically'

Have a try.