1 / 26

ASP.NET Authentication

ASP.NET Authentication.

feleti
Download Presentation

ASP.NET Authentication

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. ASP.NET Authentication

  2. Authentication is the process of obtaining identification credentials such as name and password from a user and validating those credentials against some authority. If the credentials are valid, the entity that submitted the credentials is considered an authenticated identity. Once an identity has been authenticated, the authorization process determines whether that identity has access to a given resource. ASP.NET implements additional authentication schemes using authentication providers, which are separate from and apply only after the IIS authentication schemes. ASP.NET supports the following authentication providers: Windows (default) Forms Passport None ASP.NET Authentication

  3. Authentication systems • To enable an authentication provider for an ASP.NET application, you only need to create an entry for the application configuration file as follows. // Web.config file <authentication mode= "[Windows|Forms|Passport|None]"/>

  4. Windows authentication provider • The Windows authentication provider relies upon IIS to perform the required authentication of a client. After IIS authenticates a client, it passes a security token to ASP.NET. ASP.NET constructs and attaches an object of the WindowsPrincipal Class to the application context based on the security token it receives from IIS. • Pro • Authenticates using Windows accounts, so you do not need to write any custom authentication code. • Con • May require the use and management of individual Windows user accounts.

  5. Passport authentication provider • The Passport authentication provider is a centralized authentication service provided by Microsoft that offers a single logon and core profile services for member sites. Passport is a forms-based authentication service. When member sites register with Passport, the Passport service grants a site-specific key. The Passport logon server uses this key to encrypt and decrypt the query strings passed between the member site and the Passport logon server. • Pros • Supports single sign-in across multiple domains. • Compatible with all browsers. • Con • Places an external dependency for the authentication process.

  6. None (Custom Authentication) • Specify "None" as the authentication provider when users are not authenticated at all or if you plan to develop custom authentication code. For example, you may want to develop your own authentication scheme using an ISAPI filter that authenticates users and manually creates an object of the GenericPrincipal Class. • Pros • Offers total control of the authentication process providing the greatest flexibility. • Provides the highest performance if you do not implement an authentication method. • Cons • Custom-built authentication schemes are seldom as secure as those provided by the operating system. • Requires extra work to custom-build an authentication scheme.

  7. Forms authentication provider • The Forms authentication provider is an authentication scheme that makes it possible for the application to collect credentials using an HTML form directly from the client. The client submits credentials directly to your application code for authentication. If your application authenticates the client, it issues a cookie to the client that the client presents on subsequent requests. If a request for a protected resource does not contain the cookie, the application redirects the client to the logon page. When authenticating credentials, the application can store credentials in a number of ways, such as a configuration file or a SQL Server database.

  8. The forms authentication process

  9. Why use forms authentication? • Cookie authentication is an attractive option for developers for a number of reasons: • You have full control over the authentication code. • You have full control over the appearance of the login form. • It works with any browser. • It allows you to decide how to store user information.

  10. Implementing forms authentication • Basically, you need to complete the following steps to use forms authentication in your application: • Configure forms authentication in the web.config file. • Configure IIS to allow anonymous access to the virtual directory and configure ASP.NET to restrict anonymous access to the web application. • Create a custom login page that collects and validates a user name and password and then interacts with the forms authentication infrastructure for creating the ticket.

  11. Complete set of options in configure forms authentication • <authentication mode="Forms"> • <!-- Detailed configuration options --> • <forms name=“.ASPXAUTH" • loginUrl=“login.aspx" • timeout=“30" • slidingExpiration=“false" • cookieless=“AutoDetect" • protection="All" • requireSSL="false" • enableCrossAppRedirects="false" • defaultUrl="Default.aspx" • domain=“www.mydomain.com" • path="/" /> • </authentication>

  12. Credentials store in web.config • <authentication mode="Forms"> • <!-- Detailed configuration options --> • <forms name="MyCookieName" • loginUrl="MyLogin.aspx" timeout="20"> <credentials passwordFormat="Clear"> • <user name="Admin" password="(Admin)"/> • <user name="Mario" password="Szpuszta"/> • <user name="Matthew" password="MacDonald"/> </credentials> • </forms> • </authentication>

  13. IIS and ASP.NET

  14. FormsAuthentication-Module • The most important part of the forms authentication framework is the FormsAuthentication-Module, which is an HttpModule class that detects existing forms authentication tickets in the request.

  15. The forms authentication classes • System.Web.Security.FormsAuthentication • System.Web.Security.FormsAuthenticationEventArgs • System.Web.Security.FormsAuthenticationTicket • System.Web.Security.FormsIdentity • System.Web.Security.FormsAuthenticationModule

  16. Authorization • After authenticating a principal, the next step is to determine whether that principal has permission to access the resources it is requesting. This process is known as authorization. ASP.NET works in conjunction with its primary host environment, Internet Information Services (IIS), to provide authentication and authorization services to applications. • There are several schemes to determine if an authenticated principal has authorization to access a particular resource. The security of an ASP.NET application is built upon the security infrastructure of IIS and Windows. Any communication between client and application must first pass through IIS and any process that runs on a Windows server does so in the context of an authenticated user account. When using the NTFS file system, Windows maintains an access control list (ACL) for every resource it controls, which serves as the ultimate authority for resource access permissions.

  17. Items control authorization • The following items control authorization in an ASP.NET application: • Windows Access Control Lists (ACLs) • Web Server Permissions • URL Authorization • .NET Principal Objects • Roles and Method-Level Security

  18. ACLs and Web Server Permissions • Windows Access Control Lists • Using Windows ACLs, you can create file system permissions on specific application files. This solution works best if your application is authenticating users to Windows accounts. To use Windows ACLs, you must use the Windows NTFS file system. • Web Server Permissions • You can configure IIS to specify the following permissions on Web site directories, such as read access and directory browsing.

  19. URL Authorization • URL Authorization • The UrlAuthorizationModule Class maps users and roles to elements within the URI namespace, which is defined by a URL. This module implements both positive and negative authorization assertions. The module can either be used to selectively permit or deny specific users access to arbitrary elements of the URI namespace. For example, you can base access on user role membership. • <configuration> • <system.web> • <authentication mode="Windows" /> • <authorization> • <allow users="domain1\user, domain2\user2, domain1\user3" /> • <deny users="*" /> • </authorization> • </system.web> • </configuration>

  20. .NET Principal Objects • WindowsPrincipal Object • The System.Security.Principal Namespace provides a WindowsPrincipal Class to represent the security context under which the code is running. This object is automatically created for you when you use Windows authentication in IIS. It allows you to check the Windows group membership of a Windows user account and restrict access accordingly. • GenericPrincipal Object • You can create an object from the GenericPrincipal Class based on your own custom roles. Use this when you have your own user/role database. You can populate the principal object in the OnAuthenticate event. You can have a custom table mapped to Windows accounts that you access in this event. Using that information, you can create a custom principal object for the authenticated user. For returning authenticated users, you can use a cookie to recreate the principal object.

  21. Roles and Method-Level Security • Roles and Method-Level Security • If you are using Windows accounts, create roles for your users by creating Windows groups. Because the processing thread is impersonating the client and a WindowsPrincipal object is available, use the following approaches: • Create NTFS ACLs on protected resources accessed by the ASP.NET thread. • Call the WindowsPrincipal.IsInRole method from each method to verify the caller has the appropriate permissions. You can also implement a logic statement in code that calls a particular subroutine based on the client's group membership. • If you are using a GenericPrincipal object created from users and roles contained in a custom database: • You can programmatically check role membership by calling the GenericPrincipal.IsInRole method in the same fashion as with the WindowsPrincipal object.

  22. Roles and Method-Level Security • If you are not using a principal object, you have other options: • The role-based security model supports a permission object similar to the permission objects found in the code access security model. This object, PrincipalPermission, represents the identity and role that a particular principal class must have to run. You can use the PrincipalPermission class for both imperative and declarative security checks. • Accept user credentials as parameters to the method call and perform a look-up within the method. • Verify the existence of a cookie as the first operation of the method call. • Create a logon method that returns a custom key value. Subsequent methods accept the key value as a parameter. This is similar to using browser-supported cookies; however, you can use it in cases where the client does not support cookies.

  23. ASP.NET Impersonation • Another important security feature is the ability to control the identity under which code is executed. Impersonation is when ASP.NET executes code in the context of an authenticated and authorized client. By default, ASP.NET does not use impersonation and instead executes all code using the same user account as the ASP.NET process, which is typically the ASPNET account. This is contrary to the default behavior of ASP, which uses impersonation by default. In Internet Information Services (IIS) 6, the default identity is the NetworkService account.

  24. Impersonation options • If you enable impersonation, ASP.NET can either impersonate the authenticated identity received from IIS or one specified in the application's Web.config file. You have the following three options when configuring impersonation: • Impersonation is disabled. • <identity impersonate="false" /> • Impersonation enabled. • <identity impersonate="true"/> • Impersonation enabled, with a specific impersonation identity specified. • <identity impersonate="true" userName="domain\user" password="password" />

  25. Attention!!! • You should exercise care when using impersonation because it makes it possible for an application to potentially process code using permissions not anticipated by the application designer. For example, if your application impersonates an authenticated intranet user, that application possesses administrative privileges when impersonating a user with those privileges. Likewise, if the impersonated user possesses more restrictive permissions than anticipated, the user may not be able to use the application.

  26. For more information, please contact: Uladzimir Tsikhon Software Engineering Manager, Belarus Recourse Development Department EPAM Systems, Inc. Belarus, MinskPhone: +375(17) 2101662 ext 1756 Fax: +375(17) 2101168 Email: uladzimir_tsikhon@epam.com http://www.epam.com

More Related