<?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: Get current user (and their roles) from SplunkJS in Security</title>
    <link>https://community.splunk.com/t5/Security/Get-current-user-and-their-roles-from-SplunkJS/m-p/145162#M4439</link>
    <description>&lt;P&gt;Hi rmearkle,&lt;/P&gt;

&lt;P&gt;I have similar kind of requirement.&lt;/P&gt;

&lt;P&gt;How can we call this entire code in a function?&lt;/P&gt;

&lt;P&gt;How can use this code to restrict few inputs buttons as invisible?&lt;/P&gt;

&lt;P&gt;-Krishna Rajapantula&lt;/P&gt;</description>
    <pubDate>Thu, 01 Oct 2015 16:02:26 GMT</pubDate>
    <dc:creator>krishnarajapant</dc:creator>
    <dc:date>2015-10-01T16:02:26Z</dc:date>
    <item>
      <title>Get current user (and their roles) from SplunkJS</title>
      <link>https://community.splunk.com/t5/Security/Get-current-user-and-their-roles-from-SplunkJS/m-p/145160#M4437</link>
      <description>&lt;P&gt;I am creating a custom dashboard that will be distributed to a wide range of people with varying levels of access. I have found this code to get the current user:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;require([ 'underscore', 'jquery', 'splunkjs/mvc', ],
       function(_, $, mvc ) {        
          var tokens = mvc.Components.getInstance("default");       
          var current=Splunk.util.getConfigValue("USERNAME");        
          tokens.set("currentuser", current);
       });
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;I also need to be able to get user roles, so that I can dynamically set properties in my D3 chart on this dashboard. &lt;/P&gt;

&lt;P&gt;The only alternative I have found is creating what could become dozens of different dashboards with set permissions, which is not really acceptable as there will be so many different tiers under different branches.&lt;/P&gt;</description>
      <pubDate>Tue, 28 Jul 2015 13:00:52 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Security/Get-current-user-and-their-roles-from-SplunkJS/m-p/145160#M4437</guid>
      <dc:creator>rmearkle</dc:creator>
      <dc:date>2015-07-28T13:00:52Z</dc:date>
    </item>
    <item>
      <title>Re: Get current user (and their roles) from SplunkJS</title>
      <link>https://community.splunk.com/t5/Security/Get-current-user-and-their-roles-from-SplunkJS/m-p/145161#M4438</link>
      <description>&lt;P&gt;Well, answered my own question. Using the REST function I was able to get the roles and parse them inside my Javascript.&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;var userSearch = new SearchManager({
                    "id": "userSearch",
                    "preview": "false",
                    "cache": "false",
                    "search": "|rest splunk_server=local /services/authentication/current-context |table roles |mvexpand roles"
                }, {tokens: false});


    userSearch.startSearch();
    var roleSearchResults = userSearch.data('results');
    roleSearchResults.on("data", function() {   
        var userRoles = roleSearchResults.data().rows;          
        for(var i=0; i&amp;lt;userRoles.length; i++){
            console.log(userRoles[i][0]);               
        }

    });
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;This code will log the string values of all the roles for the current user to the console.&lt;/P&gt;</description>
      <pubDate>Tue, 28 Jul 2015 18:59:10 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Security/Get-current-user-and-their-roles-from-SplunkJS/m-p/145161#M4438</guid>
      <dc:creator>rmearkle</dc:creator>
      <dc:date>2015-07-28T18:59:10Z</dc:date>
    </item>
    <item>
      <title>Re: Get current user (and their roles) from SplunkJS</title>
      <link>https://community.splunk.com/t5/Security/Get-current-user-and-their-roles-from-SplunkJS/m-p/145162#M4439</link>
      <description>&lt;P&gt;Hi rmearkle,&lt;/P&gt;

&lt;P&gt;I have similar kind of requirement.&lt;/P&gt;

&lt;P&gt;How can we call this entire code in a function?&lt;/P&gt;

&lt;P&gt;How can use this code to restrict few inputs buttons as invisible?&lt;/P&gt;

&lt;P&gt;-Krishna Rajapantula&lt;/P&gt;</description>
      <pubDate>Thu, 01 Oct 2015 16:02:26 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Security/Get-current-user-and-their-roles-from-SplunkJS/m-p/145162#M4439</guid>
      <dc:creator>krishnarajapant</dc:creator>
      <dc:date>2015-10-01T16:02:26Z</dc:date>
    </item>
    <item>
      <title>Re: Get current user (and their roles) from SplunkJS</title>
      <link>https://community.splunk.com/t5/Security/Get-current-user-and-their-roles-from-SplunkJS/m-p/145163#M4440</link>
      <description>&lt;P&gt;It can be done much easier...&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;                    var service = mvc.createService();
                service.currentUser(function(err, user) {
                    //user real name
                    real_name = user.properties().realname

                    //user name
                    usr = user.name

                    //user roles
                    roles = user.properties().roles
                });
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 30 Jun 2016 10:15:43 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Security/Get-current-user-and-their-roles-from-SplunkJS/m-p/145163#M4440</guid>
      <dc:creator>loggar</dc:creator>
      <dc:date>2016-06-30T10:15:43Z</dc:date>
    </item>
  </channel>
</rss>

