ManageEngine to Sharepoint身份验证401 NTLM

时间:2015-06-18 10:52:19

标签: java authentication sharepoint curl sharepoint-2010

我需要一些Java应用程序的帮助。 此代码来自ManageEngine,是与Jira集成的示例。

我需要与Sharepoint集成,但我无法访问Sharepoint并且正在获取

  

'未经授权:您未经过身份验证。需要身份验证    执行此操作'

     
      
  • 这是错误401。
  •   

我有一个curl脚本来测试访问权限,这只适用于NTLM身份验证 - 但是此示例是为BASIC身份验证构建的。

请问一些如何在此脚本中转换此身份验证以使用NTLM的帮助 - 我花了几天时间阅读这篇文章,但我对Java很新,所以我现在真的很喜欢。

我认为问题在于代码的这一部分(完整代码要大到现在):

 private String getResultantFromExtApp(String requestURL, String methodType, String data, HashMap authenticationDetails) throws Exception {

    String resultant = null;
    String userName = (String) authenticationDetails.get("username");
    String passWord = (String) authenticationDetails.get("password");
    logger.log(Level.INFO, "requestURL:::::::::" + requestURL);
    try
    {
        URL url = new URL(requestURL);
        BASE64Encoder enc = new BASE64Encoder();

        String userpassword = userName + ":" + passWord;
        String encodedAuthorization = new sun.misc.BASE64Encoder().encode(userpassword.getBytes());
        HttpURLConnection connection = (HttpURLConnection) url.openConnection();
        connection.setDoOutput(true);
        if (methodType.equals("POST"))
        {
            connection.setRequestMethod("POST"); // No I18N
        }
        else if (methodType.equals("GET"))
        {
            connection.setRequestMethod("GET"); // No I18N
        }

        connection.setRequestProperty("Content-Type", "application/json"); // No I18N
        connection.setRequestProperty("Authorization", "Basic " + encodedAuthorization); // No I18N
        if (methodType.equals("POST"))
        {
            connection.setUseCaches(false);
            connection.setAllowUserInteraction(false);
            OutputStream out = connection.getOutputStream();
            Writer write = new OutputStreamWriter(out, "UTF-8"); // No I18N
            write.write(data);
            write.close();
            out.close();
        }
        int responseCode = connection.getResponseCode();
        logger.log(Level.INFO, "responseCode:::::::::" + responseCode);
        InputStream content = null;

0 个答案:

没有答案