Search code examples
jakarta-eejmsweblogicmessage-driven-bean

Weblogic Message Driven Bean reading from a secured queue @RunAs does not work


I have a MDB very simple which works fine as long as the queue from where it reads messages is not secured

After I secure the Queue with a username it can;t read messages anymore

@MessageDriven(mappedName = "DistributedQueueTest")

public class MdbReceiver implements MessageListener {
@Resource
private MessageDrivenContext mdc;

@Override
public void onMessage(Message inMessage) {
TextMessage msg = null;
try {
msg = (TextMessage) inMessage;
System.out.println("Test MdbReceiver Message received : " + msg.getText());
} catch (JMSException e) {
e.printStackTrace();
mdc.setRollbackOnly();
}
}

}

I tried with all kind of @RunAs annotations @weblogic.jws.security.RunAs(role="Joan",mapToPrincipal="ccc_user") where ccc_user is alowed to read messages from the queue

import javax.annotation.security.RunAs; @RunAs("SomeRole") gives me an error on deployment Unable to deploy EJB: MdbReceiver from mdbReceiver.jar: Expected role in mapping

Any idea how can i do this with annotations ? I tried even without annotations ...same the exeption in weblogic console is

weblogic.jms.common.JMSSecurityException: Access denied to resource: type=<jms>, application=UNIV_REC_Module, destinationType=queue, resource=DistributedQueueTest, action=receive

Thank you


Solution

  • If you annotate your MDB as follows it should work:

    @MessageDriven(name = "MdbReceiver", mappedName = "DistributedQueueTest")
    @DeclareRoles({"Loan"})
    @RolesAllowed("Loan")
    public class MdbReceiver implements MessageListener {
    ...
    }