on EAP 6.3 the Security Context Principal is anonymous when invoking EJB sessionBean from MDB
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 isjshepher, and they have the roleguest. 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 of over 48,000 articles and solutions.
Welcome! Check out the Getting Started with Red Hat page for quick tours and guides for common tasks.
