// By default, build the principal with the run-as role value
Principal principal = new JPrincipal(this.runAsRole);
// Get the EasyBeans DD
EasyBeansDD easyBeansDD = this.bean.getEjbJarDeployableMetadata().getEasyBeansDD();
if (easyBeansDD != null) {
// Get the current bean name
String beanName = this.bean.getJCommonBean().getName();
// For each declared session bean
List<Session> sessions = easyBeansDD.getEJB().getSessions();
for (Session session : sessions) {
String ejbName = session.getEjbName();
// Found the bean to analyze
if (beanName.equals(ejbName)) {
RunAs runAs = session.getRunAs();
if (runAs != null) {
// Found the principal name to use with the current bean
String beanPincipalName = runAs.getPrincipalName();
principal = new JPrincipal(beanPincipalName);
// Read security role mappings to get all roles for the principal name identity
for (SecurityRoleMapping securityRoleMapping : easyBeansDD.getSecurityRoleMappings()) {
for (String pincipalName : securityRoleMapping.getPrincipalNames()) {
if (beanPincipalName.equals(pincipalName)) {
principals.add(new JPrincipal(securityRoleMapping.getRoleName()));
}
}