IWMSEventAuthorizationPlugin.AuthorizeEvent (Visual Basic .NET)

The AuthorizeEvent method is used by the plug-in to authorize the event requested by the server.

IWMSEventAuthorizationPlugin.AuthorizeEvent(  ByRef pEvent As WMS_EVENT,
  pUserCtx As IWMSContext,
  pPresentationCtx As IWMSContext,
  pCommandCtx As IWMSCommandContext,
  pCallback As IWMSEventAuthorizationCallback,
  Context As Object
)

Arguments

[in] Reference to a WMS_EVENT structure containing the event to be authorized.

[in] IWMSContextIWMSContext Object (Visual Basic .NET) containing the User Context.

[in] IWMSContext object containing the Presentation Context.

[in] IWMSCommandContextIWMSCommandContext Object (Visual Basic .NET) containing the Command Context.

[in] IWMSEventAuthorizationCallbackIWMSEventAuthorizationCallback Object (Visual Basic .NET) used by the plug-in to call IWMSEventAuthorizationCallback.OnAuthorizeEvent to return a result to the server.

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

Return Value

This method does not return a value. To report an error, the plug-in can throw a COMException object to the server. If the plug-in uses the IWMSEventLogIWMSEventLog Object (Visual Basic .NET) to log error information, it is recommended that it throw NS_E_PLUGIN_ERROR_REPORTED (0xC00D157D). 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 send custom error information to the Windows Event Viewer, throwing 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 a plug-in is not able to verify access to a file because the file could not be found, it is recommended that the plug-in throw NS_E_AUTHORIZATION_FILE_NOT_FOUND (0xc00d1590). The server informs the client that the file could not be found (a 201 error) rather than indicating only that access was denied (a 401 error).

Remarks

Before calling this method, the server calls GetAuthorizedEvents to retrieve an array of events that the plug-in must authorize. The server calls AuthorizeEvent when one of these events occurs.

Example

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

Public Sub AuthorizeEvent( _
    ByRef pEvent As WMS_EVENT, ByVal pUserCtx As IWMSContext, _
    ByVal pPresentationCtx As IWMSContext, _
    ByVal pCommandCtx As IWMSCommandContext, _
    ByVal pCallback As IWMSEventAuthorizationCallback, _
    ByVal Context As Object) _
        Implements IWMSEventAuthorizationPlugin.AuthorizeEvent

        Dim wmsAccess As WMS_ACCESS_CONTROL = _
                         WMS_ACCESS_CONTROL.WMS_ACL_DENY_ALL
        Dim strUser As String = ""

        ' This variable uses numerical values to 
        ' represent HRESULT error codes.
        Dim hr As Integer = 0

        ' Switch on the event type.
        Select Case (pEvent.Type)
            Case WMS_EVENT_TYPE.WMS_EVENT_DESCRIBE, _
                 WMS_EVENT_TYPE.WMS_EVENT_OPEN, _
                 WMS_EVENT_TYPE.WMS_EVENT_GET_PARAMETER, _
                 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, _
                                         strUser, _
                                         0)

                   If strUser <> "" Then

                        ' 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, ByRef _
                                                                wmsAccess)

                      If pEvent.Type = _
                         WMS_EVENT_TYPE.WMS_EVENT_OPEN Or _
                         pEvent.Type = WMS_EVENT_TYPE.WMS_EVENT_DESCRIBE _
                         Or pEvent.Type = _
                         WMS_EVENT_TYPE.WMS_EVENT_GET_PARAMETER Then

                            ' Check to see whether read access is 
                            ' permitted.
                          If WMS_ACCESS_CONTROL.WMS_ACL_DENY_READ = _
                                                            wmsAccess Then

                                ' User was denied read access.
                                ' Pass the callback method the integer
                                ' value of E_ACCESSDENIED.
                                hr = &H80070005
                          ElseIf WMS_ACCESS_CONTROL.WMS_ACL_ALLOW_READ = _
                                                            wmsAccess Then

                                ' 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 = &H80004005
                          End If
                      End If
                   Else

                        ' Check whether write access is permitted.
                        If WMS_ACCESS_CONTROL.WMS_ACL_DENY_WRITE = _
                                                            wmsAccess Then

                                ' User was denied read access.
                                ' Pass the callback method the integer
                                ' value of E_ACCESSDENIED.
                                hr = &H80070005
                        ElseIf WMS_ACCESS_CONTROL.WMS_ACL_ALLOW_WRITE = _
                                                            wmsAccess Then
                            ' 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 = &H80004005
                        End If
                    End If

                ' Null out string containing user name.
                strUser = ""

                Catch e As Exception
                    ' TODO: Handle exceptions.
                Finally
                    ' Report the results of the authorization
                    ' challenge back to the server.
                    pCallback.OnAuthorizeEvent(hr, Context)
                End Try
        End Select
    End Sub

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

IWMSCommandContext Object (Visual Basic .NET)

IWMSContext Object (Visual Basic .NET)

IWMSEventAuthorizationCallback Object (Visual Basic .NET)

IWMSEventAuthorizationPlugin Object (Visual Basic .NET)