Share via


IWMSEventAuthorizationCallback.OnAuthorizeEvent (Visual Basic .NET)

banner art

Previous Next

IWMSEventAuthorizationCallback.OnAuthorizeEvent (Visual Basic .NET)

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

Syntax

  

Parameters

hr

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

Context

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 Values

This method does not return a value. If the plug-in uses the IWMSEventLog object to log error information, it is recommended that it send NS_E_PLUGIN_ERROR_REPORTED (0xC00D157D) to the server in the hr 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 Code

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.

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

Previous Next