Iterator rollMappings = security.getRoleMappings().iterator();
while (rollMappings.hasNext()) {
Role role = (Role) rollMappings.next();
String roleName = role.getRoleName();
if (!securityRoles.contains(roleName)) throw new GeronimoSecurityException("Role does not exist in this configuration");
Subject roleDesignate = new Subject();
Iterator realms = role.getRealms().iterator();
while (realms.hasNext()) {
Set principalSet = new HashSet();
Realm realm = (Realm) realms.next();
Iterator principals = realm.getPrincipals().iterator();
while (principals.hasNext()) {
Principal principal = (Principal) principals.next();
RealmPrincipal realmPrincipal = ConfigurationUtil.generateRealmPrincipal(principal, realm.getRealmName());
if (realmPrincipal == null) throw new GeronimoSecurityException("Unable to create realm principal");
principalSet.add(realmPrincipal);
if (principal.isDesignatedRunAs()) roleDesignate.getPrincipals().add(realmPrincipal);
}
roleMapper.addRoleMapping(roleName, principalSet);
}
if (roleDesignate.getPrincipals().size() > 0) context.setRoleDesignate(roleName, roleDesignate);
}
Iterator keys = roleRefs.keySet().iterator();
while (keys.hasNext()) {
String roleLink = (String) keys.next();
iter = ((Set) roleRefs.get(roleLink)).iterator();
while (iter.hasNext()) {
configuration.addToRole(roleLink, (WebRoleRefPermission) iter.next());
}
}
} catch (ClassCastException cce) {
throw new GeronimoSecurityException("Policy configuration object does not implement RoleMappingConfiguration", cce.getCause());
} catch (PolicyContextException e) {
throw new GeronimoSecurityException(e);
}
}