User Authentication, Active Directory and more (help)

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

  1. #1

    Default User Authentication, Active Directory and more (help)

    Hi,

    Can a .NET application make use of the information within the Active
    Directory in order to Authenticate and Authorize users?

    For example users from a specific group have been authorize to use a
    number of features in the application while users from another group
    have not.

    I know there is something called Code Access Security, but there seem to
    be classes for the Active Directory Services and classes for something
    called Windows Principle.

    I wonder if someone could get me started with this.

    Another thing is, can devices running the Compact Framework
    be authenticated and authorized in the same way (since they don't have a
    user logged on) Can they be a valid member of a domain ?


    Thnx.
    Timothy Parez Guest

  2. Similar Questions and Discussions

    1. Windows Authentication with Asp.net and against Active Directory
      How can i use Windows authentication in IIS against AD. How will i create a WindowsPrincipal object(with asp.net) in the Context.User property...
    2. Authentication against active directory
      Hello I am developing a ASP.NET site (using VB). I found some code that allows me to authenticate the user trying to access the site against the...
    3. Forms Authentication with Active Directory using vb.net
      I have seen many examples of form authentication using c#. Can someone point me to a sample using vb.net. I would like to use WinNT://domain,...
    4. Active Directory Authentication in ASP
      I have been attempting to find a script that works in a variety of AD implementations to authenticate a user from a form in ASP. After many failed...
    5. Authentication on Active Directory
      How do I autheticate using a <FORM> and C# on Active Directory? Thanks in advance
  3. #2

    Default Re: User Authentication, Active Directory and more (help)

    Yes, .NET can make use of any Windows account (local machine, NT4 domain or
    AD) for authentication and authorization.

    The built-in support for this is in the WindowsIdentity and WindowsPrincipal
    classes. WindowsIdentity represents the Windows user and is basicallly a
    wrapper around the Windows login token. WindowsPrincipal contains a
    WindowsIdentity and provides the ability to do role-based authorization
    against a user's Windows groups by calling the IsInRole method with the
    Windows group name. You can get the current WindowsIdentity at any time by
    calling WindowsIdentity.GetCurrent().

    The WindowsPrincipal class can be associated automatically with the
    currently executing thread as well. The mechanism for doing this is
    different depending on whether it is an ASP.NET or WinForms/Console app.
    This association allows you to take advantage of the
    PrincipalPermissionAttribute for doing declarative security in .NET. There
    is quite a bit of explanation of this stuff that you can find in MSDN if you
    need specifics, or you can ask here.

    Joe K.

    "Timothy Parez" <tpsoftware@users.sourceforge.net> wrote in message
    news:X6CdnTDpUNfLs0zdRVn-jA@scarlet.biz...
    > Hi,
    >
    > Can a .NET application make use of the information within the Active
    > Directory in order to Authenticate and Authorize users?
    >
    > For example users from a specific group have been authorize to use a
    > number of features in the application while users from another group
    > have not.
    >
    > I know there is something called Code Access Security, but there seem to
    > be classes for the Active Directory Services and classes for something
    > called Windows Principle.
    >
    > I wonder if someone could get me started with this.
    >
    > Another thing is, can devices running the Compact Framework
    > be authenticated and authorized in the same way (since they don't have a
    > user logged on) Can they be a valid member of a domain ?
    >
    >
    > Thnx.

    Joe Kaplan \(MVP - ADSI\) Guest

  4. #3

    Default Re: User Authentication, Active Directory and more (help)

    Joe Kaplan (MVP - ADSI) wrote:
    > Yes, .NET can make use of any Windows account (local machine, NT4 domain or
    > AD) for authentication and authorization.
    >
    > The built-in support for this is in the WindowsIdentity and WindowsPrincipal
    > classes. WindowsIdentity represents the Windows user and is basicallly a
    > wrapper around the Windows login token. WindowsPrincipal contains a
    > WindowsIdentity and provides the ability to do role-based authorization
    > against a user's Windows groups by calling the IsInRole method with the
    > Windows group name. You can get the current WindowsIdentity at any time by
    > calling WindowsIdentity.GetCurrent().
    >
    > The WindowsPrincipal class can be associated automatically with the
    > currently executing thread as well. The mechanism for doing this is
    > different depending on whether it is an ASP.NET or WinForms/Console app.
    > This association allows you to take advantage of the
    > PrincipalPermissionAttribute for doing declarative security in .NET. There
    > is quite a bit of explanation of this stuff that you can find in MSDN if you
    > need specifics, or you can ask here.
    >
    > Joe K.
    >
    What about the PocketPC,
    how would I fit it into this scenario
    because the PocketPC's will be used to scan barcodes and insert items
    into the database (with that barcode as the key)
    Timothy Parez Guest

  5. #4

    Default Re: User Authentication, Active Directory and more (help)

    Ah, forgot that part. I'm not a CF programmer, so I don't know the details,
    but the Framework reference doesn't say WindowsIdentity is supported on CF,
    so you may be SOL. My guess is that PocketPC doesn't support Windows
    security (you don't log onto the domain on one of those, do you?), so that's
    why it is excluded.

    I'm not sure what to tell you to do on Pocket PC, sorry. It doesn't even
    look like any of the classes in System.Security.Principal are in the CF, so
    you may have to roll your own.

    Joe K.

    "Timothy Parez" <tpsoftware@users.sourceforge.net> wrote in message
    news:40D1D8AC.2070500@users.sourceforge.net...
    > Joe Kaplan (MVP - ADSI) wrote:
    > > Yes, .NET can make use of any Windows account (local machine, NT4 domain
    or
    > > AD) for authentication and authorization.
    > >
    > > The built-in support for this is in the WindowsIdentity and
    WindowsPrincipal
    > > classes. WindowsIdentity represents the Windows user and is basicallly
    a
    > > wrapper around the Windows login token. WindowsPrincipal contains a
    > > WindowsIdentity and provides the ability to do role-based authorization
    > > against a user's Windows groups by calling the IsInRole method with the
    > > Windows group name. You can get the current WindowsIdentity at any time
    by
    > > calling WindowsIdentity.GetCurrent().
    > >
    > > The WindowsPrincipal class can be associated automatically with the
    > > currently executing thread as well. The mechanism for doing this is
    > > different depending on whether it is an ASP.NET or WinForms/Console app.
    > > This association allows you to take advantage of the
    > > PrincipalPermissionAttribute for doing declarative security in .NET.
    There
    > > is quite a bit of explanation of this stuff that you can find in MSDN if
    you
    > > need specifics, or you can ask here.
    > >
    > > Joe K.
    > >
    >
    > What about the PocketPC,
    > how would I fit it into this scenario
    > because the PocketPC's will be used to scan barcodes and insert items
    > into the database (with that barcode as the key)

    Joe Kaplan \(MVP - ADSI\) Guest

  6. #5

    Default Re: User Authentication, Active Directory and more (help)

    Would the following be possible:

    On the Server I could have an XML WebService which takes a windows
    username and password as parameters for a "login" function.
    Can this be done ?

    Thnx
    (Sorry for the endless questions)


    Joe Kaplan (MVP - ADSI) wrote:
    > Ah, forgot that part. I'm not a CF programmer, so I don't know the details,
    > but the Framework reference doesn't say WindowsIdentity is supported on CF,
    > so you may be SOL. My guess is that PocketPC doesn't support Windows
    > security (you don't log onto the domain on one of those, do you?), so that's
    > why it is excluded.
    >
    > I'm not sure what to tell you to do on Pocket PC, sorry. It doesn't even
    > look like any of the classes in System.Security.Principal are in the CF, so
    > you may have to roll your own.
    >
    > Joe K.
    >
    > "Timothy Parez" <tpsoftware@users.sourceforge.net> wrote in message
    > news:40D1D8AC.2070500@users.sourceforge.net...
    >
    >>Joe Kaplan (MVP - ADSI) wrote:
    >>
    >>>Yes, .NET can make use of any Windows account (local machine, NT4 domain
    >
    > or
    >
    >>>AD) for authentication and authorization.
    >>>
    >>>The built-in support for this is in the WindowsIdentity and
    >
    > WindowsPrincipal
    >
    >>>classes. WindowsIdentity represents the Windows user and is basicallly
    >
    > a
    >
    >>>wrapper around the Windows login token. WindowsPrincipal contains a
    >>>WindowsIdentity and provides the ability to do role-based authorization
    >>>against a user's Windows groups by calling the IsInRole method with the
    >>>Windows group name. You can get the current WindowsIdentity at any time
    >
    > by
    >
    >>>calling WindowsIdentity.GetCurrent().
    >>>
    >>>The WindowsPrincipal class can be associated automatically with the
    >>>currently executing thread as well. The mechanism for doing this is
    >>>different depending on whether it is an ASP.NET or WinForms/Console app.
    >>>This association allows you to take advantage of the
    >>>PrincipalPermissionAttribute for doing declarative security in .NET.
    >
    > There
    >
    >>>is quite a bit of explanation of this stuff that you can find in MSDN if
    >
    > you
    >
    >>>need specifics, or you can ask here.
    >>>
    >>>Joe K.
    >>>
    >>
    >>What about the PocketPC,
    >>how would I fit it into this scenario
    >>because the PocketPC's will be used to scan barcodes and insert items
    >>into the database (with that barcode as the key)
    >
    >
    >
    Timothy Parez Guest

  7. #6

    Default Re: User Authentication, Active Directory and more (help)

    Sure, you could do that and return some sort of cookie/token that could be
    passesd in subsequent messages. You might want to check out how ASP.NET
    forms authentication works as it does really similar stuff and they have
    already thought through a lot of the security issues.

    To validate the credentials on the server side, you could use
    System.DirectoryServices to validate via LDAP or use the LogonUser API to
    actually try to log the user on to Windows. It depends on what you need to
    do, but either might be appropriate solutions.

    Another nice thing is that the role-based authorization framework IS
    available in regular Windows, so you can do role-based authorization in your
    Web Services.

    Without knowing more about your application architecture, it is hard to make
    really good suggestions about how you should proceed, but hopefully this is
    still helpful.

    Joe K.


    "Timothy Parez" <tpsoftware@users.sourceforge.net> wrote in message
    news:C_mdndIxROF64U_dRVn-sA@scarlet.biz...
    > Would the following be possible:
    >
    > On the Server I could have an XML WebService which takes a windows
    > username and password as parameters for a "login" function.
    > Can this be done ?
    >
    > Thnx
    > (Sorry for the endless questions)
    >
    >
    > Joe Kaplan (MVP - ADSI) wrote:
    > > Ah, forgot that part. I'm not a CF programmer, so I don't know the
    details,
    > > but the Framework reference doesn't say WindowsIdentity is supported on
    CF,
    > > so you may be SOL. My guess is that PocketPC doesn't support Windows
    > > security (you don't log onto the domain on one of those, do you?), so
    that's
    > > why it is excluded.
    > >
    > > I'm not sure what to tell you to do on Pocket PC, sorry. It doesn't
    even
    > > look like any of the classes in System.Security.Principal are in the CF,
    so
    > > you may have to roll your own.
    > >
    > > Joe K.
    > >
    > > "Timothy Parez" <tpsoftware@users.sourceforge.net> wrote in message
    > > news:40D1D8AC.2070500@users.sourceforge.net...
    > >
    > >>Joe Kaplan (MVP - ADSI) wrote:
    > >>
    > >>>Yes, .NET can make use of any Windows account (local machine, NT4
    domain
    > >
    > > or
    > >
    > >>>AD) for authentication and authorization.
    > >>>
    > >>>The built-in support for this is in the WindowsIdentity and
    > >
    > > WindowsPrincipal
    > >
    > >>>classes. WindowsIdentity represents the Windows user and is basicallly
    > >
    > > a
    > >
    > >>>wrapper around the Windows login token. WindowsPrincipal contains a
    > >>>WindowsIdentity and provides the ability to do role-based authorization
    > >>>against a user's Windows groups by calling the IsInRole method with the
    > >>>Windows group name. You can get the current WindowsIdentity at any
    time
    > >
    > > by
    > >
    > >>>calling WindowsIdentity.GetCurrent().
    > >>>
    > >>>The WindowsPrincipal class can be associated automatically with the
    > >>>currently executing thread as well. The mechanism for doing this is
    > >>>different depending on whether it is an ASP.NET or WinForms/Console
    app.
    > >>>This association allows you to take advantage of the
    > >>>PrincipalPermissionAttribute for doing declarative security in .NET.
    > >
    > > There
    > >
    > >>>is quite a bit of explanation of this stuff that you can find in MSDN
    if
    > >
    > > you
    > >
    > >>>need specifics, or you can ask here.
    > >>>
    > >>>Joe K.
    > >>>
    > >>
    > >>What about the PocketPC,
    > >>how would I fit it into this scenario
    > >>because the PocketPC's will be used to scan barcodes and insert items
    > >>into the database (with that barcode as the key)
    > >
    > >
    > >

    Joe Kaplan \(MVP - ADSI\) Guest

  8. #7

    Default Re: User Authentication, Active Directory and more (help)

    Hey,

    Thnx for all the information.

    I would like to ask you for some more help :)

    I tried using the following in my web.config file but it doesn't really work

    <system.web>
    <authentication mode="Windows"/>
    <authorization>
    <allow roles="Admins" />
    <deny users="*" />
    </authorization>
    </system.web>

    I have also played with these values, but either I get a logon screen
    but I can never logon, or I don't get a logon screen and get a page that
    I'm not authorized to view that page right away.

    In any case I don't think this will be the best option for me.

    Using the DirectoryServices namespace, can I take a username and
    password and validate it against the AD from my code

    ie. is there something like (I know seems stupid but I must ask)

    if (User.Authenticate("username","password"))
    {
    MessageBox.Show("Welcome");
    }
    else
    {
    MessageBox.Show("Try again m8");
    }

    This would be a lot better than the logon provided by ASP.NET (more
    compatible and usable in code)

    Thnx for you help.

    Timothy.
    Timothy Parez Guest

  9. #8

    Default Re: User Authentication, Active Directory and more (help)

    When you are using Windows authentication in IIS and ASP.NET, the roles in
    the IPrincipal that gets created will be Windows groups, so they will be of
    the form Domain\Group Name.

    I order to make sure you are using Windows authentication in IIS, you must
    disable anonymous access and enable Basic, Digest or Integrated
    authentication. Don't use Basic without SSL or you will be passing
    credentials in plain text over the network. In ASP.NET, you need to make
    sure the authentication tag in web.config is set to Windows (which is the
    default).

    In order to authenticate users in Active Directory, the IIS server must be a
    member of the Active Directory domain.

    If you want to build your own authentication scheme using
    System.DirectoryServices or something, then you will also be responsible for
    building the IPrincipal object that contains the user's roles. This sample
    of Forms authentication with System.DirectoryServices is an okay starting
    point.

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

    HTH,

    Joe K.

    "Timothy Parez" <tpsoftware@users.sourceforge.net> wrote in message
    news:40D67AC6.7030502@users.sourceforge.net...
    > Hey,
    >
    > Thnx for all the information.
    >
    > I would like to ask you for some more help :)
    >
    > I tried using the following in my web.config file but it doesn't really
    work
    >
    > <system.web>
    > <authentication mode="Windows"/>
    > <authorization>
    > <allow roles="Admins" />
    > <deny users="*" />
    > </authorization>
    > </system.web>
    >
    > I have also played with these values, but either I get a logon screen
    > but I can never logon, or I don't get a logon screen and get a page that
    > I'm not authorized to view that page right away.
    >
    > In any case I don't think this will be the best option for me.
    >
    > Using the DirectoryServices namespace, can I take a username and
    > password and validate it against the AD from my code
    >
    > ie. is there something like (I know seems stupid but I must ask)
    >
    > if (User.Authenticate("username","password"))
    > {
    > MessageBox.Show("Welcome");
    > }
    > else
    > {
    > MessageBox.Show("Try again m8");
    > }
    >
    > This would be a lot better than the logon provided by ASP.NET (more
    > compatible and usable in code)
    >
    > Thnx for you help.
    >
    > Timothy.

    Joe Kaplan \(MVP - ADSI\) Guest

  10. #9

    Default Re: User Authentication, Active Directory and more (help)

    Joe Kaplan (MVP - ADSI) wrote:
    > When you are using Windows authentication in IIS and ASP.NET, the roles in
    > the IPrincipal that gets created will be Windows groups, so they will be of
    > the form Domain\Group Name.
    >
    > I order to make sure you are using Windows authentication in IIS, you must
    > disable anonymous access and enable Basic, Digest or Integrated
    > authentication. Don't use Basic without SSL or you will be passing
    > credentials in plain text over the network. In ASP.NET, you need to make
    > sure the authentication tag in web.config is set to Windows (which is the
    > default).
    >
    > In order to authenticate users in Active Directory, the IIS server must be a
    > member of the Active Directory domain.
    >
    > If you want to build your own authentication scheme using
    > System.DirectoryServices or something, then you will also be responsible for
    > building the IPrincipal object that contains the user's roles. This sample
    > of Forms authentication with System.DirectoryServices is an okay starting
    > point.
    >
    > [url]http://support.microsoft.com/default.aspx?scid=kb;en-us;326340[/url]
    >
    > HTH,
    >
    > Joe K.
    >
    > "Timothy Parez" <tpsoftware@users.sourceforge.net> wrote in message
    > news:40D67AC6.7030502@users.sourceforge.net...
    >
    >>Hey,
    >>
    >>Thnx for all the information.
    >>
    >>I would like to ask you for some more help :)
    >>
    >>I tried using the following in my web.config file but it doesn't really
    >
    > work
    >
    >><system.web>
    >> <authentication mode="Windows"/>
    >> <authorization>
    >> <allow roles="Admins" />
    >> <deny users="*" />
    >> </authorization>
    >></system.web>
    >>
    >>I have also played with these values, but either I get a logon screen
    >>but I can never logon, or I don't get a logon screen and get a page that
    >>I'm not authorized to view that page right away.
    >>
    >>In any case I don't think this will be the best option for me.
    >>
    >>Using the DirectoryServices namespace, can I take a username and
    >>password and validate it against the AD from my code
    >>
    >>ie. is there something like (I know seems stupid but I must ask)
    >>
    >>if (User.Authenticate("username","password"))
    >>{
    >>MessageBox.Show("Welcome");
    >>}
    >>else
    >>{
    >>MessageBox.Show("Try again m8");
    >>}
    >>
    >>This would be a lot better than the logon provided by ASP.NET (more
    >>compatible and usable in code)
    >>
    >>Thnx for you help.
    >>
    >>Timothy.
    >
    >
    >
    Hey,

    I've got that working now
    and I now am able to get the name from User.Identity in my ASP.NET page
    but methods like IsInRole() seem to have no effect on it.

    Any suggestions?
    Timothy Parez Guest

  11. #10

    Default Re: User Authentication, Active Directory and more (help)

    How are you testing the IsInRole method? With Windows/Domain logins, the
    groups you use must be in the form "domain\group name".

    Joe K.
    >
    > Hey,
    >
    > I've got that working now
    > and I now am able to get the name from User.Identity in my ASP.NET page
    > but methods like IsInRole() seem to have no effect on it.
    >
    > Any suggestions?

    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