1 --- apache-tomcat-6.0.29-src/java/org/apache/catalina/startup/UserConfig.java.orig 2010-07-19 15:02:32.000000000 +0200
2 +++ apache-tomcat-6.0.29-src/java/org/apache/catalina/startup/UserConfig.java 2010-11-18 13:50:33.433156115 +0100
7 + * The connection URL for the LDAP server we will contact.
9 + private String connectionURL = null;
13 + * The connection username for the LDAP server we will contact.
15 + private String connectionName = null;
19 + * The connection password for the LDAP server we will contact.
21 + private String connectionPassword = null;
25 + * The type of authentication to use
27 + private String authentication = null;
30 + * The base element for user searches.
32 + private String searchBase = "";
36 + * The message format used to search for users.
38 + private String searchFilter = "(objectClass=posixAccount)";
42 + * Should we search the entire subtree for matching users?
44 + private boolean searchSubtree = false;
48 + * The attibute that denotes user name(s).
50 + private String userAttr = "uid";
54 + * The attibute that denotes user home directory.
56 + private String homeAttr = "homeDirectory";
59 * The string resources for this package.
61 private static final StringManager sm =
68 + * The connection URL for the LDAP server we will contact.
70 + public String getConnectionURL() {
72 + return (this.connectionURL);
75 + public void setConnectionURL(String connectionURL) {
77 + this.connectionURL = connectionURL;
83 + * The connection username for the LDAP server we will contact.
85 + public String getConnectionName() {
87 + return (this.connectionName);
90 + public void setConnectionName(String connectionName) {
92 + this.connectionName = connectionName;
98 + * The connection password for the LDAP server we will contact.
100 + public String getConnectionPassword() {
102 + return (this.connectionPassword);
105 + public void setConnectionPassword(String connectionPassword) {
107 + this.connectionPassword = connectionPassword;
112 + * Return the type of authentication to use.
114 + public String getAuthentication() {
116 + return (this.authentication);
121 + * Set the type of authentication to use.
123 + * @param authentication The authentication
125 + public void setAuthentication(String authentication) {
127 + this.authentication = authentication;
133 + * The base element for user searches.
135 + public String getSearchBase() {
137 + return (this.searchBase);
140 + public void setSearchBase(String searchBase) {
142 + this.searchBase = searchBase;
148 + * The message format used to search for users.
150 + public String getSearchFilter() {
152 + return (this.searchFilter);
155 + public void setSearchFilter(String searchFilter) {
157 + this.searchFilter = searchFilter;
163 + * Should we search the entire subtree for matching users?
165 + public boolean getSearchSubtree() {
167 + return (this.searchSubtree);
170 + public void setSearchSubtree(String searchSubtree) {
172 + this.searchSubtree = searchSubtree;
178 + * The attibute that denotes user name(s).
180 + public String getUserAttr() {
182 + return (this.userAttr);
185 + public void setUserAttr(String userAttr) {
187 + this.userAttr = userAttr;
193 + * The attibute that denotes user home directory.
195 + public String getHomeAttr() {
197 + return (this.homeAttr);
200 + public void setHomeAttr(String homeAttr) {
202 + this.homeAttr = homeAttr;
208 * Return the user database class name for this component.
209 --- /dev/null 2010-10-22 13:07:45.106999849 +0200
210 +++ apache-tomcat-6.0.29-src/java/org/apache/catalina/startup/LDAPUserDatabase.java 2010-11-18 13:50:32.671156104 +0100
213 + * Licensed to the Apache Software Foundation (ASF) under one or more
214 + * contributor license agreements. See the NOTICE file distributed with
215 + * this work for additional information regarding copyright ownership.
216 + * The ASF licenses this file to You under the Apache License, Version 2.0
217 + * (the "License"); you may not use this file except in compliance with
218 + * the License. You may obtain a copy of the License at
220 + * http://www.apache.org/licenses/LICENSE-2.0
222 + * Unless required by applicable law or agreed to in writing, software
223 + * distributed under the License is distributed on an "AS IS" BASIS,
224 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
225 + * See the License for the specific language governing permissions and
226 + * limitations under the License.
230 +package org.apache.catalina.startup;
233 +import java.util.Collection;
234 +import java.util.Hashtable;
235 +import java.util.Enumeration;
236 +import java.util.Vector;
237 +import javax.naming.directory.DirContext;
238 +import javax.naming.directory.InitialDirContext;
239 +import javax.naming.directory.Attribute;
240 +import javax.naming.directory.Attributes;
241 +import javax.naming.directory.SearchControls;
242 +import javax.naming.directory.SearchResult;
243 +import javax.naming.Context;
244 +import javax.naming.NamingException;
245 +import javax.naming.NamingEnumeration;
248 + * Concrete implementation of the <code>UserDatabase</code> interface
249 + * that retrieves user data from LDAP server.
251 + * @author Jan Rękorajski
255 +public final class LDAPUserDatabase
256 + implements UserDatabase {
258 + // --------------------------------------------------------- Constructors
261 + * Initialize a new instance of this user database component.
263 + public LDAPUserDatabase() {
267 + // --------------------------------------------------- Instance Variables
270 + * The set of home directories for all defined users, keyed by username.
272 + private Hashtable homes = new Hashtable();
275 + * The UserConfig listener with which we are associated.
277 + private UserConfig userConfig = null;
279 + // ----------------------------------------------------------- Properties
282 + * Return the UserConfig listener with which we are associated.
284 + public UserConfig getUserConfig() {
285 + return (this.userConfig);
289 + * Set the UserConfig listener with which we are associated.
291 + * @param userConfig The new UserConfig listener
293 + public void setUserConfig(UserConfig userConfig) {
294 + this.userConfig = userConfig;
298 + // ------------------------------------------------------- Public Methods
301 + * Return an absolute pathname to the home directory for the specified user.
303 + * @param user User for which a home directory should be retrieved
305 + public String getHome(String user) {
306 + return ((String) homes.get(user));
311 + * Return an enumeration of the usernames defined on this server.
313 + public Enumeration getUsers() {
314 + return (homes.keys());
317 + // ------------------------------------------------------ Private Methods
321 + * Initialize our set of users and home directories.
323 + private void init() {
324 + static String INIT_CTX = "com.sun.jndi.ldap.LdapCtxFactory";
326 + String connectionURL = userConfig.getConnectionURL();
327 + String connectionName = userConfig.getConnectionName();
328 + String connectionPassword = userConfig.getConnectionPassword();
329 + String authentication = userConfig.getAuthentication();
330 + String searchBase = userConfig.getSearchBase();
331 + String searchFilter = userConfig.getSearchFilter();
332 + boolean searchSubtree = userConfig.getSearchSubtree();
333 + String userAttr = userConfig.getUserAttr();
334 + String homeAttr = userConfig.getHomeAttr();
337 + Hashtable<String,String> env = new Hashtable<String,String>();
339 + env.put(Context.INITIAL_CONTEXT_FACTORY, INIT_CTX);
340 + if (connectionName != null)
341 + env.put(Context.SECURITY_PRINCIPAL, connectionName);
342 + if (connectionPassword != null)
343 + env.put(Context.SECURITY_CREDENTIALS, connectionPassword);
344 + if (connectionURL != null)
345 + env.put(Context.PROVIDER_URL, connectionURL);
346 + if (authentication != null)
347 + env.put(Context.SECURITY_AUTHENTICATION, authentication);
349 + DirContext dirContext = new InitialDirContext(env);
351 + SearchControls constraints = new SearchControls();
352 + if (searchSubtree) {
353 + constraints.setSearchScope(SearchControls.SUBTREE_SCOPE);
355 + constraints.setSearchScope(SearchControls.ONELEVEL_SCOPE);
357 + NamingEnumeration results = dirContext.search(searchBase, searchFilter, constraints);
358 + while (results != null && results.hasMore()) {
359 + SearchResult sr = (SearchResult)results.next();
360 + String username = null;
361 + String home = null;
362 + Attributes attr = sr.getAttributes();
363 + Attribute a = attr.get(homeAttr);
364 + if (a != null && a.size() == 1)
365 + home = (String)a.get();
366 + Attribute a = attr.get(userAttr);
367 + if ((home != null) && (a != null)) {
368 + // Add all possible names of this user and corresponding directory
369 + for (int i = 0; i < a.size(); i++) {
370 + username = (String)a.get(i);
371 + if (username != null)
372 + homes.put(username, home);
376 + } catch (Exception e) {
377 + // e.printStackTrace();