1 7 package org.jboss.security.auth.login; 8 9 import java.util.HashMap ; 10 import javax.security.auth.login.AppConfigurationEntry ; 11 12 import org.jboss.xb.binding.ObjectModelFactory; 13 import org.jboss.xb.binding.UnmarshallingContext; 14 import org.jboss.util.StringPropertyReplacer; 15 import org.xml.sax.Attributes ; 16 17 22 public class LoginConfigObjectModelFactory implements ObjectModelFactory 23 { 24 public Object completeRoot(Object root, UnmarshallingContext ctx, 25 String uri, String name) 26 { 27 return root; 28 } 29 30 public Object newRoot(Object root, UnmarshallingContext navigator, 31 String namespaceURI, String localName, Attributes attrs) 32 { 33 if (!localName.equals("policy")) 34 { 35 throw new IllegalStateException ("Unexpected root element: was expecting 'policy' but got '" + localName + "'"); 36 } 37 return new PolicyConfig(); 38 } 39 40 41 public Object newChild(PolicyConfig config, UnmarshallingContext navigator, 42 String namespaceUri, String localName, Attributes attrs) 43 { 44 Object child = null; 45 if("application-policy".equals(localName)) 46 { 47 String name = attrs.getValue("name"); 48 name = StringPropertyReplacer.replaceProperties(name); 49 child = new AuthenticationInfo(name); 50 } 51 return child; 52 } 53 public Object newChild(AuthenticationInfo info, UnmarshallingContext navigator, 54 String namespaceUri, String localName, Attributes attrs) 55 { 56 Object child = null; 57 if("login-module".equals(localName)) 58 { 59 String code = attrs.getValue("code"); 60 code = StringPropertyReplacer.replaceProperties(code.trim()); 61 String flag = attrs.getValue("flag"); 62 flag = StringPropertyReplacer.replaceProperties(flag.trim()); 63 AppConfigurationEntryHolder holder = new AppConfigurationEntryHolder(code, flag); 64 child = holder; 65 } 66 67 return child; 68 } 69 public Object newChild(AppConfigurationEntryHolder entry, UnmarshallingContext navigator, 70 String namespaceUri, String localName, Attributes attrs) 71 { 72 Object child = null; 73 if("module-option".equals(localName)) 74 { 75 String name = attrs.getValue("name"); 76 child = new ModuleOption(name); 77 } 78 79 return child; 80 } 81 82 public void setValue(ModuleOption option, UnmarshallingContext navigator, 83 String namespaceUri, String localName, String value) 84 { 85 if("module-option".equals(localName)) 86 { 87 String valueWithReplacement = StringPropertyReplacer.replaceProperties(value.trim()); 88 option.setValue(valueWithReplacement); 89 } 90 } 91 92 public void addChild(PolicyConfig config, AuthenticationInfo authInfo, 93 UnmarshallingContext navigator, String namespaceURI, String localName) 94 { 95 config.add(authInfo); 96 } 97 public void addChild(AuthenticationInfo authInfo, AppConfigurationEntryHolder entryInfo, 98 UnmarshallingContext navigator, String namespaceURI, String localName) 99 { 100 AppConfigurationEntry entry = entryInfo.getEntry(); 101 authInfo.addAppConfigurationEntry(entry); 102 } 103 public void addChild(AppConfigurationEntryHolder entryInfo, ModuleOption option, 104 UnmarshallingContext navigator, String namespaceURI, String localName) 105 { 106 entryInfo.addOption(option); 107 } 108 public void addChild(ModuleOption option, Object value, 109 UnmarshallingContext navigator, String namespaceURI, String localName) 110 { 111 option.setValue(value); 112 } 113 114 private static class AppConfigurationEntryHolder 115 { 116 String code; 117 AppConfigurationEntry.LoginModuleControlFlag controlFlag; 118 HashMap options = new HashMap (); 119 AppConfigurationEntryHolder(String code, String flag) 120 { 121 this.code = code; 122 controlFlag = AppConfigurationEntry.LoginModuleControlFlag.REQUIRED; 123 if (flag != null) 124 { 125 flag = flag.toLowerCase(); 127 if (AppConfigurationEntry.LoginModuleControlFlag.REQUIRED.toString().indexOf(flag) > 0) 128 controlFlag = AppConfigurationEntry.LoginModuleControlFlag.REQUIRED; 129 else if (AppConfigurationEntry.LoginModuleControlFlag.REQUISITE.toString().indexOf(flag) > 0) 130 controlFlag = AppConfigurationEntry.LoginModuleControlFlag.REQUISITE; 131 else if (AppConfigurationEntry.LoginModuleControlFlag.SUFFICIENT.toString().indexOf(flag) > 0) 132 controlFlag = AppConfigurationEntry.LoginModuleControlFlag.SUFFICIENT; 133 else if (AppConfigurationEntry.LoginModuleControlFlag.OPTIONAL.toString().indexOf(flag) > 0) 134 controlFlag = AppConfigurationEntry.LoginModuleControlFlag.OPTIONAL; 135 } 136 } 137 138 public AppConfigurationEntry getEntry() 139 { 140 AppConfigurationEntry entry = new AppConfigurationEntry (code, controlFlag, options); 141 return entry; 142 } 143 144 public void addOption(ModuleOption option) 145 { 146 options.put(option.name, option.value); 147 } 148 } 149 private static class ModuleOption 150 { 151 String name; 152 Object value = ""; 153 ModuleOption(String name) 154 { 155 this.name = name; 156 } 157 void setValue(Object value) 158 { 159 this.value = value; 160 } 161 } 162 } 163 | Popular Tags |