|
CHAPTER 21
Permission Checker Component |
| One of the benefits of using Microsofts Internet Information Server is its close connection to Windows NT and its security model. The Permission Checker component allows you to utilize this connection to determine whether a user on your web site has permission to view a given file stored on an NTFS volume. This allows you to customize your sites pages according to the permissions granted a given user. For example, you could use the Permission Checker component to check whether a user has access to a certain downloadable file before creating a link to the file. This way, if the user does not have access to the file, she does not even see the link to it. Conceivably, you could use this strategy to prevent unauthorized users from ever seeing any indication that files to which they do not have access exist. There are two requirements for using the Permission Checker component. The first is that your site must be running on Windows NT (Personal Web Server for Windows 95/98 will not work). Second, your web site must not rely exclusively on anonymous connections and the (low-level) security such an access method provides. You must have either Basic Clear Text or Windows NT Challenge Response authentication selected as a security option for your web site. These authentication methods provide the Permission Checker object with a security context in which to test for various permissions. If you do not have Basic or NT Challenge Response, the Permission Checker is unable to distinguish between one anonymous user and another. Note that this chapter documents the Permission Checker component 2.0 (Beta 3) that can be downloaded from Microsofts web site. Instantiating the Permission Checker 359 Permission Checker Instantiating the Permission Checker ASP in a Nutshell: A Desktop Quick Reference, eMatter Edition Copyright © 2000 OReilly & Associates, Inc. All rights reserved. Accessory Files/Required DLL Files permchk.dll The dynamic link library for the Permission Checker component. This DLL comes with the IIS installation media but is not installed by default. You must register this DLL by hand before you can use it. Instantiating the Permission Checker To create an object variable containing an instance of a Permission Checker object, use the Server objects CreateObject method. The syntax for the CreateObject method is as follows: Set objMyObject = Server.CreateObject(strProgId) where: objMyObject represents the name of the Permission Checker object. The strProgId parameter represents the programmatic ID (ProgID) for the Permission Checker component, which is IISSample.PermissionChecker. Example <% ' The following code uses the CreateObject method of the ' Server object to instantiate a Permission Checker ' object on the server. Dim objPermChkr Set objPermChkr = _ Server.CreateObject("IISSample.PermissionChecker") %> For more details on the use of the CreateObject method see its documentation in Chapter 8, Server Object. Permission Checker Summary Properties None Collections None Methods HasAccess Events None 360 Chapter 21 Permission Checker Component Comments/Troubleshooting ASP in a Nutshell: A Desktop Quick Reference, eMatter Edition Copyright © 2000 OReilly & Associates, Inc. All rights reserved. Comments/Troubleshooting Suppose that your web site consists of several pages that must be accessible to all userseven anonymous users. It also contains several pages that require that the user use a specific account or be a member of a specific group. To allow for both types of users on your site, select the Anonymous option and either the Basic Clear Text or Windows NT Challenge Response using the Internet Information Server Management Console. Then set the file permissions on the restricted files so that anonymous users are forbidden access. Alternatively, you could check the LOGON_USER element of the Request objects ServerVariables collection and, if its blank, set the Status property of the Response object to 401 Unauthorized. This will force the user to log on to the site using a valid username and password. Note that Basic Clear Text authentication is by no means secure. However, Windows NT Challenge Response, though more secure, is supported only by Microsofts Internet Explorer. Also, it may not work when your users are connecting to your site (and providing security information) through a proxy server. In my experience, the typical result in this latter case is that you receive two empty strings for the username and password. Even if you exclusively use anonymous access to your site, the Permission Checker component still has a useful purpose. In attempting to determine the security on a given file, the Permission Checker object must determine if the file exists. Although there are other ways to determine this information, this may be the easiest. Methods Reference HasAccess objPermChkr.HasAccess(strPath) Determines whether the current user has access to the file specified in the strPath argument. The return value is a Boolean. Parameters strPath A string value that represents the relative path to the file to which you are determining accessibility. This path can be a virtual or a physical path. Example <% ' Declare local variables. Dim objPermChkr Dim blnPermission ' Instantiate a Permission Checker object. Set objPermChkr = Server.CreateObject( _ "IISSample.PermissionChecker") HasAccess 361 Permission Checker HasAccess ASP in a Nutshell: A Desktop Quick Reference, eMatter Edition Copyright © 2000 OReilly & Associates, Inc. All rights reserved. ' Determine whether the current user has access to the ' security page using a virtual path. blnPermission = objPermChkr.HasAccess("/Apps/SecPage.asp") ' Determine whether the current user has access to the ' security page using a physical path. blnPermission = objPermChkr.HasAccess( _ "c:\inetpub\wwwroot\Apps\SecPage.asp") ...[addition code] ' You can then use the results of these tests to determine ' whether or not to create a hyperlink to the restricted ' page If blnPermission Then %> Congratulations, you have access to the security page. <A HREF = "/Apps/SecPage.asp">Security Page</A> <% End If %> Notes If the file does not exist, the call to HasAccess returns a value of False. ASP in a Nutshell: A Desktop Quick Reference, eMatter Edition 365 |