1 7 package org.jboss.security.auth.login; 8 9 import java.util.ArrayList ; 10 import java.util.HashMap ; 11 12 import javax.security.auth.login.AppConfigurationEntry ; 13 14 import org.w3c.dom.Element ; 15 import org.w3c.dom.NodeList ; 16 import org.jboss.metadata.MetaData; 17 18 24 public class ConfigUtil 25 { 26 30 static public AuthenticationInfo parseAuthentication(Element policy) 31 throws Exception 32 { 33 NodeList authentication = policy.getElementsByTagName("authentication"); 35 if (authentication.getLength() == 0) 36 { 37 return null; 38 } 39 40 Element auth = (Element ) authentication.item(0); 41 NodeList modules = auth.getElementsByTagName("login-module"); 42 ArrayList tmp = new ArrayList (); 43 for (int n = 0; n < modules.getLength(); n++) 44 { 45 Element module = (Element ) modules.item(n); 46 parseModule(module, tmp); 47 } 48 AppConfigurationEntry [] entries = new AppConfigurationEntry [tmp.size()]; 49 tmp.toArray(entries); 50 AuthenticationInfo info = new AuthenticationInfo(); 51 info.setAppConfigurationEntry(entries); 52 return info; 53 } 54 55 static void parseModule(Element module, ArrayList entries) 56 throws Exception 57 { 58 AppConfigurationEntry.LoginModuleControlFlag controlFlag = AppConfigurationEntry.LoginModuleControlFlag.REQUIRED; 59 String className = MetaData.getElementAttribute(module, "code"); 60 String flag = MetaData.getElementAttribute(module, "flag"); 61 if (flag != null) 62 { 63 flag = flag.toLowerCase(); 65 if (AppConfigurationEntry.LoginModuleControlFlag.REQUIRED.toString().indexOf(flag) > 0) 66 controlFlag = AppConfigurationEntry.LoginModuleControlFlag.REQUIRED; 67 else if (AppConfigurationEntry.LoginModuleControlFlag.REQUISITE.toString().indexOf(flag) > 0) 68 controlFlag = AppConfigurationEntry.LoginModuleControlFlag.REQUISITE; 69 else if (AppConfigurationEntry.LoginModuleControlFlag.SUFFICIENT.toString().indexOf(flag) > 0) 70 controlFlag = AppConfigurationEntry.LoginModuleControlFlag.SUFFICIENT; 71 else if (AppConfigurationEntry.LoginModuleControlFlag.OPTIONAL.toString().indexOf(flag) > 0) 72 controlFlag = AppConfigurationEntry.LoginModuleControlFlag.OPTIONAL; 73 } 74 NodeList opts = module.getElementsByTagName("module-option"); 75 HashMap options = new HashMap (); 76 for (int n = 0; n < opts.getLength(); n++) 77 { 78 Element opt = (Element ) opts.item(n); 79 String name = opt.getAttribute("name"); 80 String value = MetaData.getElementContent(opt, ""); 81 options.put(name, value); 82 } 83 AppConfigurationEntry entry = new AppConfigurationEntry (className, controlFlag, options); 84 entries.add(entry); 85 } 86 } 87 | Popular Tags |