view src/kryshen/catalina/startup/HomesUserDatabase.java @ 4:6ef7cbf5c8d6

Cleanup.
author Mikhail Kryshen <mikhail@kryshen.net>
date Fri, 30 Oct 2009 05:15:03 +0300
parents 3ab011b6e6e8
children 64c05808a046
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.Collections;
24 import java.util.HashMap;
25 import java.util.Map;
27 /**
28 * Concrete implementation of the <strong>UserDatabase</code> interface
29 * considers all directories in a directory whose pathname is specified
30 * to our constructor to be "home" directories for those users.
31 *
32 * @author Craig R. McClanahan
33 * @author Mikhail Kryshen
34 */
36 public final class HomesUserDatabase implements UserDatabase {
38 // --------------------------------------------------- Instance Variables
40 /**
41 * The set of home directories for all defined users, keyed by username.
42 */
43 private Map<String, File> homes = new HashMap<String, File>();
46 /**
47 * The UserConfig listener with which we are associated.
48 */
49 private UserConfig userConfig = null;
52 // ----------------------------------------------------------- Properties
55 /**
56 * Return the UserConfig listener with which we are associated.
57 */
58 public UserConfig getUserConfig() {
59 return (this.userConfig);
60 }
63 /**
64 * Set the UserConfig listener with which we are associated.
65 *
66 * @param userConfig The new UserConfig listener
67 */
68 public void setUserConfig(UserConfig userConfig) {
69 this.userConfig = userConfig;
70 init();
72 }
75 // ------------------------------------------------------- Public Methods
78 /**
79 * Return mapping between usernames and home directories.
80 */
81 public Map<String, File> getUserHomes() {
82 return Collections.unmodifiableMap(homes);
83 }
85 // ------------------------------------------------------ Private Methods
88 /**
89 * Initialize our set of users and home directories.
90 */
91 private void init() {
92 String homeBase = userConfig.getHomeBase();
93 File homeBaseDir = new File(homeBase);
95 if (!homeBaseDir.exists() || !homeBaseDir.isDirectory()) {
96 return;
97 }
99 String homeBaseFiles[] = homeBaseDir.list();
101 for (int i = 0; i < homeBaseFiles.length; i++) {
102 File homeDir = new File(homeBaseDir, homeBaseFiles[i]);
104 if (!homeDir.isDirectory() || !homeDir.canExecute()) {
105 continue;
106 }
108 homes.put(homeBaseFiles[i], homeDir);
109 }
110 }
111 }