DirectoryEntry CommitChanges() is throwing Access Denied error
I am working on Active Directive Role modification module in my project and getting Access denied error while Adding/Removing the roles of users. I am Administrator of AD server.
I noticed one schenario which is given below.
1: New user added in AD without any role.
2: Applying any role for user -(Getting error Access denied)
3: If apply the Super User role then role added successfully.
Code is given below
// Search for role in Adam.
DirectorySearcher directorySearcher = new DirectorySearcher(GetAdamSdsRoot());
directorySearcher.Filter = "(&(objectCategory=group)(cn=" + roleName + "))";
SearchResult searchResult = directorySearcher.FindOne();
// Remove user from role.
DirectoryEntry directoryEntry = searchResult.GetDirectoryEntry();
directoryEntry.Properties["member"].Remove("<SID=" + GetActiveDirectoryUserSid(userName) + ">");
directoryEntry.CommitChanges();
c# winforms active-directory
add a comment |
I am working on Active Directive Role modification module in my project and getting Access denied error while Adding/Removing the roles of users. I am Administrator of AD server.
I noticed one schenario which is given below.
1: New user added in AD without any role.
2: Applying any role for user -(Getting error Access denied)
3: If apply the Super User role then role added successfully.
Code is given below
// Search for role in Adam.
DirectorySearcher directorySearcher = new DirectorySearcher(GetAdamSdsRoot());
directorySearcher.Filter = "(&(objectCategory=group)(cn=" + roleName + "))";
SearchResult searchResult = directorySearcher.FindOne();
// Remove user from role.
DirectoryEntry directoryEntry = searchResult.GetDirectoryEntry();
directoryEntry.Properties["member"].Remove("<SID=" + GetActiveDirectoryUserSid(userName) + ">");
directoryEntry.CommitChanges();
c# winforms active-directory
add a comment |
I am working on Active Directive Role modification module in my project and getting Access denied error while Adding/Removing the roles of users. I am Administrator of AD server.
I noticed one schenario which is given below.
1: New user added in AD without any role.
2: Applying any role for user -(Getting error Access denied)
3: If apply the Super User role then role added successfully.
Code is given below
// Search for role in Adam.
DirectorySearcher directorySearcher = new DirectorySearcher(GetAdamSdsRoot());
directorySearcher.Filter = "(&(objectCategory=group)(cn=" + roleName + "))";
SearchResult searchResult = directorySearcher.FindOne();
// Remove user from role.
DirectoryEntry directoryEntry = searchResult.GetDirectoryEntry();
directoryEntry.Properties["member"].Remove("<SID=" + GetActiveDirectoryUserSid(userName) + ">");
directoryEntry.CommitChanges();
c# winforms active-directory
I am working on Active Directive Role modification module in my project and getting Access denied error while Adding/Removing the roles of users. I am Administrator of AD server.
I noticed one schenario which is given below.
1: New user added in AD without any role.
2: Applying any role for user -(Getting error Access denied)
3: If apply the Super User role then role added successfully.
Code is given below
// Search for role in Adam.
DirectorySearcher directorySearcher = new DirectorySearcher(GetAdamSdsRoot());
directorySearcher.Filter = "(&(objectCategory=group)(cn=" + roleName + "))";
SearchResult searchResult = directorySearcher.FindOne();
// Remove user from role.
DirectoryEntry directoryEntry = searchResult.GetDirectoryEntry();
directoryEntry.Properties["member"].Remove("<SID=" + GetActiveDirectoryUserSid(userName) + ">");
directoryEntry.CommitChanges();
c# winforms active-directory
c# winforms active-directory
asked Nov 13 '18 at 5:58
Arun SinghArun Singh
68
68
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
For one, this isn't going to work:
directoryEntry.Properties["member"].Remove("<SID=" + GetActiveDirectoryUserSid(userName) + ">");
The member
attribute is a list of distinguishedName
attributes of the members, not their SIDs. So you need to remove the user's distinguishedName
, not the SID.
But if that was the only problem, the exception would not be "Access denied".
I know you said you are an administrator, but are you running this under your administrator credentials?
Yes, I am running under the administrator account. Also noticed one more things that is given below. 1: There is 9 role on server. two is parent role and 7 is child folder role. If I assigned parent role then it work and if assigned child role then showing error. 2: If I assigned parent role and again updating child role then not getting access denied iissue.
– Arun Singh
Nov 14 '18 at 8:25
Have you changed your code to use thedistinguishedName
of the user and not the SID?
– Gabriel Luci
Nov 14 '18 at 13:13
Yes, I changed but getting diff error : "information: An invalid dn syntax has been specified.". My DN is "CN=singh Arunkumar,OU=Consultants,OU=Users,OU=SE,OU=CRFREE,DC=CRFREE,DC=com"/ Code line : directoryEntry.Properties["member"].Remove("<distinguishedName=" + GetActiveDirectoryUserDistinguishedName(userName) + ">");
– Arun Singh
Nov 15 '18 at 7:53
You don't need the "<distinguishedName=" . You just pass the DN to the Remove method.
– Gabriel Luci
Nov 15 '18 at 12:18
So in your case:directoryEntry.Properties["member"].Remove(GetActiveDirectoryUserDistinguishedName(userName))
– Gabriel Luci
Nov 15 '18 at 13:17
|
show 7 more comments
Your Answer
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53274688%2fdirectoryentry-commitchanges-is-throwing-access-denied-error%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
For one, this isn't going to work:
directoryEntry.Properties["member"].Remove("<SID=" + GetActiveDirectoryUserSid(userName) + ">");
The member
attribute is a list of distinguishedName
attributes of the members, not their SIDs. So you need to remove the user's distinguishedName
, not the SID.
But if that was the only problem, the exception would not be "Access denied".
I know you said you are an administrator, but are you running this under your administrator credentials?
Yes, I am running under the administrator account. Also noticed one more things that is given below. 1: There is 9 role on server. two is parent role and 7 is child folder role. If I assigned parent role then it work and if assigned child role then showing error. 2: If I assigned parent role and again updating child role then not getting access denied iissue.
– Arun Singh
Nov 14 '18 at 8:25
Have you changed your code to use thedistinguishedName
of the user and not the SID?
– Gabriel Luci
Nov 14 '18 at 13:13
Yes, I changed but getting diff error : "information: An invalid dn syntax has been specified.". My DN is "CN=singh Arunkumar,OU=Consultants,OU=Users,OU=SE,OU=CRFREE,DC=CRFREE,DC=com"/ Code line : directoryEntry.Properties["member"].Remove("<distinguishedName=" + GetActiveDirectoryUserDistinguishedName(userName) + ">");
– Arun Singh
Nov 15 '18 at 7:53
You don't need the "<distinguishedName=" . You just pass the DN to the Remove method.
– Gabriel Luci
Nov 15 '18 at 12:18
So in your case:directoryEntry.Properties["member"].Remove(GetActiveDirectoryUserDistinguishedName(userName))
– Gabriel Luci
Nov 15 '18 at 13:17
|
show 7 more comments
For one, this isn't going to work:
directoryEntry.Properties["member"].Remove("<SID=" + GetActiveDirectoryUserSid(userName) + ">");
The member
attribute is a list of distinguishedName
attributes of the members, not their SIDs. So you need to remove the user's distinguishedName
, not the SID.
But if that was the only problem, the exception would not be "Access denied".
I know you said you are an administrator, but are you running this under your administrator credentials?
Yes, I am running under the administrator account. Also noticed one more things that is given below. 1: There is 9 role on server. two is parent role and 7 is child folder role. If I assigned parent role then it work and if assigned child role then showing error. 2: If I assigned parent role and again updating child role then not getting access denied iissue.
– Arun Singh
Nov 14 '18 at 8:25
Have you changed your code to use thedistinguishedName
of the user and not the SID?
– Gabriel Luci
Nov 14 '18 at 13:13
Yes, I changed but getting diff error : "information: An invalid dn syntax has been specified.". My DN is "CN=singh Arunkumar,OU=Consultants,OU=Users,OU=SE,OU=CRFREE,DC=CRFREE,DC=com"/ Code line : directoryEntry.Properties["member"].Remove("<distinguishedName=" + GetActiveDirectoryUserDistinguishedName(userName) + ">");
– Arun Singh
Nov 15 '18 at 7:53
You don't need the "<distinguishedName=" . You just pass the DN to the Remove method.
– Gabriel Luci
Nov 15 '18 at 12:18
So in your case:directoryEntry.Properties["member"].Remove(GetActiveDirectoryUserDistinguishedName(userName))
– Gabriel Luci
Nov 15 '18 at 13:17
|
show 7 more comments
For one, this isn't going to work:
directoryEntry.Properties["member"].Remove("<SID=" + GetActiveDirectoryUserSid(userName) + ">");
The member
attribute is a list of distinguishedName
attributes of the members, not their SIDs. So you need to remove the user's distinguishedName
, not the SID.
But if that was the only problem, the exception would not be "Access denied".
I know you said you are an administrator, but are you running this under your administrator credentials?
For one, this isn't going to work:
directoryEntry.Properties["member"].Remove("<SID=" + GetActiveDirectoryUserSid(userName) + ">");
The member
attribute is a list of distinguishedName
attributes of the members, not their SIDs. So you need to remove the user's distinguishedName
, not the SID.
But if that was the only problem, the exception would not be "Access denied".
I know you said you are an administrator, but are you running this under your administrator credentials?
answered Nov 13 '18 at 14:14
Gabriel LuciGabriel Luci
10.8k11424
10.8k11424
Yes, I am running under the administrator account. Also noticed one more things that is given below. 1: There is 9 role on server. two is parent role and 7 is child folder role. If I assigned parent role then it work and if assigned child role then showing error. 2: If I assigned parent role and again updating child role then not getting access denied iissue.
– Arun Singh
Nov 14 '18 at 8:25
Have you changed your code to use thedistinguishedName
of the user and not the SID?
– Gabriel Luci
Nov 14 '18 at 13:13
Yes, I changed but getting diff error : "information: An invalid dn syntax has been specified.". My DN is "CN=singh Arunkumar,OU=Consultants,OU=Users,OU=SE,OU=CRFREE,DC=CRFREE,DC=com"/ Code line : directoryEntry.Properties["member"].Remove("<distinguishedName=" + GetActiveDirectoryUserDistinguishedName(userName) + ">");
– Arun Singh
Nov 15 '18 at 7:53
You don't need the "<distinguishedName=" . You just pass the DN to the Remove method.
– Gabriel Luci
Nov 15 '18 at 12:18
So in your case:directoryEntry.Properties["member"].Remove(GetActiveDirectoryUserDistinguishedName(userName))
– Gabriel Luci
Nov 15 '18 at 13:17
|
show 7 more comments
Yes, I am running under the administrator account. Also noticed one more things that is given below. 1: There is 9 role on server. two is parent role and 7 is child folder role. If I assigned parent role then it work and if assigned child role then showing error. 2: If I assigned parent role and again updating child role then not getting access denied iissue.
– Arun Singh
Nov 14 '18 at 8:25
Have you changed your code to use thedistinguishedName
of the user and not the SID?
– Gabriel Luci
Nov 14 '18 at 13:13
Yes, I changed but getting diff error : "information: An invalid dn syntax has been specified.". My DN is "CN=singh Arunkumar,OU=Consultants,OU=Users,OU=SE,OU=CRFREE,DC=CRFREE,DC=com"/ Code line : directoryEntry.Properties["member"].Remove("<distinguishedName=" + GetActiveDirectoryUserDistinguishedName(userName) + ">");
– Arun Singh
Nov 15 '18 at 7:53
You don't need the "<distinguishedName=" . You just pass the DN to the Remove method.
– Gabriel Luci
Nov 15 '18 at 12:18
So in your case:directoryEntry.Properties["member"].Remove(GetActiveDirectoryUserDistinguishedName(userName))
– Gabriel Luci
Nov 15 '18 at 13:17
Yes, I am running under the administrator account. Also noticed one more things that is given below. 1: There is 9 role on server. two is parent role and 7 is child folder role. If I assigned parent role then it work and if assigned child role then showing error. 2: If I assigned parent role and again updating child role then not getting access denied iissue.
– Arun Singh
Nov 14 '18 at 8:25
Yes, I am running under the administrator account. Also noticed one more things that is given below. 1: There is 9 role on server. two is parent role and 7 is child folder role. If I assigned parent role then it work and if assigned child role then showing error. 2: If I assigned parent role and again updating child role then not getting access denied iissue.
– Arun Singh
Nov 14 '18 at 8:25
Have you changed your code to use the
distinguishedName
of the user and not the SID?– Gabriel Luci
Nov 14 '18 at 13:13
Have you changed your code to use the
distinguishedName
of the user and not the SID?– Gabriel Luci
Nov 14 '18 at 13:13
Yes, I changed but getting diff error : "information: An invalid dn syntax has been specified.". My DN is "CN=singh Arunkumar,OU=Consultants,OU=Users,OU=SE,OU=CRFREE,DC=CRFREE,DC=com"/ Code line : directoryEntry.Properties["member"].Remove("<distinguishedName=" + GetActiveDirectoryUserDistinguishedName(userName) + ">");
– Arun Singh
Nov 15 '18 at 7:53
Yes, I changed but getting diff error : "information: An invalid dn syntax has been specified.". My DN is "CN=singh Arunkumar,OU=Consultants,OU=Users,OU=SE,OU=CRFREE,DC=CRFREE,DC=com"/ Code line : directoryEntry.Properties["member"].Remove("<distinguishedName=" + GetActiveDirectoryUserDistinguishedName(userName) + ">");
– Arun Singh
Nov 15 '18 at 7:53
You don't need the "<distinguishedName=" . You just pass the DN to the Remove method.
– Gabriel Luci
Nov 15 '18 at 12:18
You don't need the "<distinguishedName=" . You just pass the DN to the Remove method.
– Gabriel Luci
Nov 15 '18 at 12:18
So in your case:
directoryEntry.Properties["member"].Remove(GetActiveDirectoryUserDistinguishedName(userName))
– Gabriel Luci
Nov 15 '18 at 13:17
So in your case:
directoryEntry.Properties["member"].Remove(GetActiveDirectoryUserDistinguishedName(userName))
– Gabriel Luci
Nov 15 '18 at 13:17
|
show 7 more comments
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53274688%2fdirectoryentry-commitchanges-is-throwing-access-denied-error%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown