Skip to content
DataMiner DoJo

More results...

Generic selectors
Exact matches only
Search in title
Search in content
Post Type Selectors
Search in posts
Search in pages
Search in posts
Search in pages
Log in
Menu
  • Blog
  • Questions
  • Learning
    • E-learning Courses
    • Open Classroom Training
    • Certification
      • DataMiner Fundamentals
      • DataMiner Configurator
      • DataMiner Automation
      • Scripts & Connectors Developer: HTTP Basics
      • Scripts & Connectors Developer: SNMP Basics
      • Visual Overview – Level 1
      • Verify a certificate
    • Tutorials
    • Video Library
    • Books We Like
    • >> Go to DataMiner Docs
  • Expert Center
    • Solutions & Use Cases
      • Solutions
      • Use Case Library
    • Markets & Industries
      • Media production
      • Government & defense
      • Content distribution
      • Service providers
      • Partners
      • OSS/BSS
    • DataMiner Insights
      • Security
      • Integration Studio
      • System Architecture
      • DataMiner Releases & Updates
      • DataMiner Apps
    • Agile
      • Agile Webspace
      • Everything Agile
        • The Agile Manifesto
        • Best Practices
        • Retro Recipes
      • Methodologies
        • The Scrum Framework
        • Kanban
        • Extreme Programming
      • Roles
        • The Product Owner
        • The Agile Coach
        • The Quality & UX Coach (QX)
    • DataMiner DevOps Professional Program
  • Downloads
  • More
    • Feature Suggestions
    • Climb the leaderboard!
    • Swag Shop
    • Contact
      • General Inquiries
      • DataMiner DevOps Support
      • Commercial Requests
    • Global Feedback Survey
  • PARTNERS
    • All Partners
    • Technology Partners
    • Strategic Partner Program
    • Deal Registration
  • >> Go to dataminer.services

Impersonating User in C# causes users to be removed on LDAP synchronization

Solved1.76K views18th May 2022CSharp impersonation LDAP LDAP synchornization powershell
4
Pedro Carmo [SLC]20 17th May 2022 2 Comments

Hi all,

I'm creating a protocol to fetch DHCP information through powershell.

I'm able to access the information if I:

  1. Open a powershell instance;
  2. run start powershell -credential ""
  3. introduce username and password of another user with permissions to access such information
  4. run Get-DhcpServerv4Scope -ComputerName "swic3dhcp1"

Without step 2 I'm not able to run step 4, due to lack of permissions.

After doing some investigation, the only way I was able to successfully launch a powershell instance with permissions to fetch the DHCP data was by using 'SimpleImpersonation' NuGet, that uses the LogonUser Windows API to run code as another user:

using (SafeAccessTokenHandle userHandle = credentials.LogonUser(LogonType.Interactive))
{
response = WindowsIdentity.RunImpersonated(userHandle, () =>
{
var ps = PowerShell.Create();
ps.AddScript(@"Get-DhcpServerv4Scope -ComputerName ""swic3dhcp1""");
return InvokeSafe(ps, protocol);
});
}

However, once the LDAP Resync task runs a lot of users belonging to a group are removed from DataMiner and it's no longer possible to access the Agent with those accounts:

Text of the highlighted events:

'twic4ums1a' | 'Security Edited'| 'Users(s) ORFCMC\USRCWIC9CTLWS04AGR, ORFCMC\USRCWIC9CTLWS01BGR, ORFCMC\USRCWIC9CTLWS01AGR, ORFCMC\USRCWIC9CTLWS03AGR, ORFCMC\USRCWIC9CTLWS03BGR, ORFCMC\USRCWIC9CTLWS02BGR removed from group ORFCMC\res.adm25.svcDataminer.CMC.Playout By DMS-synchronization from Active directory'

- Today 4:37:03 PM

'twic4ums1a' | 'Client disconnected' | 'SLHelper.exe/Group Combination Connection ($$GROUPSEC\$$GRP_35) removed because of error: Unable to connect to the remote server'

-Today 4:20:11 PM

NOTE: I also checked how powershell commands are executed in the node tool automation script and I get an exception: access is denied when creating a PSSession object.

Given that I'm using WindowsIdentity.RunImpersonated, contained in the System.Security.Principal namespace, I believe using this is messing up something in the Active Directory.

If I cannot use this approach, can somebody suggest how to get around this?

Thanks in advance.

Best Regards

Pedro Carmo [SLC] Selected answer as best 18th May 2022
Gellynck Jens [SLC] commented 18th May 2022

Are the users still part of the group on the DC / Active Directory?

Pedro Carmo [SLC] commented 18th May 2022

Yes, they only get removed in the synchronization after the code runs. If I restore the security.xml file and don’t run that piece of code, the synchronization will not remove any account.

1 Answer

  • Active
  • Voted
  • Newest
  • Oldest
3
João Severino [SLC] [DevOps Catalyst]12.94K Posted 18th May 2022 1 Comment

I have had success in the past with running methods as an impersonated user by following the example given on this page:

WindowsIdentity.Impersonate Method (System.Security.Principal) | Microsoft Docs

It looks similar to the code the NuGet you are using implements but I do not use the RunImpersonated call.

Instead, like in the example, I call WindowsIdentity.Impersonate and after that, I just run my normal methods as if no impersonation was needed.

Pedro Carmo [SLC] Posted new comment 18th May 2022
Pedro Carmo [SLC] commented 18th May 2022

I’ve used WindowsIdentity.Impersonate and it works perfectly without removing DataMiner users.
Looks like this solves the impersonation issue.
Thanks for the help!

You are viewing 1 out of 1 answers, click here to view all answers.
Please login to be able to comment or post an answer.

My DevOps rank

DevOps Members get more insights on their profile page.

My user earnings

0 Dojo credits

Spend your credits in our swag shop.

0 Reputation points

Boost your reputation, climb the leaderboard.

Promo banner DataMiner DevOps Professiona Program
DataMiner Integration Studio (DIS)
Empower Katas

Recent questions

Multiple Set on Table parameters for DVE’s 0 Answers | 1 Vote
DOM Definition relations returned in Definition query 0 Answers | 1 Vote
Alarm Dashboard PDF/CSV Export 1 Answer | 0 Votes

Question Tags

adl2099 (115) alarm (62) Alarm Console (82) alarms (100) alarm template (83) Automation (223) automation scipt (111) Automation script (167) backup (71) Cassandra (180) Connector (108) Correlation (68) Cube (150) Dashboard (194) Dashboards (188) database (83) DataMiner Cube (57) DIS (81) DMS (71) DOM (140) driver (65) DVE (56) Elastic (83) Elasticsearch (115) elements (80) Failover (104) GQI (159) HTTP (76) IDP (74) LCA (152) low code app (166) low code apps (93) lowcodeapps (75) MySQL (53) protocol (203) QAction (83) security (88) services (51) SNMP (86) SRM (337) table (54) trending (87) upgrade (62) Visio (539) Visual Overview (345)
Privacy Policy • Terms & Conditions • Contact

© 2025 Skyline Communications. All rights reserved.

DOJO Q&A widget

Can't find what you need?

? Explore the Q&A DataMiner Docs

[ Placeholder content for popup link ] WordPress Download Manager - Best Download Management Plugin