changeset 2:d11df03af52a

Fixed version of HomeUserDatabase.
author Mikhail Kryshen <mikhail@kryshen.net>
date Fri, 30 Oct 2009 03:54:56 +0300
parents bd283605f2ae
children 3ab011b6e6e8
files src/kryshen/catalina/startup/HomesUserDatabase.java
diffstat 1 files changed, 145 insertions(+), 0 deletions(-) [+]
line diff
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/src/kryshen/catalina/startup/HomesUserDatabase.java	Fri Oct 30 03:54:56 2009 +0300
     1.3 @@ -0,0 +1,145 @@
     1.4 +/*
     1.5 + * Licensed to the Apache Software Foundation (ASF) under one or more
     1.6 + * contributor license agreements.  See the NOTICE file distributed with
     1.7 + * this work for additional information regarding copyright ownership.
     1.8 + * The ASF licenses this file to You under the Apache License, Version 2.0
     1.9 + * (the "License"); you may not use this file except in compliance with
    1.10 + * the License.  You may obtain a copy of the License at
    1.11 + * 
    1.12 + *      http://www.apache.org/licenses/LICENSE-2.0
    1.13 + * 
    1.14 + * Unless required by applicable law or agreed to in writing, software
    1.15 + * distributed under the License is distributed on an "AS IS" BASIS,
    1.16 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    1.17 + * See the License for the specific language governing permissions and
    1.18 + * limitations under the License.
    1.19 + */
    1.20 +
    1.21 +
    1.22 +package kryshen.catalina.startup;
    1.23 +
    1.24 +
    1.25 +import java.io.File;
    1.26 +import java.util.Hashtable;
    1.27 +import java.util.Enumeration;
    1.28 +import org.apache.catalina.startup.*;
    1.29 +
    1.30 +
    1.31 +/**
    1.32 + * Concrete implementation of the <strong>UserDatabase</code> interface
    1.33 + * considers all directories in a directory whose pathname is specified
    1.34 + * to our constructor to be "home" directories for those users.
    1.35 + *
    1.36 + * @author Craig R. McClanahan
    1.37 + * @version $Revision: 467222 $ $Date: 2006-10-24 05:17:11 +0200 (Tue, 24 Oct 2006) $
    1.38 + */
    1.39 +
    1.40 +public final class HomesUserDatabase
    1.41 +    implements UserDatabase {
    1.42 +
    1.43 +
    1.44 +    // --------------------------------------------------------- Constructors
    1.45 +
    1.46 +
    1.47 +    /**
    1.48 +     * Initialize a new instance of this user database component.
    1.49 +     */
    1.50 +    public HomesUserDatabase() {
    1.51 +
    1.52 +        super();
    1.53 +
    1.54 +    }
    1.55 +
    1.56 +
    1.57 +    // --------------------------------------------------- Instance Variables
    1.58 +
    1.59 +
    1.60 +    /**
    1.61 +     * The set of home directories for all defined users, keyed by username.
    1.62 +     */
    1.63 +    private Hashtable homes = new Hashtable();
    1.64 +
    1.65 +
    1.66 +    /**
    1.67 +     * The UserConfig listener with which we are associated.
    1.68 +     */
    1.69 +    private UserConfig userConfig = null;
    1.70 +
    1.71 +
    1.72 +    // ----------------------------------------------------------- Properties
    1.73 +
    1.74 +
    1.75 +    /**
    1.76 +     * Return the UserConfig listener with which we are associated.
    1.77 +     */
    1.78 +    public UserConfig getUserConfig() {
    1.79 +
    1.80 +        return (this.userConfig);
    1.81 +
    1.82 +    }
    1.83 +
    1.84 +
    1.85 +    /**
    1.86 +     * Set the UserConfig listener with which we are associated.
    1.87 +     *
    1.88 +     * @param userConfig The new UserConfig listener
    1.89 +     */
    1.90 +    public void setUserConfig(UserConfig userConfig) {
    1.91 +
    1.92 +        this.userConfig = userConfig;
    1.93 +        init();
    1.94 +
    1.95 +    }
    1.96 +
    1.97 +
    1.98 +    // ------------------------------------------------------- Public Methods
    1.99 +
   1.100 +
   1.101 +    /**
   1.102 +     * Return an absolute pathname to the home directory for the specified user.
   1.103 +     *
   1.104 +     * @param user User for which a home directory should be retrieved
   1.105 +     */
   1.106 +    public String getHome(String user) {
   1.107 +
   1.108 +        return ((String) homes.get(user));
   1.109 +
   1.110 +    }
   1.111 +
   1.112 +
   1.113 +    /**
   1.114 +     * Return an enumeration of the usernames defined on this server.
   1.115 +     */
   1.116 +    public Enumeration getUsers() {
   1.117 +
   1.118 +        return (homes.keys());
   1.119 +
   1.120 +    }
   1.121 +
   1.122 +
   1.123 +    // ------------------------------------------------------ Private Methods
   1.124 +
   1.125 +
   1.126 +    /**
   1.127 +     * Initialize our set of users and home directories.
   1.128 +     */
   1.129 +    private void init() {
   1.130 +
   1.131 +        String homeBase = userConfig.getHomeBase();
   1.132 +        File homeBaseDir = new File(homeBase);
   1.133 +        if (!homeBaseDir.exists() || !homeBaseDir.isDirectory())
   1.134 +            return;
   1.135 +        String homeBaseFiles[] = homeBaseDir.list();
   1.136 +
   1.137 +        for (int i = 0; i < homeBaseFiles.length; i++) {
   1.138 +            File homeDir = new File(homeBaseDir, homeBaseFiles[i]);
   1.139 +            if (!homeDir.isDirectory() || !homeDir.canExecute())
   1.140 +                continue;
   1.141 +            homes.put(homeBaseFiles[i], homeDir.toString());
   1.142 +        }
   1.143 +
   1.144 +
   1.145 +    }
   1.146 +
   1.147 +
   1.148 +}