* @version $Rev: $ $Date: $
*/
public class SecurityBuilder {
public static Security buildSecurityConfig(GerSecurityType securityType) {
Security security = null;
if (securityType != null) {
security = new Security();
security.setDoAsCurrentCaller(securityType.getDoasCurrentCaller());
security.setUseContextHandler(securityType.getUseContextHandler());
security.setDefaultRole(securityType.getDefaultRole());
GerDefaultPrincipalType defaultPrincipalType = securityType.getDefaultPrincipal();
DefaultPrincipal defaultPrincipal = new DefaultPrincipal();
defaultPrincipal.setRealmName(defaultPrincipalType.getRealmName());
defaultPrincipal.setPrincipal(buildPrincipal(defaultPrincipalType.getPrincipal()));
security.setDefaultPrincipal(defaultPrincipal);
GerRoleMappingsType roleMappingsType = securityType.getRoleMappings();
if (roleMappingsType != null) {
for (int i = 0; i < roleMappingsType.sizeOfRoleArray(); i++) {
GerRoleType roleType = roleMappingsType.getRoleArray(i);
Role role = new Role();
role.setRoleName(roleType.getRoleName());
for (int j = 0; j < roleType.sizeOfRealmArray(); j++) {
GerRealmType realmType = roleType.getRealmArray(j);
Realm realm = new Realm();
realm.setRealmName(realmType.getRealmName());
for (int k = 0; k < realmType.sizeOfPrincipalArray(); k++) {
realm.getPrincipals().add(buildPrincipal(realmType.getPrincipalArray(k)));
}
role.getRealms().add(realm);
}
security.getRoleMappings().add(role);
}
}
GerAutoMapRolesType autoMapRolesType = securityType.getAutoMapRoles();
if (autoMapRolesType != null) {
AutoMapAssistant assistant = new AutoMapAssistant();
assistant.setSecurityRealm(autoMapRolesType.getSecurityRealm());
GerClassOverrideType[] classOverrideArray = autoMapRolesType.getClassOverrideArray();
for (int i = 0; i < classOverrideArray.length; i++) {
assistant.getClassOverrides().add(classOverrideArray[i].getClass1());
}
security.setAssistant(assistant);
}
}
return security;
}