on EAP 6.3 the Security Context Principal is anonymous when invoking EJB sessionBean from MDB

Solution Unverified - Updated -

Issue

  • When invoking an EJB sessionBean from an MDB I have the permissions to execute the sessionBean, but the principal is not set correctly.

Here is my MDB:

@MessageDriven(name = "HelloWorldQueueMDB", activationConfig = {
        @ActivationConfigProperty(propertyName = "destinationType", propertyValue = "javax.jms.Queue"),
        @ActivationConfigProperty(propertyName = "destination", propertyValue = "queue/HELLOWORLDMDBQueue"),
        @ActivationConfigProperty(propertyName = "acknowledgeMode", propertyValue = "Auto-acknowledge") })
@RunAs("guest")
@PermitAll
public class HelloWorldQueueMDB implements MessageListener {

    private final static Logger LOGGER = Logger.getLogger(HelloWorldQueueMDB.class.toString());
    @EJB
    private SecureSessionBean secureBean;

    /**
     * @see MessageListener#onMessage(Message)
     */
    public void onMessage(Message rcvMessage) {
        TextMessage msg = null;
        try {
            if (rcvMessage instanceof TextMessage) {
                msg = (TextMessage) rcvMessage;
                LOGGER.info("Received Message from queue: " + msg.getText());
                secureBean.printRole();
            } else {
                LOGGER.warning("Message of wrong type: " + rcvMessage.getClass().getName());
            }
        } catch (JMSException e) {
            throw new RuntimeException(e);
        }
    }
}

And my EJB SessionBean:

@Stateless
@LocalBean
public class SecureSessionBean {


        @Resource SessionContext ctx;
    /**
     * Default constructor. 
     */
    public SecureSessionBean() {
        // TODO Auto-generated constructor stub
    }

    @RolesAllowed("guest")
    public void printRole(){
        Principal callerPrincipal = ctx.getCallerPrincipal();
        System.out.println("** Principal name:" + callerPrincipal.getName());
    }

}
  • I have added a role to the 'ManagementRealm' using the bin/add-user.sh. The username is jshepher, and they have the role guest. In the logs I see the principal is anonymous, why?

  • Query regarding Security Context Propagation in MDB/EAP.

Environment

Red Hat JBoss Enterprise Application Platform 6.3.0

Subscriber exclusive content

A Red Hat subscription provides unlimited access to our knowledgebase, tools, and much more.

Current Customers and Partners

Log in for full access

Log In

New to Red Hat?

Learn more about Red Hat subscriptions

Using a Red Hat product through a public cloud?

How to access this content