MDB and current principal
bwallis42 Sep 5, 2013 2:18 AMI've been searching and reading on this topic and don't seem to be able to get it to work, what I have below is what I have read about and it is AFAIK the correct way to do this.
I'm running this code in JBoss EAP 6.1.0.GA. The two beans are packaged in the same ejb jar file which is itself in an ear file.
I have an MDB like so (this is cut down a bit)
@MessageDriven(name = "TaskListHumanTaskRequiredReceiver", activationConfig = { @ActivationConfigProperty( propertyName = "destinationType", propertyValue = "javax.jms.Topic"), @ActivationConfigProperty( propertyName = "destination", propertyValue = "topic/TaskIn"), }) @SecurityDomain(harvey-security-domain) @RunAsPrincipal("harvey") @RunAs("Admin") @PermitAll public class HumanTaskRequiredReceiver implements MessageListener { private static final Logger LOGGER = LoggerFactory.getLogger(HumanTaskRequiredReceiver.class); @Resource MessageDrivenContext sessionContext; @EJB private TaskServiceBeanLocal taskServiceBean; public void onMessage(Message message) { LOGGER.info("Caller Principal is " + sessionContext.getCallerPrincipal()); LOGGER.info("Has roll Admin? " + sessionContext.isCallerInRole("Admin")); Task task = new Task(); // ... taskServiceBean.save(task); } }
and I have my stateless session bean like so
@Stateless public class TaskServiceBean implements TaskServiceBeanLocal, TaskServiceBeanRemote { private static final Logger LOGGER = LoggerFactory.getLogger(TaskServiceBean.class); @Resource SessionContext sessionContext; public Task save(Task task) { LOGGER.info("Caller Principal is " + sessionContext.getCallerPrincipal()); LOGGER.info("Has roll Admin? " + sessionContext.isCallerInRole("Admin")); // ... } }
I don't have any additional deployment descriptors, the annotations should do all that I need. But it is not working.
The output from the logging is always
Caller Principal is anonymous
and
Has roll Admin? false
I am trying to get the caller principal in the called session bean to be "harvey" and the role "Admin" when it is called from the MDB. Is there something missing from my setup?
The security domain is configured in standalone.xml like so
<security-domain name="harvey-security-domain" cache-type="default"> <authentication> <login-module code="LdapExtended" flag="optional"> <module-option name="java.naming.provider.url" value="ldap://10.64.33.105:389"/> <module-option name="bindDN" value="cn=Administrator,CN=Users,DC=melb-dev,DC=oopl,DC=com,DC=au"/> <module-option name="bindCredential" value="Object123"/> <module-option name="baseCtxDN" value="CN=Users,DC=melb-dev,DC=oopl,DC=com,DC=au"/> <module-option name="baseFilter" value="(sn={0})"/> <module-option name="rolesCtxDN" value="CN=Users,DC=melb-dev,DC=oopl,DC=com,DC=au"/> <module-option name="roleFilter" value="(member={1})"/> <module-option name="roleNameAttributeID" value="cn"/> <module-option name="roleAttributeIsDN" value="false"/> <module-option name="roleRecursion" value="0"/> <module-option name="searchScope" value="ONELEVEL_SCOPE"/> <module-option name="allowEmptyPasswords" value="false"/> </login-module> <login-module code="RealmDirect" flag="optional"> <module-option name="password-stacking" value="useFirstPass"/> </login-module> </authentication> </security-domain>
and the application realm has a user named "harvey" with the role "Admin" (the ldap doesn't).
thanks,