get WindowsIdentity with forms authentication

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

  1. #1

    Default get WindowsIdentity with forms authentication

    Hi,

    I am trying to figure out a way to authenticate against Active Directory and
    retrieve system.security.principal.WindowsIdentity object, without having to
    see the awful grey Basic Authentication logon box. I have found
    documentation that you can send a authtentication request programatically by
    using the system.net.authenticationmanager.authenticate method, but i can
    not get this to work and have not found any samples.

    Does anyone know a way to Authenticate against AD and have your browser
    session retrieve a identity using forms ?

    regards

    Niclas


    Niclas Lindblom Guest

  2. Similar Questions and Discussions

    1. Accessing htm files without authentication (forms authentication)
      I have application with forms authentication. All works fine. When user opens .aspx file gets login form, login and then get the .aspx page. But...
    2. ASP.Net Forms authentication with basic authentication popup
      Relatively new to ASP.Net but have a strange problem. My site uses forms authentication for a large administration section however after the user...
    3. Forms authentication then redirection to a secure web with NT authentication?
      Hi, I want to allow access to particular secured intranet web sites. These intranet are stored in sharepoint (2003 version) Actually I've...
    4. Authentication ticket, cookieless, forms authentication?
      Hi. I want to use Forms Authentication, cookieless. The issue is setting the Authentication Ticket without using cookies (!) That is, the...
    5. Forms authentication with Windows authentication
      Hi, I have an ASP.NET web site that uses IIS Basic Authentication and accesses an OLAP Server at various stages. The OLAP Server authentication...
  3. #2

    Default Re: get WindowsIdentity with forms authentication

    If you want an actual WindowsIdentity object, you must have a logon token
    for the user, which means that you will need to call LogonUser with the
    user's credentials.

    If you would be okay with a GenericIdentity/GenericPrincipal, then you can
    create one by authenticating to AD and building those objects yourself.
    There is a sample on how to do this with System.DirectoryServices and Forms
    authentication in the MS KB:

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

    That article has some flaws in it, but it is an okay starting point. Note
    that the recommended way of doing authentication is by using SSPI instead of
    System.DirectoryServices with an LDAP bind, but I don't have a good managed
    code wrapper example of SSPI. Maybe someone else does?

    The disadvantage with the GenericIdentity is that you can't impersonate with
    it, but it can be used to drive the security model in your application using
    the standard IPrincipal interface.

    HTH,

    Joe K.

    "Niclas Lindblom" <lindblom_niclas@hotmail.com> wrote in message
    news:%23JDulu0jDHA.4008@TK2MSFTNGP11.phx.gbl...
    > Hi,
    >
    > I am trying to figure out a way to authenticate against Active Directory
    and
    > retrieve system.security.principal.WindowsIdentity object, without having
    to
    > see the awful grey Basic Authentication logon box. I have found
    > documentation that you can send a authtentication request programatically
    by
    > using the system.net.authenticationmanager.authenticate method, but i can
    > not get this to work and have not found any samples.
    >
    > Does anyone know a way to Authenticate against AD and have your browser
    > session retrieve a identity using forms ?
    >
    > regards
    >
    > Niclas
    >
    >
    Joe Kaplan \(MVP - ADSI\) Guest

  4. #3

    Default Re: get WindowsIdentity with forms authentication

    Is there no way i can do this and get the same functionality as using Basic
    authentication with the grey box (not sure how this works) since this seem
    to create a session identity automatically.

    Thanks for your help

    Niclas
    "Joe Kaplan (MVP - ADSI)" <joseph.e.kaplan@removethis.accenture.com> wrote
    in message news:ePsARB1jDHA.2416@TK2MSFTNGP10.phx.gbl...
    > If you want an actual WindowsIdentity object, you must have a logon token
    > for the user, which means that you will need to call LogonUser with the
    > user's credentials.
    >
    > If you would be okay with a GenericIdentity/GenericPrincipal, then you can
    > create one by authenticating to AD and building those objects yourself.
    > There is a sample on how to do this with System.DirectoryServices and
    Forms
    > authentication in the MS KB:
    >
    > [url]http://support.microsoft.com/default.aspx?scid=kb;en-us;326340[/url]
    >
    > That article has some flaws in it, but it is an okay starting point. Note
    > that the recommended way of doing authentication is by using SSPI instead
    of
    > System.DirectoryServices with an LDAP bind, but I don't have a good
    managed
    > code wrapper example of SSPI. Maybe someone else does?
    >
    > The disadvantage with the GenericIdentity is that you can't impersonate
    with
    > it, but it can be used to drive the security model in your application
    using
    > the standard IPrincipal interface.
    >
    > HTH,
    >
    > Joe K.
    >
    > "Niclas Lindblom" <lindblom_niclas@hotmail.com> wrote in message
    > news:%23JDulu0jDHA.4008@TK2MSFTNGP11.phx.gbl...
    > > Hi,
    > >
    > > I am trying to figure out a way to authenticate against Active Directory
    > and
    > > retrieve system.security.principal.WindowsIdentity object, without
    having
    > to
    > > see the awful grey Basic Authentication logon box. I have found
    > > documentation that you can send a authtentication request
    programatically
    > by
    > > using the system.net.authenticationmanager.authenticate method, but i
    can
    > > not get this to work and have not found any samples.
    > >
    > > Does anyone know a way to Authenticate against AD and have your browser
    > > session retrieve a identity using forms ?
    > >
    > > regards
    > >
    > > Niclas
    > >
    > >
    >

    MS Newsgroups Guest

  5. #4

    Default Re: get WindowsIdentity with forms authentication

    It sounds like you want a WindowsIdentity/logon token for the user, so you
    will need to use an API that calls LogonUser. The easy way to do this would
    be to build a Forms Auth. system that uses the new constructor on
    WindowsIdentity in Framework 1.1 that takes a username and password. Note
    that the documentation says that you must be running Win2K3 for this call to
    work.

    [url]http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/frlrfSystemSecurityPrincipalWindowsIdentityClassct orTopic5.asp?frame=true[/url]

    The other option is to P/Invoke LogonUser directly. You need very high
    privileges to call this function under Windows 2000 though, so the viability
    of this solution may depend on your platform and security needs.

    [url]http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/frlrfSystemSecurityPrincipalWindowsImpersonationCo ntextClassTopic.asp?frame=true[/url]

    Either of these (which do essentially the same thing under the hood) will
    give you the same functionality as Basic authentication (a primary logon
    token).

    HTH,

    Joe K.


    "MS Newsgroups" <nospam@nospam.com> wrote in message
    news:%23XjD939jDHA.744@tk2msftngp13.phx.gbl...
    > Is there no way i can do this and get the same functionality as using
    Basic
    > authentication with the grey box (not sure how this works) since this seem
    > to create a session identity automatically.
    >
    > Thanks for your help
    >
    > Niclas
    > "Joe Kaplan (MVP - ADSI)" <joseph.e.kaplan@removethis.accenture.com> wrote
    > in message news:ePsARB1jDHA.2416@TK2MSFTNGP10.phx.gbl...
    > > If you want an actual WindowsIdentity object, you must have a logon
    token
    > > for the user, which means that you will need to call LogonUser with the
    > > user's credentials.
    > >
    > > If you would be okay with a GenericIdentity/GenericPrincipal, then you
    can
    > > create one by authenticating to AD and building those objects yourself.
    > > There is a sample on how to do this with System.DirectoryServices and
    > Forms
    > > authentication in the MS KB:
    > >
    > > [url]http://support.microsoft.com/default.aspx?scid=kb;en-us;326340[/url]
    > >
    > > That article has some flaws in it, but it is an okay starting point.
    Note
    > > that the recommended way of doing authentication is by using SSPI
    instead
    > of
    > > System.DirectoryServices with an LDAP bind, but I don't have a good
    > managed
    > > code wrapper example of SSPI. Maybe someone else does?
    > >
    > > The disadvantage with the GenericIdentity is that you can't impersonate
    > with
    > > it, but it can be used to drive the security model in your application
    > using
    > > the standard IPrincipal interface.
    > >
    > > HTH,
    > >
    > > Joe K.
    > >
    > > "Niclas Lindblom" <lindblom_niclas@hotmail.com> wrote in message
    > > news:%23JDulu0jDHA.4008@TK2MSFTNGP11.phx.gbl...
    > > > Hi,
    > > >
    > > > I am trying to figure out a way to authenticate against Active
    Directory
    > > and
    > > > retrieve system.security.principal.WindowsIdentity object, without
    > having
    > > to
    > > > see the awful grey Basic Authentication logon box. I have found
    > > > documentation that you can send a authtentication request
    > programatically
    > > by
    > > > using the system.net.authenticationmanager.authenticate method, but i
    > can
    > > > not get this to work and have not found any samples.
    > > >
    > > > Does anyone know a way to Authenticate against AD and have your
    browser
    > > > session retrieve a identity using forms ?
    > > >
    > > > regards
    > > >
    > > > Niclas
    > > >
    > > >
    > >
    >
    >
    Joe Kaplan \(MVP - ADSI\) Guest

  6. #5

    Default Re: get WindowsIdentity with forms authentication

    Thanks Joe, I have actually looked at this option. What i haven't figured
    out yet is how to associate the current users session with the new
    WindowsIdentity object i have created. I have a feeling that i need to use
    impersonation, but haven't had time to test this yet.

    Am I one the right track, or do you know how to get this working ?

    Thanks for helping out

    Niclas
    "Joe Kaplan (MVP - ADSI)" <joseph.e.kaplan@removethis.accenture.com> wrote
    in message news:O1Va9FHkDHA.2424@TK2MSFTNGP10.phx.gbl...
    > It sounds like you want a WindowsIdentity/logon token for the user, so you
    > will need to use an API that calls LogonUser. The easy way to do this
    would
    > be to build a Forms Auth. system that uses the new constructor on
    > WindowsIdentity in Framework 1.1 that takes a username and password. Note
    > that the documentation says that you must be running Win2K3 for this call
    to
    > work.
    >
    >
    [url]http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/frlrfSystemSecurityPrincipalWindowsIdentityClassct orTopic5.asp?frame=true[/url]
    >
    > The other option is to P/Invoke LogonUser directly. You need very high
    > privileges to call this function under Windows 2000 though, so the
    viability
    > of this solution may depend on your platform and security needs.
    >
    >
    [url]http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/frlrfSystemSecurityPrincipalWindowsImpersonationCo ntextClassTopic.asp?frame=true[/url]
    >
    > Either of these (which do essentially the same thing under the hood) will
    > give you the same functionality as Basic authentication (a primary logon
    > token).
    >
    > HTH,
    >
    > Joe K.
    >
    >
    > "MS Newsgroups" <nospam@nospam.com> wrote in message
    > news:%23XjD939jDHA.744@tk2msftngp13.phx.gbl...
    > > Is there no way i can do this and get the same functionality as using
    > Basic
    > > authentication with the grey box (not sure how this works) since this
    seem
    > > to create a session identity automatically.
    > >
    > > Thanks for your help
    > >
    > > Niclas
    > > "Joe Kaplan (MVP - ADSI)" <joseph.e.kaplan@removethis.accenture.com>
    wrote
    > > in message news:ePsARB1jDHA.2416@TK2MSFTNGP10.phx.gbl...
    > > > If you want an actual WindowsIdentity object, you must have a logon
    > token
    > > > for the user, which means that you will need to call LogonUser with
    the
    > > > user's credentials.
    > > >
    > > > If you would be okay with a GenericIdentity/GenericPrincipal, then you
    > can
    > > > create one by authenticating to AD and building those objects
    yourself.
    > > > There is a sample on how to do this with System.DirectoryServices and
    > > Forms
    > > > authentication in the MS KB:
    > > >
    > > > [url]http://support.microsoft.com/default.aspx?scid=kb;en-us;326340[/url]
    > > >
    > > > That article has some flaws in it, but it is an okay starting point.
    > Note
    > > > that the recommended way of doing authentication is by using SSPI
    > instead
    > > of
    > > > System.DirectoryServices with an LDAP bind, but I don't have a good
    > > managed
    > > > code wrapper example of SSPI. Maybe someone else does?
    > > >
    > > > The disadvantage with the GenericIdentity is that you can't
    impersonate
    > > with
    > > > it, but it can be used to drive the security model in your application
    > > using
    > > > the standard IPrincipal interface.
    > > >
    > > > HTH,
    > > >
    > > > Joe K.
    > > >
    > > > "Niclas Lindblom" <lindblom_niclas@hotmail.com> wrote in message
    > > > news:%23JDulu0jDHA.4008@TK2MSFTNGP11.phx.gbl...
    > > > > Hi,
    > > > >
    > > > > I am trying to figure out a way to authenticate against Active
    > Directory
    > > > and
    > > > > retrieve system.security.principal.WindowsIdentity object, without
    > > having
    > > > to
    > > > > see the awful grey Basic Authentication logon box. I have found
    > > > > documentation that you can send a authtentication request
    > > programatically
    > > > by
    > > > > using the system.net.authenticationmanager.authenticate method, but
    i
    > > can
    > > > > not get this to work and have not found any samples.
    > > > >
    > > > > Does anyone know a way to Authenticate against AD and have your
    > browser
    > > > > session retrieve a identity using forms ?
    > > > >
    > > > > regards
    > > > >
    > > > > Niclas
    > > > >
    > > > >
    > > >
    > >
    > >
    >

    Niclas Lindblom Guest

  7. #6

    Default Re: get WindowsIdentity with forms authentication

    The normal thing to do would be to create the WindowIdentity, then to create
    a new WindowsPrincipal from that and set the User property on the
    HttpContext equal to that. Then the WindowsPrincipal for the current user
    will be associated with that request and all of the normal ASP.NET
    role-based security will flow from there.

    Someone else may need to provide you with more details if that isn't enough
    info as I am not a super expert in Forms authentication.

    Joe K.

    "Niclas Lindblom" <lindblom_niclas@hotmail.com> wrote in message
    news:eR8P5uKkDHA.1656@tk2msftngp13.phx.gbl...
    > Thanks Joe, I have actually looked at this option. What i haven't figured
    > out yet is how to associate the current users session with the new
    > WindowsIdentity object i have created. I have a feeling that i need to use
    > impersonation, but haven't had time to test this yet.
    >
    > Am I one the right track, or do you know how to get this working ?
    >
    > Thanks for helping out
    >
    > Niclas
    > "Joe Kaplan (MVP - ADSI)" <joseph.e.kaplan@removethis.accenture.com> wrote
    > in message news:O1Va9FHkDHA.2424@TK2MSFTNGP10.phx.gbl...
    > > It sounds like you want a WindowsIdentity/logon token for the user, so
    you
    > > will need to use an API that calls LogonUser. The easy way to do this
    > would
    > > be to build a Forms Auth. system that uses the new constructor on
    > > WindowsIdentity in Framework 1.1 that takes a username and password.
    Note
    > > that the documentation says that you must be running Win2K3 for this
    call
    > to
    > > work.
    > >
    > >
    >
    [url]http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/frlrfSystemSecurityPrincipalWindowsIdentityClassct orTopic5.asp?frame=true[/url]
    > >
    > > The other option is to P/Invoke LogonUser directly. You need very high
    > > privileges to call this function under Windows 2000 though, so the
    > viability
    > > of this solution may depend on your platform and security needs.
    > >
    > >
    >
    [url]http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/frlrfSystemSecurityPrincipalWindowsImpersonationCo ntextClassTopic.asp?frame=[/url]
    true
    > >
    > > Either of these (which do essentially the same thing under the hood)
    will
    > > give you the same functionality as Basic authentication (a primary logon
    > > token).
    > >
    > > HTH,
    > >
    > > Joe K.
    > >
    > >
    > > "MS Newsgroups" <nospam@nospam.com> wrote in message
    > > news:%23XjD939jDHA.744@tk2msftngp13.phx.gbl...
    > > > Is there no way i can do this and get the same functionality as using
    > > Basic
    > > > authentication with the grey box (not sure how this works) since this
    > seem
    > > > to create a session identity automatically.
    > > >
    > > > Thanks for your help
    > > >
    > > > Niclas
    > > > "Joe Kaplan (MVP - ADSI)" <joseph.e.kaplan@removethis.accenture.com>
    > wrote
    > > > in message news:ePsARB1jDHA.2416@TK2MSFTNGP10.phx.gbl...
    > > > > If you want an actual WindowsIdentity object, you must have a logon
    > > token
    > > > > for the user, which means that you will need to call LogonUser with
    > the
    > > > > user's credentials.
    > > > >
    > > > > If you would be okay with a GenericIdentity/GenericPrincipal, then
    you
    > > can
    > > > > create one by authenticating to AD and building those objects
    > yourself.
    > > > > There is a sample on how to do this with System.DirectoryServices
    and
    > > > Forms
    > > > > authentication in the MS KB:
    > > > >
    > > > > [url]http://support.microsoft.com/default.aspx?scid=kb;en-us;326340[/url]
    > > > >
    > > > > That article has some flaws in it, but it is an okay starting point.
    > > Note
    > > > > that the recommended way of doing authentication is by using SSPI
    > > instead
    > > > of
    > > > > System.DirectoryServices with an LDAP bind, but I don't have a good
    > > > managed
    > > > > code wrapper example of SSPI. Maybe someone else does?
    > > > >
    > > > > The disadvantage with the GenericIdentity is that you can't
    > impersonate
    > > > with
    > > > > it, but it can be used to drive the security model in your
    application
    > > > using
    > > > > the standard IPrincipal interface.
    > > > >
    > > > > HTH,
    > > > >
    > > > > Joe K.
    > > > >
    > > > > "Niclas Lindblom" <lindblom_niclas@hotmail.com> wrote in message
    > > > > news:%23JDulu0jDHA.4008@TK2MSFTNGP11.phx.gbl...
    > > > > > Hi,
    > > > > >
    > > > > > I am trying to figure out a way to authenticate against Active
    > > Directory
    > > > > and
    > > > > > retrieve system.security.principal.WindowsIdentity object, without
    > > > having
    > > > > to
    > > > > > see the awful grey Basic Authentication logon box. I have found
    > > > > > documentation that you can send a authtentication request
    > > > programatically
    > > > > by
    > > > > > using the system.net.authenticationmanager.authenticate method,
    but
    > i
    > > > can
    > > > > > not get this to work and have not found any samples.
    > > > > >
    > > > > > Does anyone know a way to Authenticate against AD and have your
    > > browser
    > > > > > session retrieve a identity using forms ?
    > > > > >
    > > > > > regards
    > > > > >
    > > > > > Niclas
    > > > > >
    > > > > >
    > > > >
    > > >
    > > >
    > >
    >
    >
    Joe Kaplan \(MVP - ADSI\) Guest

  8. #7

    Default Re: get WindowsIdentity with forms authentication

    Hi,

    I've came to the same solution on my own but when I assign WindowsPrincipal
    to the User property of HttpContext it get's assigned for the current
    request but for the next request it's gone. User.Identity.Name becomes
    "Anonymous" again and IsAuthenticated is false. What should I do for this
    assignment to persist across requests?

    Best regards,
    Alan Mendelevich.

    "Joe Kaplan (MVP - ADSI)" <joseph.e.kaplan@removethis.accenture.com> wrote
    in message news:ei52RHUkDHA.3256@tk2msftngp13.phx.gbl...
    > The normal thing to do would be to create the WindowIdentity, then to
    create
    > a new WindowsPrincipal from that and set the User property on the
    > HttpContext equal to that. Then the WindowsPrincipal for the current user
    > will be associated with that request and all of the normal ASP.NET
    > role-based security will flow from there.
    >
    > Someone else may need to provide you with more details if that isn't
    enough
    > info as I am not a super expert in Forms authentication.
    >
    > Joe K.
    >
    > "Niclas Lindblom" <lindblom_niclas@hotmail.com> wrote in message
    > news:eR8P5uKkDHA.1656@tk2msftngp13.phx.gbl...
    > > Thanks Joe, I have actually looked at this option. What i haven't
    figured
    > > out yet is how to associate the current users session with the new
    > > WindowsIdentity object i have created. I have a feeling that i need to
    use
    > > impersonation, but haven't had time to test this yet.
    > >
    > > Am I one the right track, or do you know how to get this working ?
    > >
    > > Thanks for helping out
    > >
    > > Niclas
    > > "Joe Kaplan (MVP - ADSI)" <joseph.e.kaplan@removethis.accenture.com>
    wrote
    > > in message news:O1Va9FHkDHA.2424@TK2MSFTNGP10.phx.gbl...
    > > > It sounds like you want a WindowsIdentity/logon token for the user, so
    > you
    > > > will need to use an API that calls LogonUser. The easy way to do this
    > > would
    > > > be to build a Forms Auth. system that uses the new constructor on
    > > > WindowsIdentity in Framework 1.1 that takes a username and password.
    > Note
    > > > that the documentation says that you must be running Win2K3 for this
    > call
    > > to
    > > > work.
    > > >
    > > >
    > >
    >
    [url]http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/[/url]
    frlrfSystemSecurityPrincipalWindowsIdentityClassct orTopic5.asp?frame=true
    > > >
    > > > The other option is to P/Invoke LogonUser directly. You need very
    high
    > > > privileges to call this function under Windows 2000 though, so the
    > > viability
    > > > of this solution may depend on your platform and security needs.
    > > >
    > > >
    > >
    >
    [url]http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/[/url]
    frlrfSystemSecurityPrincipalWindowsImpersonationCo ntextClassTopic.asp?frame=
    > true
    > > >
    > > > Either of these (which do essentially the same thing under the hood)
    > will
    > > > give you the same functionality as Basic authentication (a primary
    logon
    > > > token).
    > > >
    > > > HTH,
    > > >
    > > > Joe K.
    > > >
    > > >
    > > > "MS Newsgroups" <nospam@nospam.com> wrote in message
    > > > news:%23XjD939jDHA.744@tk2msftngp13.phx.gbl...
    > > > > Is there no way i can do this and get the same functionality as
    using
    > > > Basic
    > > > > authentication with the grey box (not sure how this works) since
    this
    > > seem
    > > > > to create a session identity automatically.
    > > > >
    > > > > Thanks for your help
    > > > >
    > > > > Niclas
    > > > > "Joe Kaplan (MVP - ADSI)" <joseph.e.kaplan@removethis.accenture.com>
    > > wrote
    > > > > in message news:ePsARB1jDHA.2416@TK2MSFTNGP10.phx.gbl...
    > > > > > If you want an actual WindowsIdentity object, you must have a
    logon
    > > > token
    > > > > > for the user, which means that you will need to call LogonUser
    with
    > > the
    > > > > > user's credentials.
    > > > > >
    > > > > > If you would be okay with a GenericIdentity/GenericPrincipal, then
    > you
    > > > can
    > > > > > create one by authenticating to AD and building those objects
    > > yourself.
    > > > > > There is a sample on how to do this with System.DirectoryServices
    > and
    > > > > Forms
    > > > > > authentication in the MS KB:
    > > > > >
    > > > > > [url]http://support.microsoft.com/default.aspx?scid=kb;en-us;326340[/url]
    > > > > >
    > > > > > That article has some flaws in it, but it is an okay starting
    point.
    > > > Note
    > > > > > that the recommended way of doing authentication is by using SSPI
    > > > instead
    > > > > of
    > > > > > System.DirectoryServices with an LDAP bind, but I don't have a
    good
    > > > > managed
    > > > > > code wrapper example of SSPI. Maybe someone else does?
    > > > > >
    > > > > > The disadvantage with the GenericIdentity is that you can't
    > > impersonate
    > > > > with
    > > > > > it, but it can be used to drive the security model in your
    > application
    > > > > using
    > > > > > the standard IPrincipal interface.
    > > > > >
    > > > > > HTH,
    > > > > >
    > > > > > Joe K.
    > > > > >
    > > > > > "Niclas Lindblom" <lindblom_niclas@hotmail.com> wrote in message
    > > > > > news:%23JDulu0jDHA.4008@TK2MSFTNGP11.phx.gbl...
    > > > > > > Hi,
    > > > > > >
    > > > > > > I am trying to figure out a way to authenticate against Active
    > > > Directory
    > > > > > and
    > > > > > > retrieve system.security.principal.WindowsIdentity object,
    without
    > > > > having
    > > > > > to
    > > > > > > see the awful grey Basic Authentication logon box. I have found
    > > > > > > documentation that you can send a authtentication request
    > > > > programatically
    > > > > > by
    > > > > > > using the system.net.authenticationmanager.authenticate method,
    > but
    > > i
    > > > > can
    > > > > > > not get this to work and have not found any samples.
    > > > > > >
    > > > > > > Does anyone know a way to Authenticate against AD and have your
    > > > browser
    > > > > > > session retrieve a identity using forms ?
    > > > > > >
    > > > > > > regards
    > > > > > >
    > > > > > > Niclas
    > > > > > >
    > > > > > >
    > > > > >
    > > > >
    > > > >
    > > >
    > >
    > >
    >

    Alan Mendelevich Guest

  9. #8

    Default Re: get WindowsIdentity with forms authentication

    This is how i done it:

    Logon using API call to get a token, create a new WindowsIdentity Object and
    create a new Windows principal

    Add the principal to the session with

    session.add("AuthID", ctype(myNewPrincipal,object))

    Change userID for this call with:

    context.User = CType(Session.Item("AuthID"), WindowsPrincipal)

    Then i use global.asax to change the identity for every request

    Private Sub Global_PreRequestHandlerExecute(ByVal sender As Object, ByVal e
    As System.EventArgs) Handles MyBase.PreRequestHandlerExecute

    If Not Session.Item("AuthIdentity") Is Nothing Then
    Context.User = CType(Session.Item("AuthIdentity"),
    WindowsPrincipal)
    End If

    What i have also done, but not included here, is that i save the anonymous
    principal to the session before switching, so i can switch back if i would
    like the user to be able to perform a log off and continue as anonymous

    Any questions,

    Let me know

    Niclas Lindblom


    "Alan Mendelevich" <ng@ailon.org> wrote in message
    news:utdagljkDHA.3504@TK2MSFTNGP11.phx.gbl...
    > Hi,
    >
    > I've came to the same solution on my own but when I assign
    WindowsPrincipal
    > to the User property of HttpContext it get's assigned for the current
    > request but for the next request it's gone. User.Identity.Name becomes
    > "Anonymous" again and IsAuthenticated is false. What should I do for this
    > assignment to persist across requests?
    >
    > Best regards,
    > Alan Mendelevich.
    >
    > "Joe Kaplan (MVP - ADSI)" <joseph.e.kaplan@removethis.accenture.com> wrote
    > in message news:ei52RHUkDHA.3256@tk2msftngp13.phx.gbl...
    > > The normal thing to do would be to create the WindowIdentity, then to
    > create
    > > a new WindowsPrincipal from that and set the User property on the
    > > HttpContext equal to that. Then the WindowsPrincipal for the current
    user
    > > will be associated with that request and all of the normal ASP.NET
    > > role-based security will flow from there.
    > >
    > > Someone else may need to provide you with more details if that isn't
    > enough
    > > info as I am not a super expert in Forms authentication.
    > >
    > > Joe K.
    > >
    > > "Niclas Lindblom" <lindblom_niclas@hotmail.com> wrote in message
    > > news:eR8P5uKkDHA.1656@tk2msftngp13.phx.gbl...
    > > > Thanks Joe, I have actually looked at this option. What i haven't
    > figured
    > > > out yet is how to associate the current users session with the new
    > > > WindowsIdentity object i have created. I have a feeling that i need to
    > use
    > > > impersonation, but haven't had time to test this yet.
    > > >
    > > > Am I one the right track, or do you know how to get this working ?
    > > >
    > > > Thanks for helping out
    > > >
    > > > Niclas
    > > > "Joe Kaplan (MVP - ADSI)" <joseph.e.kaplan@removethis.accenture.com>
    > wrote
    > > > in message news:O1Va9FHkDHA.2424@TK2MSFTNGP10.phx.gbl...
    > > > > It sounds like you want a WindowsIdentity/logon token for the user,
    so
    > > you
    > > > > will need to use an API that calls LogonUser. The easy way to do
    this
    > > > would
    > > > > be to build a Forms Auth. system that uses the new constructor on
    > > > > WindowsIdentity in Framework 1.1 that takes a username and password.
    > > Note
    > > > > that the documentation says that you must be running Win2K3 for this
    > > call
    > > > to
    > > > > work.
    > > > >
    > > > >
    > > >
    > >
    >
    [url]http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/[/url]
    > frlrfSystemSecurityPrincipalWindowsIdentityClassct orTopic5.asp?frame=true
    > > > >
    > > > > The other option is to P/Invoke LogonUser directly. You need very
    > high
    > > > > privileges to call this function under Windows 2000 though, so the
    > > > viability
    > > > > of this solution may depend on your platform and security needs.
    > > > >
    > > > >
    > > >
    > >
    >
    [url]http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/[/url]
    >
    frlrfSystemSecurityPrincipalWindowsImpersonationCo ntextClassTopic.asp?frame=
    > > true
    > > > >
    > > > > Either of these (which do essentially the same thing under the hood)
    > > will
    > > > > give you the same functionality as Basic authentication (a primary
    > logon
    > > > > token).
    > > > >
    > > > > HTH,
    > > > >
    > > > > Joe K.
    > > > >
    > > > >
    > > > > "MS Newsgroups" <nospam@nospam.com> wrote in message
    > > > > news:%23XjD939jDHA.744@tk2msftngp13.phx.gbl...
    > > > > > Is there no way i can do this and get the same functionality as
    > using
    > > > > Basic
    > > > > > authentication with the grey box (not sure how this works) since
    > this
    > > > seem
    > > > > > to create a session identity automatically.
    > > > > >
    > > > > > Thanks for your help
    > > > > >
    > > > > > Niclas
    > > > > > "Joe Kaplan (MVP - ADSI)"
    <joseph.e.kaplan@removethis.accenture.com>
    > > > wrote
    > > > > > in message news:ePsARB1jDHA.2416@TK2MSFTNGP10.phx.gbl...
    > > > > > > If you want an actual WindowsIdentity object, you must have a
    > logon
    > > > > token
    > > > > > > for the user, which means that you will need to call LogonUser
    > with
    > > > the
    > > > > > > user's credentials.
    > > > > > >
    > > > > > > If you would be okay with a GenericIdentity/GenericPrincipal,
    then
    > > you
    > > > > can
    > > > > > > create one by authenticating to AD and building those objects
    > > > yourself.
    > > > > > > There is a sample on how to do this with
    System.DirectoryServices
    > > and
    > > > > > Forms
    > > > > > > authentication in the MS KB:
    > > > > > >
    > > > > > > [url]http://support.microsoft.com/default.aspx?scid=kb;en-us;326340[/url]
    > > > > > >
    > > > > > > That article has some flaws in it, but it is an okay starting
    > point.
    > > > > Note
    > > > > > > that the recommended way of doing authentication is by using
    SSPI
    > > > > instead
    > > > > > of
    > > > > > > System.DirectoryServices with an LDAP bind, but I don't have a
    > good
    > > > > > managed
    > > > > > > code wrapper example of SSPI. Maybe someone else does?
    > > > > > >
    > > > > > > The disadvantage with the GenericIdentity is that you can't
    > > > impersonate
    > > > > > with
    > > > > > > it, but it can be used to drive the security model in your
    > > application
    > > > > > using
    > > > > > > the standard IPrincipal interface.
    > > > > > >
    > > > > > > HTH,
    > > > > > >
    > > > > > > Joe K.
    > > > > > >
    > > > > > > "Niclas Lindblom" <lindblom_niclas@hotmail.com> wrote in message
    > > > > > > news:%23JDulu0jDHA.4008@TK2MSFTNGP11.phx.gbl...
    > > > > > > > Hi,
    > > > > > > >
    > > > > > > > I am trying to figure out a way to authenticate against Active
    > > > > Directory
    > > > > > > and
    > > > > > > > retrieve system.security.principal.WindowsIdentity object,
    > without
    > > > > > having
    > > > > > > to
    > > > > > > > see the awful grey Basic Authentication logon box. I have
    found
    > > > > > > > documentation that you can send a authtentication request
    > > > > > programatically
    > > > > > > by
    > > > > > > > using the system.net.authenticationmanager.authenticate
    method,
    > > but
    > > > i
    > > > > > can
    > > > > > > > not get this to work and have not found any samples.
    > > > > > > >
    > > > > > > > Does anyone know a way to Authenticate against AD and have
    your
    > > > > browser
    > > > > > > > session retrieve a identity using forms ?
    > > > > > > >
    > > > > > > > regards
    > > > > > > >
    > > > > > > > Niclas
    > > > > > > >
    > > > > > > >
    > > > > > >
    > > > > >
    > > > > >
    > > > >
    > > >
    > > >
    > >
    >
    >

    MS Newsgroups 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