KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > catalina > startup > HomesUserDatabase


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  */

17
18
19 package org.apache.catalina.startup;
20
21
22 import java.io.File JavaDoc;
23 import java.util.Hashtable JavaDoc;
24 import java.util.Enumeration JavaDoc;
25
26
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  * @version $Revision: 467222 $ $Date: 2006-10-24 05:17:11 +0200 (mar., 24 oct. 2006) $
34  */

35
36 public final class HomesUserDatabase
37     implements UserDatabase {
38
39
40     // --------------------------------------------------------- Constructors
41

42
43     /**
44      * Initialize a new instance of this user database component.
45      */

46     public HomesUserDatabase() {
47
48         super();
49
50     }
51
52
53     // --------------------------------------------------- Instance Variables
54

55
56     /**
57      * The set of home directories for all defined users, keyed by username.
58      */

59     private Hashtable JavaDoc homes = new Hashtable JavaDoc();
60
61
62     /**
63      * The UserConfig listener with which we are associated.
64      */

65     private UserConfig userConfig = null;
66
67
68     // ----------------------------------------------------------- Properties
69

70
71     /**
72      * Return the UserConfig listener with which we are associated.
73      */

74     public UserConfig getUserConfig() {
75
76         return (this.userConfig);
77
78     }
79
80
81     /**
82      * Set the UserConfig listener with which we are associated.
83      *
84      * @param userConfig The new UserConfig listener
85      */

86     public void setUserConfig(UserConfig userConfig) {
87
88         this.userConfig = userConfig;
89         init();
90
91     }
92
93
94     // ------------------------------------------------------- Public Methods
95

96
97     /**
98      * Return an absolute pathname to the home directory for the specified user.
99      *
100      * @param user User for which a home directory should be retrieved
101      */

102     public String JavaDoc getHome(String JavaDoc user) {
103
104         return ((String JavaDoc) homes.get(user));
105
106     }
107
108
109     /**
110      * Return an enumeration of the usernames defined on this server.
111      */

112     public Enumeration JavaDoc getUsers() {
113
114         return (homes.keys());
115
116     }
117
118
119     // ------------------------------------------------------ Private Methods
120

121
122     /**
123      * Initialize our set of users and home directories.
124      */

125     private void init() {
126
127         String JavaDoc homeBase = userConfig.getHomeBase();
128         File JavaDoc homeBaseDir = new File JavaDoc(homeBase);
129         if (!homeBaseDir.exists() || !homeBaseDir.isDirectory())
130             return;
131         String JavaDoc homeBaseFiles[] = homeBaseDir.list();
132
133         for (int i = 0; i < homeBaseFiles.length; i++) {
134             File JavaDoc homeDir = new File JavaDoc(homeBaseDir, homeBaseFiles[i]);
135             if (!homeDir.isDirectory() || !homeDir.canRead())
136                 continue;
137             homes.put(homeBaseFiles[i], homeDir.toString());
138         }
139
140
141     }
142
143
144 }
145
Popular Tags