<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Why am I receiving a 401 &amp;quot;Unauthorized&amp;quot; error for all queries via Java API? in Security</title>
    <link>https://community.splunk.com/t5/Security/Why-am-I-receiving-a-401-quot-Unauthorized-quot-error-for-all/m-p/367918#M9142</link>
    <description>&lt;P&gt;This seems to be a known issue with Java 8:&lt;/P&gt;

&lt;P&gt;&lt;A href="http://dev.splunk.com/view/java-sdk/SP-CAAAEUV"&gt;http://dev.splunk.com/view/java-sdk/SP-CAAAEUV&lt;/A&gt;&lt;/P&gt;

&lt;P&gt;It may be that you need to tie in the security protocol with the service, and not your login args. In the above documentation, it links to this test class:&lt;/P&gt;

&lt;P&gt;&lt;A href="https://github.com/splunk/splunk-sdk-java/blob/develop/examples/com/splunk/examples/ssl_protocols/Program.java"&gt;https://github.com/splunk/splunk-sdk-java/blob/develop/examples/com/splunk/examples/ssl_protocols/Program.java&lt;/A&gt;&lt;/P&gt;</description>
    <pubDate>Mon, 08 May 2017 17:18:06 GMT</pubDate>
    <dc:creator>randyabeyta</dc:creator>
    <dc:date>2017-05-08T17:18:06Z</dc:date>
    <item>
      <title>Why am I receiving a 401 "Unauthorized" error for all queries via Java API?</title>
      <link>https://community.splunk.com/t5/Security/Why-am-I-receiving-a-401-quot-Unauthorized-quot-error-for-all/m-p/367917#M9141</link>
      <description>&lt;P&gt;Using Java 8 with Splunk 6.5.3, attempting to connect with Java API to get a service object. Using the same username and password I can connect with a browser and run queries normally. I suspect an SSL / https handler issue since the return from service has a token but the value for httpHandler is null.  I do not know how to approach it.&lt;/P&gt;

&lt;P&gt;I currently have:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;loginArgs.setSSLSecurityProtocol(SSLSecurityProtocol.TLSv1_2);
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Any suggestions very much appreciated.&lt;BR /&gt;
Thanks&lt;/P&gt;</description>
      <pubDate>Mon, 08 May 2017 15:36:48 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Security/Why-am-I-receiving-a-401-quot-Unauthorized-quot-error-for-all/m-p/367917#M9141</guid>
      <dc:creator>tdhealy</dc:creator>
      <dc:date>2017-05-08T15:36:48Z</dc:date>
    </item>
    <item>
      <title>Re: Why am I receiving a 401 "Unauthorized" error for all queries via Java API?</title>
      <link>https://community.splunk.com/t5/Security/Why-am-I-receiving-a-401-quot-Unauthorized-quot-error-for-all/m-p/367918#M9142</link>
      <description>&lt;P&gt;This seems to be a known issue with Java 8:&lt;/P&gt;

&lt;P&gt;&lt;A href="http://dev.splunk.com/view/java-sdk/SP-CAAAEUV"&gt;http://dev.splunk.com/view/java-sdk/SP-CAAAEUV&lt;/A&gt;&lt;/P&gt;

&lt;P&gt;It may be that you need to tie in the security protocol with the service, and not your login args. In the above documentation, it links to this test class:&lt;/P&gt;

&lt;P&gt;&lt;A href="https://github.com/splunk/splunk-sdk-java/blob/develop/examples/com/splunk/examples/ssl_protocols/Program.java"&gt;https://github.com/splunk/splunk-sdk-java/blob/develop/examples/com/splunk/examples/ssl_protocols/Program.java&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 08 May 2017 17:18:06 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Security/Why-am-I-receiving-a-401-quot-Unauthorized-quot-error-for-all/m-p/367918#M9142</guid>
      <dc:creator>randyabeyta</dc:creator>
      <dc:date>2017-05-08T17:18:06Z</dc:date>
    </item>
    <item>
      <title>Re: Why am I receiving a 401 "Unauthorized" error for all queries via Java API?</title>
      <link>https://community.splunk.com/t5/Security/Why-am-I-receiving-a-401-quot-Unauthorized-quot-error-for-all/m-p/367919#M9143</link>
      <description>&lt;P&gt;Thanks for your help Randy. I had found that Program.java yesterday after Googling my ass off, but it had failed too. So I revisited it and found that the SDK Command parser was corrupting my password string by dropping one character. So I used ServiceArgs to tray an alternative and all the connections now worked! The connection part is shown below.&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;public SplunkNAT(Properties pr) {

    props = pr;
    errLog = Utils.initLogging(props);

    ServiceArgs loginArgs = new ServiceArgs();
    loginArgs.setUsername(user);
    loginArgs.setPassword(auth);
    loginArgs.setHost(host);
    loginArgs.setPort(port);
    loginArgs.setScheme("https");
    loginArgs.setSSLSecurityProtocol(SSLSecurityProtocol.TLSv1_2);

    System.out.println("Now trying to connect to Splunk using TLSv1.2");
    try {
        Service.setSslSecurityProtocol(SSLSecurityProtocol.TLSv1_2);
        service = Service.connect(loginArgs);
        service.login();
        System.out.println("\t Success!");

    } catch (RuntimeException re) {
        errLog.severe("Unable to make Splunk Service: " + re.getMessage()
                + ExceptionUtils.getStackTrace(re));
    }
    System.out.println("Installed apps: " + service.getApplications().keySet());
}
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;-Terry&lt;/P&gt;</description>
      <pubDate>Mon, 08 May 2017 18:34:03 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Security/Why-am-I-receiving-a-401-quot-Unauthorized-quot-error-for-all/m-p/367919#M9143</guid>
      <dc:creator>tdhealy</dc:creator>
      <dc:date>2017-05-08T18:34:03Z</dc:date>
    </item>
  </channel>
</rss>

