IWMSEventAuthorizationCallback::OnAuthorizeEvent

banner art

Previous Next

IWMSEventAuthorizationCallback::OnAuthorizeEvent

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

Syntax

  HRESULT OnAuthorizeEvent(
  long  hr,
  VARIANT  Context
);

Parameters

hr

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

Context

[in] VARIANT 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

If the method succeeds, it returns S_OK. If it fails, it returns an HRESULT error code.

Return code Number Description
E_INVALIDARG 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.

HRESULT STDMETHODCALLTYPE 
CACLPlugin::AuthorizeEvent(
            WMS_EVENT __RPC_FAR *pEvent,
            IWMSContext __RPC_FAR *pUserCtx,
            IWMSContext __RPC_FAR *pPresentationCtx,
            IWMSCommandContext __RPC_FAR *pCommandCtx,
            IWMSEventAuthorizationCallback __RPC_FAR *pCallback,
            VARIANT Context )

{

    HRESULT hr = S_OK;
    WMS_ACCESS_CONTROL wmsAccess = WMS_ACL_DENY_ALL;
    LPWSTR wstrUser = NULL;

    // Switch on the event type.
    switch( pEvent->Type )
    {

    case WMS_EVENT_DESCRIBE:                    // Read access
    case WMS_EVENT_OPEN:                        // Read access
    case WMS_EVENT_GET_PARAMETER:               // Read access
    case WMS_EVENT_VALIDATE_PUSH_DISTRIBUTION:  // Write access

    // Retrieve the user name from the user context.
    hr = pUserCtx->GetStringValue( const_cast<LPWSTR>( WMS_USER_NAME ), 
                                   WMS_USER_NAME_ID, 
                                   &wstrUser, 
                                   0 );
    if( SUCCEEDED( hr ) )
    {
        // Determine whether the user is in the access control
        // list, and what rights the user has.
        // The GetUserAccess funtion is user-defined.
        hr = m_AccessControl.GetUserAccess( wstrUser, wmsAccess );
        if( SUCCEEDED( hr ) )
        {
            if( ( WMS_EVENT_OPEN == pEvent->Type ) || 
                ( WMS_EVENT_DESCRIBE == pEvent->Type ) ||
                ( WMS_EVENT_GET_PARAMETER == pEvent->Type ) )
            {
                //
                // Check to see whether read access is permitted.
                //
                if( WMS_ACL_DENY_READ & wmsAccess )
                {
                    // User was denied read access.
                    hr = E_ACCESSDENIED;
                }
                else if( WMS_ACL_ALLOW_READ & wmsAccess )
                {
                    // User was granted read access.
                    hr = S_OK;
                }
                else
                {
                    // User was neither granted nor denied read access.
                    hr = HRESULT_FROM_WIN32( ERROR_NO_SUCH_USER );
                }
            }
            else
            {
                //
                // Check whether write access is permitted.
                //
                if( WMS_ACL_DENY_WRITE & wmsAccess )
                {
                    // User was denied write access.
                    hr = E_ACCESSDENIED;
                }
                else if( WMS_ACL_ALLOW_WRITE & wmsAccess )
                {
                    // User was granted write access.
                    hr = S_OK;
                }
                else
                {
                    // User was neither granted nor denied write access.
                    hr = HRESULT_FROM_WIN32( ERROR_NO_SUCH_USER );
                }
            }
        // Free memory.
        ::CoTaskMemFree( wstrUser );
        }
    }
    else if( DISP_E_BADINDEX == hr )
    {
        // DISP_E_BADINDEX is returned from GetStringValue if 
        // WMS_USER_NAME is not valid.
        hr = HRESULT_FROM_WIN32( ERROR_NO_SUCH_USER );
    }
    break;

    default:
        hr = S_OK;
        break;
    }

 pCallback->OnAuthorizeEvent( (long) hr, Context );
 return( S_OK );
}

Requirements

Header: event.h.

Library: WMSServerTypeLib.dll.

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

See Also

Previous Next