AutoMapAssistant config = security.getAssistant();
try {
if (config != null) {
ObjectName assistantName = new ObjectName("geronimo.security:type=SecurityRealm,realm=" + config.getSecurityRealm());
Set assistants = context.getKernel().listGBeans(assistantName);
if (assistants.size() < 1 || assistants.size() > 1) throw new GeronimoSecurityException("Only one auto mapping assistant should match " + assistantName);
org.apache.geronimo.security.realm.AutoMapAssistant assistant = (org.apache.geronimo.security.realm.AutoMapAssistant) assistants.iterator().next();
String realmName = ((SecurityRealm) assistant).getRealmName();
Iterator principalClasses = null;
if (config.getClassOverrides().size() > 0) {
principalClasses = config.getClassOverrides().iterator();
} else {
principalClasses = assistant.obtainRolePrincipalClasses().iterator();
}
Iterator roles = securityRoles.iterator();
while (roles.hasNext()) {
String roleName = (String) roles.next();
Set principalSet = new HashSet();
Subject roleDesignate = new Subject();
while (principalClasses.hasNext()) {
Principal principal = new Principal();
principal.setClassName((String) principalClasses.next());
principal.setPrincipalName(roleName);
RealmPrincipal realmPrincipal = ConfigurationUtil.generateRealmPrincipal(principal, realmName);
if (realmPrincipal == null) throw new GeronimoSecurityException("Unable to create realm principal");
principalSet.add(realmPrincipal);
roleDesignate.getPrincipals().add(realmPrincipal);
}
roleMapper.addRoleMapping(roleName, principalSet);
if (roleDesignate.getPrincipals().size() > 0) context.setRoleDesignate(roleName, roleDesignate);
}
}
} catch (MalformedObjectNameException e) {
throw new GeronimoSecurityException("Bad object name geronimo.security:type=SecurityRealm,realm=" + config.getSecurityRealm());
}
}