1 19 package org.lucane.server.store.ldap; 20 21 import java.util.HashMap ; 22 23 import javax.xml.parsers.*; 24 25 import org.lucane.common.Logging; 26 import org.w3c.dom.*; 27 28 29 32 public class LdapConfig 33 { 34 public static final String CONFIG_FILE = "etc/ldap-store.xml"; 35 36 private String ldapUrl; 37 38 private String authType; 39 private String authBindDn; 40 private String authPassword; 41 42 private String pluginsDn; 43 private HashMap pluginsAttributes = new HashMap (); 44 private HashMap pluginsMapping = new HashMap (); 45 46 private String servicesDn; 47 private HashMap servicesAttributes = new HashMap (); 48 private HashMap servicesMapping = new HashMap (); 49 50 private String usersDn; 51 private HashMap usersAttributes = new HashMap (); 52 private HashMap usersMapping = new HashMap (); 53 54 private String groupsDn; 55 private HashMap groupsAttributes = new HashMap (); 56 private HashMap groupsMapping = new HashMap (); 57 58 59 64 public LdapConfig(String filename) 65 throws Exception 66 { 67 DocumentBuilder builder = DocumentBuilderFactory.newInstance().newDocumentBuilder(); 68 Document document = builder.parse(filename); 69 70 Node node = document.getFirstChild(); 72 while(node != null && node.getNodeType() != Node.ELEMENT_NODE) 73 node = node.getNextSibling(); 74 75 if(node == null || !node.getNodeName().equals("ldap")) 76 throw new Exception ("root element is different from 'ldap'"); 77 78 this.ldapUrl = node.getAttributes().getNamedItem("url").getNodeValue(); 79 80 node = node.getFirstChild(); 81 while(node != null) 82 { 83 if(node.getNodeType() == Node.ELEMENT_NODE) 84 { 85 if(node.getNodeName().equals("authentication")) 86 handleAuthentication(node); 87 else if(node.getNodeName().equals("plugins")) 88 handlePlugins(node); 89 else if(node.getNodeName().equals("services")) 90 handleServices(node); 91 else if(node.getNodeName().equals("users")) 92 handleUsers(node); 93 else if(node.getNodeName().equals("groups")) 94 handleGroups(node); 95 else 96 Logging.getLogger().warning("unexepected node : " + node.getNodeName()); 97 } 98 node = node.getNextSibling(); 99 } 100 } 101 102 107 private void handleAuthentication(Node node) 108 { 109 this.authType = node.getAttributes().getNamedItem("type").getNodeValue(); 110 this.authBindDn = node.getAttributes().getNamedItem("bind-dn").getNodeValue(); 111 this.authPassword = node.getAttributes().getNamedItem("password").getNodeValue(); 112 } 113 114 119 private void handlePlugins(Node node) 120 { 121 this.pluginsDn = node.getAttributes().getNamedItem("dn").getNodeValue(); 122 123 node = node.getFirstChild(); 124 while(node != null) 125 { 126 if(node.getNodeType() == Node.ELEMENT_NODE) 127 { 128 if(node.getNodeName().equals("attribute")) 129 handleMapping(this.pluginsAttributes, node); 130 else if(node.getNodeName().equals("mapping")) 131 handleMapping(this.pluginsMapping, node); 132 else 133 Logging.getLogger().warning("unexepected node : " + node.getNodeName()); 134 } 135 node = node.getNextSibling(); 136 } 137 } 138 139 144 private void handleServices(Node node) 145 { 146 this.servicesDn = node.getAttributes().getNamedItem("dn").getNodeValue(); 147 148 node = node.getFirstChild(); 149 while(node != null) 150 { 151 if(node.getNodeType() == Node.ELEMENT_NODE) 152 { 153 if(node.getNodeName().equals("attribute")) 154 handleMapping(this.servicesAttributes, node); 155 else if(node.getNodeName().equals("mapping")) 156 handleMapping(this.servicesMapping, node); 157 else 158 Logging.getLogger().warning("unexepected node : " + node.getNodeName()); 159 } 160 node = node.getNextSibling(); 161 } 162 } 163 164 169 private void handleUsers(Node node) 170 { 171 this.usersDn = node.getAttributes().getNamedItem("dn").getNodeValue(); 172 173 node = node.getFirstChild(); 174 while(node != null) 175 { 176 if(node.getNodeType() == Node.ELEMENT_NODE) 177 { 178 if(node.getNodeName().equals("attribute")) 179 handleMapping(this.usersAttributes, node); 180 else if(node.getNodeName().equals("mapping")) 181 handleMapping(this.usersMapping, node); 182 else 183 Logging.getLogger().warning("unexepected node : " + node.getNodeName()); 184 } 185 node = node.getNextSibling(); 186 } 187 } 188 189 194 private void handleGroups(Node node) 195 { 196 this.groupsDn = node.getAttributes().getNamedItem("dn").getNodeValue(); 197 198 node = node.getFirstChild(); 199 while(node != null) 200 { 201 if(node.getNodeType() == Node.ELEMENT_NODE) 202 { 203 if(node.getNodeName().equals("attribute")) 204 handleMapping(this.groupsAttributes, node); 205 else if(node.getNodeName().equals("mapping")) 206 handleMapping(this.groupsMapping, node); 207 else 208 Logging.getLogger().warning("unexepected node : " + node.getNodeName()); 209 } 210 node = node.getNextSibling(); 211 } 212 } 213 214 219 private void handleMapping(HashMap map, Node node) 220 { 221 String name = node.getAttributes().getNamedItem("name").getNodeValue(); 222 String value = node.getAttributes().getNamedItem("value").getNodeValue(); 223 224 map.put(name, value); 225 } 226 227 229 public String getLdapUrl() 230 { 231 return this.ldapUrl; 232 } 233 234 public String getAuthType() 235 { 236 return this.authType; 237 } 238 239 public String getAuthBindDn() 240 { 241 return this.authBindDn; 242 } 243 244 public String getAuthPassword() 245 { 246 return this.authPassword; 247 } 248 249 public String getPluginsDn() 250 { 251 return this.pluginsDn; 252 } 253 254 public HashMap getPluginsAttributes() 255 { 256 return this.pluginsAttributes; 257 } 258 259 public HashMap getPluginsMapping() 260 { 261 return this.pluginsMapping; 262 } 263 264 public String getServicesDn() 265 { 266 return this.servicesDn; 267 } 268 269 public HashMap getServicesAttributes() 270 { 271 return this.servicesAttributes; 272 } 273 274 public HashMap getServicesMapping() 275 { 276 return this.servicesMapping; 277 } 278 279 public String getUsersDn() 280 { 281 return this.usersDn; 282 } 283 284 public HashMap getUsersAttributes() 285 { 286 return this.usersAttributes; 287 } 288 289 public HashMap getUsersMapping() 290 { 291 return this.usersMapping; 292 } 293 294 public String getGroupsDn() 295 { 296 return this.groupsDn; 297 } 298 299 public HashMap getGroupsAttributes() 300 { 301 return this.groupsAttributes; 302 } 303 304 public HashMap getGroupsMapping() 305 { 306 return this.groupsMapping; 307 } 308 } | Popular Tags |