I'm running on glassfish v4 and I use a messagedriven bean. Currently I'm defining the principal under which the bean runs in the glassfish-ejb-jar.xml
like:
<enterprise-beans>
<ejb>
<ejb-name>MessageConsumerBean</ejb-name>
<principal>
<name>MDBPrincipal</name>
</principal>
Is it possible to do the same using just annotations e.g. @MessageDriven
?
According to https://java.net/downloads/ejb-spec/mdb.no-method.interface.pdf section 5.4.14 page 133 a Principal may be propagated in the security context but details are not governed by the EJB spec. In other words it's a platform dependent feature.
One can use @RunAs If MDB need to be granted a specific role to run some protected @RolesAllowed method.
If you need Principal for some application logic I'm afraid there's only platform dependent solution like RunAsPrincipal (JBoss) or glassfish-ejb-jar.xml in your case.