Webservice IsInRole and LDAP to AD

Ask a Question related to ASP.NET Security, Design and Development.

  1. #1

    Default Webservice IsInRole and LDAP to AD

    Can someone explain to me why IsInRole will work, but using
    DirectorySearcher will not? The code is running in a business object behind
    a webservice. The user's credentials (windows authenication) are being
    passed to the webservice. The webservice is configured for "integrated
    windows authenication" and no "anonymous access".

    The error "An operations error occurred" occurs when FindOne is executed.
    The LDAP information is good as it works when it is not behind the
    webservice.

    If this is because of the double-hop of a token, how can IsInRole use the
    token and not DirectorySearcher?

    Here's the code:

    For using LDAP:

    ID = CType(System.Threading.Thread.CurrentPrincipal.Ide ntity,
    WindowsIdentity)
    ImpersonateContext = ID.Impersonate()
    oLDPA = New DirectoryEntry(LDAP://ServerName/DC=name1,DC=name2,DC=net)
    oSearch = New DirectorySearcher(oLDPA)
    oGroups = New Hashtable
    With oSearch
    .Filter =
    String.Format("(&(objectCategory=person)(objectCla ss=user)(sAMAccountName={0
    }))", Split(System.Threading.Thread.CurrentPrincipal.Ide ntity.Name, "\")(1))
    .CacheResults = False
    .PropertyNamesOnly = True
    .ReferralChasing = ReferralChasingOption.All
    Dim iSearchResult As SearchResult = .FindOne
    End With

    For using IsInRole:
    If System.Threading.Thread.CurrentPrincipal.IsInRole( sGroup) Then


    Thanks,
    Harold



    Harold Guest

  2. Similar Questions and Discussions

    1. retrieve LDAP info within webservice
      Hi, Using wse2.0 a user logs on to my application. The webservice runs within the domain, the user does not (not allways). So I use the...
    2. LDAP webservice
      Minty, Good question. It should be a query type, in fact the code says it is... Can you post the exact stack trace the comes with the "not a...
    3. isInrole
      I am using isInRole function to check if a user is in a group. It works ok except it will suddenly stop working and I will have to reboot to get it...
    4. Problems with IsInRole
      I'm having problems with WindowsPrincipal.IsInRole. It's returning false when it should return true. I've written some test code that uses...
    5. Help with IsInRole
      Hi, I am using windows integrated authentication aon my intranet. How do I check if a user is a member of a group in active directory. I have the...
  3. #2

    Default Re: Webservice IsInRole and LDAP to AD

    This is probably an issue related to security context. It is explained
    pretty throughly here:

    [url]http://support.microsoft.com/default.aspx?scid=kb;en-us;329986[/url]

    Essentially, you are probably either running as a local machine account and
    your bind to AD will end up being anonymous or you are impersonating a
    domain account, but your token can't delegate to another machine, so you
    still end up with an anonymous bind.

    You can verify this is the problem easily by changing the constructor for
    your search root DirectoryEntry to include credentials.

    Also, S.DS questions are usually best asked in the adsi.general group
    (although this is obviously relevant to ASP.NET too).

    Joe K.

    "Harold" <hwh@jttb.com> wrote in message
    news:%23OQm7ImhEHA.2952@TK2MSFTNGP09.phx.gbl...
    > Can someone explain to me why IsInRole will work, but using
    > DirectorySearcher will not? The code is running in a business object
    behind
    > a webservice. The user's credentials (windows authenication) are being
    > passed to the webservice. The webservice is configured for "integrated
    > windows authenication" and no "anonymous access".
    >
    > The error "An operations error occurred" occurs when FindOne is executed.
    > The LDAP information is good as it works when it is not behind the
    > webservice.
    >
    > If this is because of the double-hop of a token, how can IsInRole use the
    > token and not DirectorySearcher?
    >
    > Here's the code:
    >
    > For using LDAP:
    >
    > ID = CType(System.Threading.Thread.CurrentPrincipal.Ide ntity,
    > WindowsIdentity)
    > ImpersonateContext = ID.Impersonate()
    > oLDPA = New DirectoryEntry(LDAP://ServerName/DC=name1,DC=name2,DC=net)
    > oSearch = New DirectorySearcher(oLDPA)
    > oGroups = New Hashtable
    > With oSearch
    > .Filter =
    >
    String.Format("(&(objectCategory=person)(objectCla ss=user)(sAMAccountName={0
    > }))", Split(System.Threading.Thread.CurrentPrincipal.Ide ntity.Name,
    "\")(1))
    > .CacheResults = False
    > .PropertyNamesOnly = True
    > .ReferralChasing = ReferralChasingOption.All
    > Dim iSearchResult As SearchResult = .FindOne
    > End With
    >
    > For using IsInRole:
    > If System.Threading.Thread.CurrentPrincipal.IsInRole( sGroup) Then
    >
    >
    > Thanks,
    > Harold
    >
    >
    >

    Joe Kaplan \(MVP - ADSI\) Guest

  4. #3

    Default Re: Webservice IsInRole and LDAP to AD

    Thanks for the article. I understand what is being said about the primary
    token and how to get around it. What I'm having a hard time understanding
    is how can the IsInRole method access the AD information and not the
    DirectorySearcher. Are they not both using the same token?

    "Joe Kaplan (MVP - ADSI)" <joseph.e.kaplan@removethis.accenture.com> wrote
    in message news:OanhOgnhEHA.2764@TK2MSFTNGP11.phx.gbl...
    > This is probably an issue related to security context. It is explained
    > pretty throughly here:
    >
    > [url]http://support.microsoft.com/default.aspx?scid=kb;en-us;329986[/url]
    >
    > Essentially, you are probably either running as a local machine account
    and
    > your bind to AD will end up being anonymous or you are impersonating a
    > domain account, but your token can't delegate to another machine, so you
    > still end up with an anonymous bind.
    >
    > You can verify this is the problem easily by changing the constructor for
    > your search root DirectoryEntry to include credentials.
    >
    > Also, S.DS questions are usually best asked in the adsi.general group
    > (although this is obviously relevant to ASP.NET too).
    >
    > Joe K.
    >
    > "Harold" <hwh@jttb.com> wrote in message
    > news:%23OQm7ImhEHA.2952@TK2MSFTNGP09.phx.gbl...
    > > Can someone explain to me why IsInRole will work, but using
    > > DirectorySearcher will not? The code is running in a business object
    > behind
    > > a webservice. The user's credentials (windows authenication) are being
    > > passed to the webservice. The webservice is configured for "integrated
    > > windows authenication" and no "anonymous access".
    > >
    > > The error "An operations error occurred" occurs when FindOne is
    executed.
    > > The LDAP information is good as it works when it is not behind the
    > > webservice.
    > >
    > > If this is because of the double-hop of a token, how can IsInRole use
    the
    > > token and not DirectorySearcher?
    > >
    > > Here's the code:
    > >
    > > For using LDAP:
    > >
    > > ID = CType(System.Threading.Thread.CurrentPrincipal.Ide ntity,
    > > WindowsIdentity)
    > > ImpersonateContext = ID.Impersonate()
    > > oLDPA = New DirectoryEntry(LDAP://ServerName/DC=name1,DC=name2,DC=net)
    > > oSearch = New DirectorySearcher(oLDPA)
    > > oGroups = New Hashtable
    > > With oSearch
    > > .Filter =
    > >
    >
    String.Format("(&(objectCategory=person)(objectCla ss=user)(sAMAccountName={0
    > > }))", Split(System.Threading.Thread.CurrentPrincipal.Ide ntity.Name,
    > "\")(1))
    > > .CacheResults = False
    > > .PropertyNamesOnly = True
    > > .ReferralChasing = ReferralChasingOption.All
    > > Dim iSearchResult As SearchResult = .FindOne
    > > End With
    > >
    > > For using IsInRole:
    > > If System.Threading.Thread.CurrentPrincipal.IsInRole( sGroup) Then
    > >
    > >
    > > Thanks,
    > > Harold
    > >
    > >
    > >
    >
    >

    Harold Guest

  5. #4

    Default Re: Webservice IsInRole and LDAP to AD

    WindowsPrincipal.IsInRole isn't using LDAP to talk to AD. Windows
    authentication uses RPC to authenticate and communicate with the domain
    controller.

    They also may not be using the same token. Windows authentication happens
    down in the lower levels of IIS directly, not in the ASP.NET stack.
    Inetinfo.exe will pass the user's token to the aspnet_wp.exe process or your
    app pool worker process on IIS 6, and they almost never use the same process
    token.

    Joe K.

    "Harold" <hwh@jttb.com> wrote in message
    news:OX61ynrhEHA.592@TK2MSFTNGP11.phx.gbl...
    > Thanks for the article. I understand what is being said about the primary
    > token and how to get around it. What I'm having a hard time understanding
    > is how can the IsInRole method access the AD information and not the
    > DirectorySearcher. Are they not both using the same token?
    >
    > "Joe Kaplan (MVP - ADSI)" <joseph.e.kaplan@removethis.accenture.com> wrote
    > in message news:OanhOgnhEHA.2764@TK2MSFTNGP11.phx.gbl...
    > > This is probably an issue related to security context. It is explained
    > > pretty throughly here:
    > >
    > > [url]http://support.microsoft.com/default.aspx?scid=kb;en-us;329986[/url]
    > >
    > > Essentially, you are probably either running as a local machine account
    > and
    > > your bind to AD will end up being anonymous or you are impersonating a
    > > domain account, but your token can't delegate to another machine, so you
    > > still end up with an anonymous bind.
    > >
    > > You can verify this is the problem easily by changing the constructor
    for
    > > your search root DirectoryEntry to include credentials.
    > >
    > > Also, S.DS questions are usually best asked in the adsi.general group
    > > (although this is obviously relevant to ASP.NET too).
    > >
    > > Joe K.
    > >
    > > "Harold" <hwh@jttb.com> wrote in message
    > > news:%23OQm7ImhEHA.2952@TK2MSFTNGP09.phx.gbl...
    > > > Can someone explain to me why IsInRole will work, but using
    > > > DirectorySearcher will not? The code is running in a business object
    > > behind
    > > > a webservice. The user's credentials (windows authenication) are
    being
    > > > passed to the webservice. The webservice is configured for
    "integrated
    > > > windows authenication" and no "anonymous access".
    > > >
    > > > The error "An operations error occurred" occurs when FindOne is
    > executed.
    > > > The LDAP information is good as it works when it is not behind the
    > > > webservice.
    > > >
    > > > If this is because of the double-hop of a token, how can IsInRole use
    > the
    > > > token and not DirectorySearcher?
    > > >
    > > > Here's the code:
    > > >
    > > > For using LDAP:
    > > >
    > > > ID = CType(System.Threading.Thread.CurrentPrincipal.Ide ntity,
    > > > WindowsIdentity)
    > > > ImpersonateContext = ID.Impersonate()
    > > > oLDPA = New DirectoryEntry(LDAP://ServerName/DC=name1,DC=name2,DC=net)
    > > > oSearch = New DirectorySearcher(oLDPA)
    > > > oGroups = New Hashtable
    > > > With oSearch
    > > > .Filter =
    > > >
    > >
    >
    String.Format("(&(objectCategory=person)(objectCla ss=user)(sAMAccountName={0
    > > > }))", Split(System.Threading.Thread.CurrentPrincipal.Ide ntity.Name,
    > > "\")(1))
    > > > .CacheResults = False
    > > > .PropertyNamesOnly = True
    > > > .ReferralChasing = ReferralChasingOption.All
    > > > Dim iSearchResult As SearchResult = .FindOne
    > > > End With
    > > >
    > > > For using IsInRole:
    > > > If System.Threading.Thread.CurrentPrincipal.IsInRole( sGroup) Then
    > > >
    > > >
    > > > Thanks,
    > > > Harold
    > > >
    > > >
    > > >
    > >
    > >
    >
    >

    Joe Kaplan \(MVP - ADSI\) Guest

Posting Permissions

  • You may not post new threads
  • You may post replies
  • You may not post attachments
  • You may not edit your posts

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139