Example get message rule

The next example rule is a get message rule that insists that a password must be supplied before allowing a get message request to be processed on the queue called OutboundQueue. The password is included as a field in the message filter passed into the getMessage() method.
Java™ code base
/* This rule only allows GETs from 'OutboundQueue',
    if a password is  */
/* supplied as part of the filter */

public void getMessage( String destQMgr,
                String destQ, MQeFields filter,
                        MQeAttribute attr, long confirmId )         {
   super.getMessage( destQMgr, destQ, filter, attr, confirmId );
   if (destQMgr.equals(Owner.GetName()
                && destQ.equals("OutboundQueue"))  {
       if ( !(filter.Contains( "Password" ) )      {
           throw new MQeException( Except_Rule,
                        "Password not supplied" );
       }
       else    {
           String pwd = filter.getAscii( "Password" );
           if ( !(pwd.equals( "1234" )) )   {
               throw new MQeException( Except_Rule,
                            "Incorrect password" );
           }
       }
   }
}
C code base
MQERETURN myRules_getMessage( MQeRulesGetMessage_in_ * pInput,
                              MQeRulesGetMessage_out_ * pOutput)    {
    MQeStringHndl hQueueManagerName, hCompareString, hCompareString2,
                  hFieldName, hFieldValue;
    MQEBOOL isEqual = MQE_FALSE;
    MQEBOOL contains = MQE_FALSE;
    MQeQueueManagerHndl hQueueManager;

    MQERETURN rc = MQERETURN_OK;
    MQeExceptBlock * pExceptBlock =
                           (MQeExceptBlock *)
                    (pOutput->pExceptBlock);
    SET_EXCEPT_BLOCK_TO_DEFAULT(pExceptBlock);

    /* get the current queue manager */
     rc = mqeQueueManager_getCurrentQueueManager(pExceptBlock,
                                                &hQueueManager);
    if(MQERETURN_OK == rc) {
        // if the destination queue manager is the local queue manager
              rc = mqeQueueManager_getName( hQueueManager,
                                      pExceptBlock,
                                      &hQueueManagerName );
        if(MQERETURN_OK == rc)     {
            rc = mqeString_equalTo(pInput->hQueue_QueueManagerName,
                                   pExceptBlock,
                                   &isEqual,
                                   hQueueManagerName);
            if(MQERETURN_OK == rc && isEqual)    {
                // if the destination queue name is "OutboundQueue"
                rc = mqeString_newUtf8(pExceptBlock,
                                       &hCompareString,
                                       "OutboundQueue");
                rc = mqeString_equalTo(pInput->hQueueName,
                                       pExceptBlock,
                                       &isEqual,
                                       hCompareString);
                if(MQERETURN_OK == rc && isEqual)    {
                    // password required for this queue
                    MQEBOOL contains = MQE_FALSE;
                    rc = mqeString_newUtf8(pExceptBlock,
                                           &hFieldName,
                                           "Password");
                    rc = mqeFields_contains(pInput->hFilter,
                                            pExceptBlock,
                                            &contains,
                                            hFieldName);
                    if(MQERETURN_OK == rc && contains == MQE_FALSE)     {
                        SET_EXCEPT_BLOCK(pExceptBlock,
                                         MQERETURN_RULES_DISALLOWED_BY_RULE,
                                         MQEREASON_NA);
                    }
                    else   {
                            // parse password, etc.
                    }
                }
            }
        }
    }
}
This previous rule is a simple example of protecting a queue. However, for more comprehensive security, you are recommended to use an authenticator. An authenticator allows an application to create access control lists, and to determine who is able to get messages from queues.

Terms of use | WebSphere software

(c) Copyright IBM Corporation 2004, 2005. All rights reserved.