<?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: Create a User using the PHP SDK in Security</title>
    <link>https://community.splunk.com/t5/Security/Create-a-User-using-the-PHP-SDK/m-p/24496#M812</link>
    <description>&lt;P&gt;Hi Sir,&lt;/P&gt;

&lt;P&gt;I'm sorry for asking this question if you don't mind, can you please give me some tips on how to generate dashboard using php sdk. I've been running in circles over this matter for days. Can you please help if it is ok.&lt;/P&gt;

&lt;P&gt;Thank you in advance. ^^&lt;/P&gt;</description>
    <pubDate>Thu, 19 Dec 2013 03:11:22 GMT</pubDate>
    <dc:creator>leordimalanta</dc:creator>
    <dc:date>2013-12-19T03:11:22Z</dc:date>
    <item>
      <title>Create a User using the PHP SDK</title>
      <link>https://community.splunk.com/t5/Security/Create-a-User-using-the-PHP-SDK/m-p/24492#M808</link>
      <description>&lt;P&gt;I'm building a PHP web app that uses the Splunk PHP SDK and I've hit a brick wall trying to create a new Splunk user.&lt;/P&gt;

&lt;P&gt;Ideally when a user account is created in my app, a corresponding account should be created in Splunk with the same credentials.&lt;/P&gt;

&lt;P&gt;I've read up on the REST documentation and found the correct Endpoint - &lt;CODE&gt;authentication/users/&lt;/CODE&gt; but as far as I can tell the PHP SDK does not support creating an Entity that is not part of a Collection as &lt;CODE&gt;Splunk_Entity&lt;/CODE&gt; does not have a &lt;CODE&gt;create()&lt;/CODE&gt; method.&lt;/P&gt;

&lt;P&gt;I have successfully created dashboards using the SDK which are &lt;CODE&gt;Splunk_Collection&lt;/CODE&gt; objects, and gathered system info from &lt;CODE&gt;server/info&lt;/CODE&gt; as a &lt;CODE&gt;Splunk_Entity&lt;/CODE&gt;.&lt;/P&gt;

&lt;P&gt;I have attempted to create a user by using &lt;CODE&gt;create()&lt;/CODE&gt; on a &lt;CODE&gt;Splunk_Collection&lt;/CODE&gt;, but as &lt;CODE&gt;authentication/users&lt;/CODE&gt; does not have a namespace when the collection is returned a fatal is thrown attempting to check the non-existent namespace:&lt;/P&gt;

&lt;BLOCKQUOTE&gt;
&lt;P&gt;Fatal error: Call to a member function children() on a non-object in /var/www/html/dev/plugins/splunk_connector/sdk/Splunk/AtomFeed.php on line 45&lt;/P&gt;
&lt;/BLOCKQUOTE&gt;

&lt;P&gt;In summary, my questions are:&lt;/P&gt;

&lt;UL&gt;
&lt;LI&gt;How (if at all) can I create an Entity using the PHP SDK?&lt;/LI&gt;
&lt;LI&gt;How do I create a User using the &lt;CODE&gt;authenticaiton/users&lt;/CODE&gt; Endpoint?&lt;/LI&gt;
&lt;/UL&gt;</description>
      <pubDate>Mon, 05 Aug 2013 08:29:28 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Security/Create-a-User-using-the-PHP-SDK/m-p/24492#M808</guid>
      <dc:creator>ztom</dc:creator>
      <dc:date>2013-08-05T08:29:28Z</dc:date>
    </item>
    <item>
      <title>Re: Create a User using the PHP SDK</title>
      <link>https://community.splunk.com/t5/Security/Create-a-User-using-the-PHP-SDK/m-p/24493#M809</link>
      <description>&lt;P&gt;Entities in Splunk are arranged into collections, and it is collections that have a create method. Even though the Splunk SDK for PHP doesn't have explicit support for users, it's a very regular collection (with the exception that usernames are case insensitive, so stick with all lowercase or it will get confused), and you can create a collection by hand.&lt;/P&gt;

