Partager via


IWMSEventAuthorizationCallback.OnAuthorizeEvent (C#)

The OnAuthorizeEvent method returns the result of the IWMSEventAuthorizationPlugin.AuthorizeEvent method call to the server.

void IWMSEventAuthorizationCallback.OnAuthorizeEvent(
  int lhr,
  object Context
);

Arguments

[in] int containing the result of the call to AuthorizeEvent.

[in] object containing a value defined by the server to identify which call to AuthorizeEvent the plug-in is responding to when it calls OnAuthorizeEvent. You must pass this value back unaltered.

Return Value

This method does not return a value. If the plug-in uses the IWMSEventLogIWMSEventLog Object (C#) to log error information, it is recommended that it send NS_E_PLUGIN_ERROR_REPORTED (0xC00D157D) to the server in the lHr parameter. Typically, the server attempts to make plug-in error information available to the server object model, the Windows Event Viewer, and the troubleshooting list in the details pane of the Windows Media Services MMC. However, if the plug-in uses the IWMSEventLog object to log custom error information to the Windows Event Viewer, sending NS_E_PLUGIN_ERROR_REPORTED stops the server from also logging to the event viewer. For more information about plug-in error information, see Identifying Plug-in Errors.

If this method fails, it throws an exception.

Number

Description

0x80070057

Context is null.

Example

The following example illustrates a possible implementation of the AuthorizeEvent method for an access control list (ACL) authorization plug-in. OnAuthorizeEvent is called at the bottom of the example.

void IWMSEventAuthorizationPlugin.AuthorizeEvent(ref WMS_EVENT pEvent,
                                                     IWMSContext pUserCtx,
                                             IWMSContext pPresentationCtx,
                                           IWMSCommandContext pCommandCtx,
                                 IWMSEventAuthorizationCallback pCallback,
                                                           object Context)
{
    WMS_ACCESS_CONTROL wmsAccess = WMS_ACCESS_CONTROL.WMS_ACL_DENY_ALL;
    string strUser = "";

    // This variable is used to represent HRESULT error codes.
    int hr = 0; 

    // Switch on the event type.
    switch (pEvent.Type)
    {
        // Read access.
        case WMS_EVENT_TYPE.WMS_EVENT_DESCRIBE:

        // Read access.
        case WMS_EVENT_TYPE.WMS_EVENT_OPEN:

        // Read access.
        case WMS_EVENT_TYPE.WMS_EVENT_GET_PARAMETER:

        // Write access.
        case WMS_EVENT_TYPE.WMS_EVENT_VALIDATE_PUSH_DISTRIBUTION: 

        try
        {
            // Retrieve the user name from the user context.
            pUserCtx.GetStringValue(WMSDefines.WMS_USER_NAME,       
                                        WMSDefines.WMS_USER_NAME_ID,
                                                    out strUser, 0);

            if (strUser != "")
            {
                // Determine whether the user is in the access control
                // list, and what rights the user has.
                // The GetUserAccess funtion is user-defined.
                m_AccessControl.GetUserAccess(strUser, out wmsAccess);

                if (pEvent.Type == WMS_EVENT_TYPE.WMS_EVENT_OPEN || 
                    pEvent.Type == WMS_EVENT_TYPE.WMS_EVENT_DESCRIBE ||
                    pEvent.Type == WMS_EVENT_TYPE.WMS_EVENT_GET_PARAMETER)
                {

                    // Check to see whether read access is permitted.
                    if (WMS_ACCESS_CONTROL.WMS_ACL_DENY_READ == wmsAccess)
                    {
                        // User was denied read access.
                        // Pass the callback method the integer
                        // value of E_ACCESSDENIED.
                        hr = unchecked((int)0x80070005);
                    }
                    else if (WMS_ACCESS_CONTROL.WMS_ACL_ALLOW_READ == 
                                                                wmsAccess)
                    {
                        // User was granted read access.
                        hr = 0; 
                    }
                    else
                    {
                        // User was neither granted nor denied read access.
                        // Pass the callback method the integer
                        // value of E_FAIL.
                        hr = unchecked((int)0x80004005);
                    }
                }
                else
                {
                    // Check whether write access is permitted.
                    if (WMS_ACCESS_CONTROL.WMS_ACL_DENY_WRITE == 
                                                                wmsAccess)
                    {
                        // User was denied write access.
                        // Pass the callback method the integer
                        // value of E_ACCESSDENIED.
                        hr = unchecked((int)0x80070005);
                    }
                    else if (WMS_ACCESS_CONTROL.WMS_ACL_ALLOW_WRITE == 
                                                                wmsAccess)
                    {
                        // User was granted write access.
                        hr = 0;
                    }
                    else
                    {
                        // User was neither granted nor denied read access.
                        // Pass the callback method the integer
                        // value of E_FAIL.
                        hr = unchecked((int)0x80004005);
                    }
                }
            }

            // Null out string containing user name.
            strUser = "";
        }
        catch (Exception)
        {
            // TODO: Handle exceptions. 
        }
        finally
        {
            // Report the results of the authorization
            // challenge back to the server.
            pCallback.OnAuthorizeEvent(hr, Context);
        }
        break;

        default:
        hr = 0;
        break;
    }
}

Requirements

Reference: Add a reference to Microsoft.WindowsMediaServices.

Namespace: Microsoft.WindowsMediaServices.Interop.

Assembly: Microsoft.WindowsMediaServices.dll.

Library: WMSServerTypeLib.dll.

Platform: Windows Server 2003, Enterprise Edition; Windows Server 2003, Datacenter Edition; Windows Server 2008.

See Also

Concepts

IWMSEventAuthorizationCallback Object (C#)