Windows Media Services SDK banner art
PreviousNext

Membership Authenticator Sample

This sample authenticator, written in C++, provides a working example of how to write a Windows Media Services authentication plug-in component. The source code can be found in the C:\Program Files\Windows Media Components\SDK\Source\Authentication directory by default, or the location where you installed the Windows Media Technologies SDK.

You can build the sample component either in Microsoft® Visual Studio® 98 (by opening the NSMemberAuthentication.dsw workspace file, and then, on the Tools menu, clicking Build).

About the Sample Authentication Component

This sample component implements the HTTP-BASIC type of authentication. It includes the following three classes: CMemberAuth, CAuthenticationContext, and CLDAPAccess. These three classes are implemented in the MemberAuth.cpp, Authctx.cpp, and LDAPAccess.cpp files, respectively. The CMemberAuth class implements the INNSAuthenticator interface, and the CAuthenticationContext implements the INSSUserAuthentication interface. For specifications on these two interfaces, see the Authentication API Reference section of the Windows Media Technologies SDK. Together, they handle communications between a server and the component, and rely on the CLDAPAccess object to implement the authentication policy based on the information available in a registered custom database.

Authenticator Object

When the server attempts to initialize the authenticator object, an instance of the CMemberAuth class, it queries the HKEY_LOCAL_MACHINE\Software\Microsoft\NetShow\Servers\Default\Authentication\HTTP Basic\Membership key in the system registry. Listed under this key are the values of the DataSource, DataUserName, DataUserPassword, DataTableName, DataUserNameField, and DataUserPasswordField variables. In addition, if the LogFile value is added, the server that is running Windows Media Services creates a log file.

If all the values are fetched without error, the CMemberAuth object creates and initializes an instance of the CLDAPAccess object. When the server sets out to create a user authentication context, it requests that the CMemberAuth object perform the CreateUserAuthentication method. This, in turn, creates and initializes an instance of the CauthenticationContext object, supplying the CLDAPAccess object for the user credential.

Implementation of the other two supported methods, GetAuthenticatorClass and GetAuthenticationType, of CMemberAuth is straightforward.

User Authentication Object

The user authentication object, an instance of the CAuthenticationContex class, fulfills the contractual obligations as spelled out in the INNSUserAuthentication interface. In addition to providing services for object management, and return user and class identifiers and the authentication result, it delegates the task of authentication to the data access object.

Data Access Object

The data access object, an instance of the CLDAPAccess class, is responsible for managing the connection to an ODBC data source, and executing database queries. It implements two methods: Init and AuthenticateUser. The Init method creates an instance of the data connection (m_piConnction) object as well as a record set (m_piRecordSet) object. The connection object performs business-specific authentication policy. In this case, it gets the user name and password from the user. The AuthenticateUser method uses this input to query the user account database against entries in the record set object. If the user input matches any entry in the database, authentication is successful. Otherwise, authentication fails.

PreviousNext


© 1996-1999 Microsoft Corporation. All rights reserved.