Is there any way to get the username of user logged into Arcgis Server via the web for a GP service using arcpy?

2496
19
10-11-2016 01:17 PM
PaulHaakma
Regular Contributor

Hi.

I'm wanting to publish a python script as a geoprocessing service (a secured service). Is there any way for arcpy to get the name of the arcgis server user who calls the gp task?

e.g. I log in and run the GP tool from the rest url, the script grabs my login name and the current datetime and adds it to a log table. We then end up with a log table of all users and times the script was run.

Cheers,

-Paul

19 Replies
ChrisPedrezuela
Occasional Contributor III

since the script will run on the AGS box, wouldn't this function just pick up the current login credential which will be the ags service account?

ArjunDongre
Occasional Contributor

Did you ever get an answer for this? I did exactly this for a map service using an SOI (java), but unfortunately you cannot write SOE/SOI's for geoprocessing services (which I am trying to figure a work around for now).

0 Kudos
PaulHaakma
Regular Contributor

Never found a way to get the username, so have assumed the answer is that no, it is not possible.

0 Kudos
DanCronin
New Contributor II

It seems as though you can achieve this by causing the GP tool to create a record in an editor-tracked table.  At least, that is what I've observed with a secured GP service + web appbuilder + EGDB.  Is there a reason why that's not practical in this case?  

0 Kudos
PaulHaakma
Regular Contributor

Hi Dan.

You mention "...by causing the GP tool to create a record in an editor-tracked table". The original question was about how a GP tool would know who the user is. Creating a record is easy of course, but no one yet has mentioned a way that the GP tool would actually know the identity/username of the user who triggered the GP service. If you know of a way, please share!

cheers,

-Paul

0 Kudos
JakubOrálek
New Contributor II

Hi. Few years ago I solved it by decripting token send by the GP Service. I prepared DecryptArcGISToken.exe console app that was called from inside a Python script. It uses ESRI.ArcGIS.TokenService.dll

Maybe there is something for Portal too, asuming majority of apps uses Portal authentication.

0 Kudos
MarcusRomboy2
New Contributor

I was able to pull the user name out of the jobinfo.json file that is created when a GP tool runs. This file ends up in the Jobs directory where the results of GP tools end up. Such as:

c:\arcgisserver\directories\arcgisjobs\<folder name>\<service>_gpserver\<job id>\jobinfo.json

The jobinfo.json file has the user and the machine that ran the service. A new directory with GP results gets created when the code runs. I snag the path and job id by using arcpy.env.scratchFolder. Then I read the jobsinfo.json file to grab the user and write it to a log.

GiacomoFavaron
New Contributor III

This doesn't work for me. I am in 10.5 what version are you?

0 Kudos
FlorianSteiner
New Contributor III

Might be different, because the config-file seems to be only available with asynchronous GP-services.

0 Kudos
helgesmebye
New Contributor

Thanks for the solution - solves my problem and lets me track who actually run the GP tool!

0 Kudos