How to Use the Authorization Sample

After you build and register the WMS SDK Sample Authorization plug-in, you must refresh the list of plug-ins in the details pane before your custom plug-in can be accessed in the user interface. Click the server node in the Windows Media Services snap-in, click Properties in the details pane, and click the Authorization category. Click the Refresh List button at the bottom of the details pane to refresh the list of plug-ins. The sample plug-in is appended to the plug-in list. Highlight the plug-in, and click Enable.

Because the plug-in does not include a graphical user interface, you must administer it programmatically. This is illustrated by the following example:

// Include files.
#include <windows.h>
#include "wmsserver.h"
#include <atlbase.h>
#include "DBAuth.h"

// Declare variables.
HRESULT         hr=S_OK;
IWMSServer*     pServer=NULL;
IWMSPlugins*    pPlugins=NULL;
IWMSPlugin*     pPlugin=NULL;
IDBAuthAdmin*   pDBAuthAdmin=NULL;
IDispatch*      pCustomInterface=NULL;
CComBSTR        bstrName;
CComVariant     varIndex;
long            lCount=0;

// Initialize COM and retrieve a pointer to IWMSServer.
hr = CoInitialize(NULL);
hr = CoCreateInstance(CLSID_WMSServer,
                      NULL,
                      CLSCTX_ALL,
                      IID_IWMSServer,
                      (void **)&pServer);

if (SUCCEEDED(hr))
{
  // Retrieve the collection of event notification 
  // and authorization plug-ins.
  hr = pServer->get_EventHandlers(&pPlugins);
  if (SUCCEEDED(hr))
  {
    // Loop through the collection and retrieve the
    // sample authorization plug-in.
    hr = pPlugins->get_Count(&lCount);
    for (int i=0; i<lCount; i++)
    {
      varIndex = i;
      hr = pPlugins->get_Item(varIndex, &pPlugin);
      hr = pPlugin->get_Name(&bstrName);
      if (bstrName == "WMS SDK Sample Authorization Plugin") break;
    }
    // Retrieve the custom administration interface.
    hr = pPlugin->get_CustomInterface(&pCustomInterface);
    hr = pCustomInterface->QueryInterface(IID_IDBAuthAdmin,
                                          (void**)&pDBAuthAdmin);
    // Add and remove users.
    hr = pDBAuthAdmin->AddUser(L"user_name");
    hr = pDBAuthAdmin->RemoveUser(L"user_name");
  }
}

// Release temporary objects and uninitialize COM.
hr = pServer->Release();
hr = pPlugins->Release();
hr = pPlugin->Release();
hr = pDBAuthAdmin->Release();
hr = pCustomInterface->Release();

CoUninitialize();

See Also

Concepts

Authorization Plug-in Sample