Team LiB
Previous Section Next Section

Authorization

SQL Server provides a number of role-based approaches for authorization. These revolve around the following thee types of roles supported by SQL Server:

For more information about these various role types (and also fixed server roles which are similar to fixed database roles but apply at the server level instead of the database level), see SQL Server Books Online (http://www.microsoft.com/sql/techinfo /productdoc/2000/books.asp).

Using Multiple Database Roles

If your application has multiple categories of users, and the users within each category require the same permissions within the database, your application requires multiple roles. Each role requires a different set of permissions within the database. For example, members of an Internet User role may require read-only permissions to the majority of tables within a database, while members of an Administrator or Operator role may require read/write permissions.

In this scenario, you can use multiple user-defined SQL Server database roles. These are used to assign permissions to database objects for the groups of users who share the same permissions in the database. With this approach, you must:

  • Create multiple service accounts to use for database access.

  • Create a SQL Server login for each account.

  • Create database users to grant the login access to the database.

  • Add each database user to a user-defined database role.

  • Establish the necessary database permissions for each role within the database.

  • Authorize users within your application (ASP.NET Web application, Web service, or middle tier component) and then use application logic within your data access layer to determine which account to connect to the database with. This is based on the role-membership of the caller.

    Declaratively, you can configure individual methods to allow only those users that belong to a set of roles. You then add imperative role-checks within method code to determine precise role membership, which determines the connection to use.

Figure 12.4 illustrates this approach.

Click To expand
Figure 12.4: Connecting to SQL Server using multiple SQL user database roles

To use the preferred Windows authentication for this scenario, you develop code (using the LogonUser API) in an out of process serviced component to impersonate one of a set of Windows identities.

With SQL authentication, you use a different connection string (containing different user names and passwords) depending upon role-based logic within your application.


Team LiB
Previous Section Next Section