001: /*
002: * Licensed to the Apache Software Foundation (ASF) under one or more
003: * contributor license agreements. See the NOTICE file distributed with
004: * this work for additional information regarding copyright ownership.
005: * The ASF licenses this file to You under the Apache License, Version 2.0
006: * (the "License"); you may not use this file except in compliance with
007: * the License. You may obtain a copy of the License at
008: *
009: * http://www.apache.org/licenses/LICENSE-2.0
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: * See the License for the specific language governing permissions and
015: * limitations under the License.
016: */
017:
018: package org.apache.catalina.startup;
019:
020: import java.io.File;
021: import java.util.Hashtable;
022: import java.util.Enumeration;
023:
024: /**
025: * Concrete implementation of the <strong>UserDatabase</code> interface
026: * considers all directories in a directory whose pathname is specified
027: * to our constructor to be "home" directories for those users.
028: *
029: * @author Craig R. McClanahan
030: * @version $Revision: 467222 $ $Date: 2006-10-24 05:17:11 +0200 (mar., 24 oct. 2006) $
031: */
032:
033: public final class HomesUserDatabase implements UserDatabase {
034:
035: // --------------------------------------------------------- Constructors
036:
037: /**
038: * Initialize a new instance of this user database component.
039: */
040: public HomesUserDatabase() {
041:
042: super ();
043:
044: }
045:
046: // --------------------------------------------------- Instance Variables
047:
048: /**
049: * The set of home directories for all defined users, keyed by username.
050: */
051: private Hashtable homes = new Hashtable();
052:
053: /**
054: * The UserConfig listener with which we are associated.
055: */
056: private UserConfig userConfig = null;
057:
058: // ----------------------------------------------------------- Properties
059:
060: /**
061: * Return the UserConfig listener with which we are associated.
062: */
063: public UserConfig getUserConfig() {
064:
065: return (this .userConfig);
066:
067: }
068:
069: /**
070: * Set the UserConfig listener with which we are associated.
071: *
072: * @param userConfig The new UserConfig listener
073: */
074: public void setUserConfig(UserConfig userConfig) {
075:
076: this .userConfig = userConfig;
077: init();
078:
079: }
080:
081: // ------------------------------------------------------- Public Methods
082:
083: /**
084: * Return an absolute pathname to the home directory for the specified user.
085: *
086: * @param user User for which a home directory should be retrieved
087: */
088: public String getHome(String user) {
089:
090: return ((String) homes.get(user));
091:
092: }
093:
094: /**
095: * Return an enumeration of the usernames defined on this server.
096: */
097: public Enumeration getUsers() {
098:
099: return (homes.keys());
100:
101: }
102:
103: // ------------------------------------------------------ Private Methods
104:
105: /**
106: * Initialize our set of users and home directories.
107: */
108: private void init() {
109:
110: String homeBase = userConfig.getHomeBase();
111: File homeBaseDir = new File(homeBase);
112: if (!homeBaseDir.exists() || !homeBaseDir.isDirectory())
113: return;
114: String homeBaseFiles[] = homeBaseDir.list();
115:
116: for (int i = 0; i < homeBaseFiles.length; i++) {
117: File homeDir = new File(homeBaseDir, homeBaseFiles[i]);
118: if (!homeDir.isDirectory() || !homeDir.canRead())
119: continue;
120: homes.put(homeBaseFiles[i], homeDir.toString());
121: }
122:
123: }
124:
125: }
|