e.g. Calendar Search Help
You must enter a value before pressing Search
tomcat

Class: org.apache.catalina.startup.HomesUserDatabase   ©

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

            
All Examples in File:
Example
Line
Rating (found
useful by...)
130 100% of 1