Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Finance | Project Operations, Human Resources, ...
Answered

Impersonate another user in X++ code

(0) ShareShare
ReportReport
Posted on by 225

Hello,

I am working on an AX customisation where I need to query user information in AD. I am relying on the following class:

directorySearcher = new System.DirectoryServices.DirectorySearcher(entry);

However, due to the nature of the requirements I would like - in this particular case - for this class to operate under the user credentials of a specific user - not the current AX user.

Is there anyway to achieve this in AX? I.e. instantiate the DirectorySearcher class under the credentials and rights of a different user?


Best regards,

Grzegorz Skrzypczyk

  • Verified answer
    Martin Dráb Profile Picture
    Martin Dráb 231,409 Most Valuable Professional on at
    RE: Impersonate another user in X++ code

    Look at runAs() function - that's what the system uses in places like in batch and AIF, where there is a global process doing thing on behalf of (and the security context of) actual users.

  • RE: Impersonate another user in X++ code

    Well I would prefer not to go into the details of the why. Let's say this is to handle an exceptional case which concerns a few users in an organisation counting many thousands. It is either this or a very tedious workaround.

    A batch could work - but ideally we would want this to be in interactive code.

    Storing the credentials is not a problem.

  • Suggested answer
    nmaenpaa Profile Picture
    nmaenpaa 101,156 on at
    RE: Impersonate another user in X++ code

    Even if that would be possible, you would need to provide the credentials of that user.

    So why not just login to AX with that correct user in the first place? You could let this user set up a batch that runs your code. That way it's executed with this user's identity.

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Daivat Vartak – Community Spotlight

We are honored to recognize Daivat Vartak as our March 2025 Community…

Announcing Our 2025 Season 1 Super Users!

A new season of Super Users has arrived, and we are so grateful for the daily…

Kudos to the February Top 10 Community Stars!

Thanks for all your good work in the Community!

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 292,516 Super User 2025 Season 1

#2
Martin Dráb Profile Picture

Martin Dráb 231,409 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Product updates

Dynamics 365 release plans