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

5297
19
10-11-2016 01:17 PM
by Anonymous User
Not applicable

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
JonathanQuinn
Esri Notable Contributor

Sounds like you want something like editor tracking, but for a GP service.  I don't think that there's anything within the framework to support that.  My only thought is to add a parameter so the user can select their username.  Since you'll have a defined list of users within your ArcGIS Server security, you could create a dropdown list of the user names, but you're relying on the user to select the correct one.  You can probably do this with an SOI.

by Anonymous User
Not applicable

Thanks for the reply Jonathan.

I haven't been able to find anything yet within the framework. Seems a little strange that the script is unaware of who is running it.

Relying on the user to input who they are in probably not a realistic option unfortunately.

Unless anyone else has any thoughts then I guess the only option is an SOI as you suggest.

0 Kudos
ChrisPedrezuela
Occasional Contributor III

I think when you switch the default log messages level settings from "Warning" to "Verbose", you can capture detailed instance of the GP or even map service being consumed by a user. Just a thought.

0 Kudos
by Anonymous User
Not applicable

You mean it is possible to decipher from the verbose log files who the user is? That is only really useful for debugging. I was wanting the GP service script itself to save a log of the users who ran it.

Even if running in verbose mode could somehow allow the script to detect the user, obviously you couldn't run the GP service permanently in verbose mode...

Thanks for the comment though on an old post! 🙂

0 Kudos
ChrisPedrezuela
Occasional Contributor III

all good. just happened to see your post since I am researching on how ArcGIS server picks up usernames. from your original post you did mention it will be a secured service so im guessing you will have a portal built-in user group or AD group to share the GP service with so basically you already have a list of users. but if its a lot of users in that group then that's a bit of a task to identify who uses it most. like the other suggestion, you could just simply make it a "required" parameter on your script for it to execute and store that parameter in a table on your sde or fgdb. You can even go further and auto fill that parameter by somehow hooking up to the AD user table.

0 Kudos
by Anonymous User
Not applicable

Correct me if I'm wrong, but even making it a 'required' parameter doesn't guarantee who is using it. A user hitting the endpoint directly could pass in someone else's username as the parameter.

ChrisPedrezuela
Occasional Contributor III

true, those will be the caveat of using it as a required parameter. Unless the suggestion you made to use os.getusername would allow the GP service running on the AGS box to somehow run a python process on the user's own machine. I reckon if you want to do it like that, you might have to include a javascript based function to query the users browser if its using SSO. Just a thought, but its getting a bit complex I think.

0 Kudos
by Anonymous User
Not applicable

Yep - overly complex!    

It doesn't seem like it's possible currently, but in theory shouldn't be too difficult for ESRI to implement. I might put it in as an Idea at some point....

0 Kudos
BlakeTerhune
MVP Regular Contributor

I've never tried but what if you just put os.getenv('username') in your GP service script?

0 Kudos