view src/kryshen/catalina/startup/HomesUserDatabase.java @ 2:d11df03af52a

Fixed version of HomeUserDatabase.
author Mikhail Kryshen <mikhail@kryshen.net>
date Fri, 30 Oct 2009 03:54:56 +0300
parents
children 3ab011b6e6e8
line source
1 /*
2 * Licensed to the Apache Software Foundation (ASF) under one or more
3 * contributor license agreements. See the NOTICE file distributed with
4 * this work for additional information regarding copyright ownership.
5 * The ASF licenses this file to You under the Apache License, Version 2.0
6 * (the "License"); you may not use this file except in compliance with
7 * the License. You may obtain a copy of the License at
8 *
9 * http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 */
19 package kryshen.catalina.startup;
22 import java.io.File;
23 import java.util.Hashtable;
24 import java.util.Enumeration;
25 import org.apache.catalina.startup.*;
28 /**
29 * Concrete implementation of the <strong>UserDatabase</code> interface
30 * considers all directories in a directory whose pathname is specified
31 * to our constructor to be "home" directories for those users.
32 *
33 * @author Craig R. McClanahan
34 * @version $Revision: 467222 $ $Date: 2006-10-24 05:17:11 +0200 (Tue, 24 Oct 2006) $
35 */
37 public final class HomesUserDatabase
38 implements UserDatabase {
41 // --------------------------------------------------------- Constructors
44 /**
45 * Initialize a new instance of this user database component.
46 */
47 public HomesUserDatabase() {
49 super();
51 }
54 // --------------------------------------------------- Instance Variables
57 /**
58 * The set of home directories for all defined users, keyed by username.
59 */
60 private Hashtable homes = new Hashtable();
63 /**
64 * The UserConfig listener with which we are associated.
65 */
66 private UserConfig userConfig = null;
69 // ----------------------------------------------------------- Properties
72 /**
73 * Return the UserConfig listener with which we are associated.
74 */
75 public UserConfig getUserConfig() {
77 return (this.userConfig);
79 }
82 /**
83 * Set the UserConfig listener with which we are associated.
84 *
85 * @param userConfig The new UserConfig listener
86 */
87 public void setUserConfig(UserConfig userConfig) {
89 this.userConfig = userConfig;
90 init();
92 }
95 // ------------------------------------------------------- Public Methods
98 /**
99 * Return an absolute pathname to the home directory for the specified user.
100 *
101 * @param user User for which a home directory should be retrieved
102 */
103 public String getHome(String user) {
105 return ((String) homes.get(user));
107 }
110 /**
111 * Return an enumeration of the usernames defined on this server.
112 */
113 public Enumeration getUsers() {
115 return (homes.keys());
117 }
120 // ------------------------------------------------------ Private Methods
123 /**
124 * Initialize our set of users and home directories.
125 */
126 private void init() {
128 String homeBase = userConfig.getHomeBase();
129 File homeBaseDir = new File(homeBase);
130 if (!homeBaseDir.exists() || !homeBaseDir.isDirectory())
131 return;
132 String homeBaseFiles[] = homeBaseDir.list();
134 for (int i = 0; i < homeBaseFiles.length; i++) {
135 File homeDir = new File(homeBaseDir, homeBaseFiles[i]);
136 if (!homeDir.isDirectory() || !homeDir.canExecute())
137 continue;
138 homes.put(homeBaseFiles[i], homeDir.toString());
139 }
142 }
145 }