&lt;P&gt;So if you have a Splunk service object in &lt;TT&gt;$service&lt;/TT&gt;, you can do&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;$userCollection = new Splunk_Collection($service, 'authentication/users/');
$user = $userCollection-&amp;gt;create("my_new_user", array(
    "password" =&amp;gt; "some_password",
    "roles" =&amp;gt; array("user", "power")
));
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;(I haven't actually tried that since I don't have PHP installed on this machine, but it should be close.) This creates a user in Splunk and returns and entity that references it.&lt;/P&gt;</description>
      <pubDate>Tue, 06 Aug 2013 17:36:41 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Security/Create-a-User-using-the-PHP-SDK/m-p/24493#M809</guid>
      <dc:creator>fross_splunk</dc:creator>
      <dc:date>2013-08-06T17:36:41Z</dc:date>
    </item>
    <item>
      <title>Re: Create a User using the PHP SDK</title>
      <link>https://community.splunk.com/t5/Security/Create-a-User-using-the-PHP-SDK/m-p/24494#M810</link>
      <description>&lt;P&gt;Thanks!&lt;/P&gt;

&lt;P&gt;I tried the code that you provided but encountered the same issue I highlighted before:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;Fatal error: Call to a member function children() on a non-object in /var/www/html/dev/plugins/splunk_connector/sdk/Splunk/AtomFeed.php on line 45
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;After digging into the SDK I believe I've found the root cause of the issue:&lt;/P&gt;

&lt;P&gt;Line 242 in Collection.php, in the &lt;CODE&gt;create()&lt;/CODE&gt; function checks for an endpoint that doesn't return content by testing&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;if ($response-&amp;gt;body === '')
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;The triple equals type check always fails because the empty Entity returned when creating a user returns an empty &lt;CODE&gt;SimpleXMLElement Object ( )&lt;/CODE&gt; instead of an empty string.&lt;/P&gt;

&lt;P&gt;I don't have enough experience or exposure to the SDK to say this will fix all test cases, but changing to the use of &lt;CODE&gt;empty()&lt;/CODE&gt; fixes the problem for me:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;if ( empty($response-&amp;gt;body) )
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 07 Aug 2013 07:58:41 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Security/Create-a-User-using-the-PHP-SDK/m-p/24494#M810</guid>
      <dc:creator>ztom</dc:creator>
      <dc:date>2013-08-07T07:58:41Z</dc:date>
    </item>
    <item>
      <title>Re: Create a User using the PHP SDK</title>
      <link>https://community.splunk.com/t5/Security/Create-a-User-using-the-PHP-SDK/m-p/24495#M811</link>
      <description>&lt;P&gt;Ah. I'll file a bug so we can fix it for the next release.&lt;/P&gt;</description>
      <pubDate>Wed, 07 Aug 2013 17:57:52 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Security/Create-a-User-using-the-PHP-SDK/m-p/24495#M811</guid>
      <dc:creator>fross_splunk</dc:creator>
      <dc:date>2013-08-07T17:57:52Z</dc:date>
    </item>
    <item>
      <title>Re: Create a User using the PHP SDK</title>
      <link>https://community.splunk.com/t5/Security/Create-a-User-using-the-PHP-SDK/m-p/24496#M812</link>
      <description>&lt;P&gt;Hi Sir,&lt;/P&gt;

&lt;P&gt;I'm sorry for asking this question if you don't mind, can you please give me some tips on how to generate dashboard using php sdk. I've been running in circles over this matter for days. Can you please help if it is ok.&lt;/P&gt;

&lt;P&gt;Thank you in advance. ^^&lt;/P&gt;</description>
      <pubDate>Thu, 19 Dec 2013 03:11:22 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Security/Create-a-User-using-the-PHP-SDK/m-p/24496#M812</guid>
      <dc:creator>leordimalanta</dc:creator>
      <dc:date>2013-12-19T03:11:22Z</dc:date>
    </item>
  </channel>
</rss>

