changeset 8:ff1e55a2171f

Refactored.
author Mikhail Kryshen <mikhail@kryshen.net>
date Sun, 01 Nov 2009 05:41:39 +0300
parents ca0b81d28307
children a3321ea9b33f
files src/kryshen/catalina/startup/HomesUserConfig.java src/kryshen/catalina/startup/HomesUserDatabase.java src/kryshen/catalina/startup/PasswdUserConfig.java src/kryshen/catalina/startup/UserConfig.java src/kryshen/catalina/startup/UserDatabase.java
diffstat 5 files changed, 122 insertions(+), 248 deletions(-) [+]
line diff
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/src/kryshen/catalina/startup/HomesUserConfig.java	Sun Nov 01 05:41:39 2009 +0300
     1.3 @@ -0,0 +1,76 @@
     1.4 +/*
     1.5 + * To change this template, choose Tools | Templates
     1.6 + * and open the template in the editor.
     1.7 + */
     1.8 +
     1.9 +package kryshen.catalina.startup;
    1.10 +
    1.11 +import java.io.File;
    1.12 +
    1.13 +/**
    1.14 + *
    1.15 + * @author Mikhail Kryshen
    1.16 + */
    1.17 +public class HomesUserConfig extends UserConfig {
    1.18 +
    1.19 +    /**
    1.20 +     * The directory name to be searched for within each user home directory.
    1.21 +     */
    1.22 +    private String directoryName = "public_webapps";
    1.23 +    /**
    1.24 +     * The base directory containing user home directories.
    1.25 +     */
    1.26 +    private String homeBase = null;
    1.27 +
    1.28 +    public String getDirectoryName() {
    1.29 +        return directoryName;
    1.30 +    }
    1.31 +
    1.32 +    /**
    1.33 +     * Set the directory name for user web applications.
    1.34 +     *
    1.35 +     * @param directoryName The new directory name
    1.36 +     */
    1.37 +    public void setDirectoryName(String directoryName) {
    1.38 +        this.directoryName = directoryName;
    1.39 +    }
    1.40 +
    1.41 +    /**
    1.42 +     * Return the base directory containing user home directories.
    1.43 +     */
    1.44 +    public String getHomeBase() {
    1.45 +        return homeBase;
    1.46 +    }
    1.47 +
    1.48 +    /**
    1.49 +     * Set the base directory containing user home directories.
    1.50 +     *
    1.51 +     * @param homeBase The new base directory
    1.52 +     */
    1.53 +    public void setHomeBase(String homeBase) {
    1.54 +        this.homeBase = homeBase;
    1.55 +    }
    1.56 +
    1.57 +    @Override
    1.58 +    protected void deployUserApps() {
    1.59 +        File homeBaseFile = new File(homeBase);
    1.60 +
    1.61 +        if (!homeBaseFile.exists() || !homeBaseFile.isDirectory()) {
    1.62 +            host.getLogger().error("Invalid home base.");
    1.63 +            return;
    1.64 +        }
    1.65 +
    1.66 +        String[] homes = homeBaseFile.list();
    1.67 +
    1.68 +        for (String name : homes) {
    1.69 +            File home = new File(homeBaseFile, name);
    1.70 +            
    1.71 +            if (!home.isDirectory() /* || !home.canExecute() */) {
    1.72 +                continue;
    1.73 +            }
    1.74 +
    1.75 +            File base = new File(home, directoryName);
    1.76 +            deployUserApps(name, base);
    1.77 +        }
    1.78 +    }
    1.79 +}
     2.1 --- a/src/kryshen/catalina/startup/HomesUserDatabase.java	Sun Nov 01 04:25:39 2009 +0300
     2.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
     2.3 @@ -1,131 +0,0 @@
     2.4 -/*
     2.5 - * Licensed to the Apache Software Foundation (ASF) under one or more
     2.6 - * contributor license agreements.  See the NOTICE file distributed with
     2.7 - * this work for additional information regarding copyright ownership.
     2.8 - * The ASF licenses this file to You under the Apache License, Version 2.0
     2.9 - * (the "License"); you may not use this file except in compliance with
    2.10 - * the License.  You may obtain a copy of the License at
    2.11 - * 
    2.12 - *      http://www.apache.org/licenses/LICENSE-2.0
    2.13 - * 
    2.14 - * Unless required by applicable law or agreed to in writing, software
    2.15 - * distributed under the License is distributed on an "AS IS" BASIS,
    2.16 - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    2.17 - * See the License for the specific language governing permissions and
    2.18 - * limitations under the License.
    2.19 - */
    2.20 -
    2.21 -
    2.22 -package kryshen.catalina.startup;
    2.23 -
    2.24 -
    2.25 -import java.io.File;
    2.26 -import java.util.Collections;
    2.27 -import java.util.Iterator;
    2.28 -
    2.29 -/**
    2.30 - * Implementation of the <code>UserDatabase</code> interface
    2.31 - * lists all users by their home directories found in the specified
    2.32 - * base directory.
    2.33 - *
    2.34 - * @author Mikhail Kryshen
    2.35 - */
    2.36 -
    2.37 -public final class HomesUserDatabase implements UserDatabase {
    2.38 -
    2.39 -    /**
    2.40 -     * Iterates over users with accessible home directories.
    2.41 -     */
    2.42 -    private class UserIterator implements Iterator<User> {
    2.43 -        final File homeBase;
    2.44 -        final String[] homes;
    2.45 -
    2.46 -        User next;
    2.47 -        int index = 0;
    2.48 -
    2.49 -        UserIterator(File homeBase) {
    2.50 -            this.homeBase = homeBase;
    2.51 -            this.homes = homeBase.list();
    2.52 -
    2.53 -            findNext();
    2.54 -        }
    2.55 -
    2.56 -        /**
    2.57 -         * Find the next accessible home directory in the list and
    2.58 -         * create appropriate User to be returned by <code>next()</code>.
    2.59 -         */
    2.60 -        void findNext() {
    2.61 -            next = null;
    2.62 -
    2.63 -            while (next == null && index < homes.length) {
    2.64 -                final String name = homes[index];
    2.65 -                final File home = new File(homeBase, name);               
    2.66 -
    2.67 -                index++;
    2.68 -                
    2.69 -                if (!home.isDirectory() /* || !home.canExecute() */) {
    2.70 -                    continue;
    2.71 -                }
    2.72 -
    2.73 -                next = new User() {
    2.74 -                    public String getName() {
    2.75 -                        return name;
    2.76 -                    }
    2.77 -
    2.78 -                    public File getHome() {
    2.79 -                        return home;
    2.80 -                    }
    2.81 -                };                
    2.82 -            }
    2.83 -        }
    2.84 -
    2.85 -        public boolean hasNext() {
    2.86 -            return next != null;
    2.87 -        }
    2.88 -
    2.89 -        public User next() {
    2.90 -            User current = next;
    2.91 -            findNext();
    2.92 -            return current;
    2.93 -        }
    2.94 -
    2.95 -        public void remove() {
    2.96 -            throw new UnsupportedOperationException("Not supported.");
    2.97 -        }
    2.98 -    }
    2.99 -
   2.100 -    /**
   2.101 -     * The UserConfig listener with which we are associated.
   2.102 -     */
   2.103 -    private UserConfig userConfig = null;
   2.104 -
   2.105 -    /**
   2.106 -     * Return the UserConfig listener with which we are associated.
   2.107 -     */
   2.108 -    public UserConfig getUserConfig() {
   2.109 -        return (this.userConfig);
   2.110 -    }
   2.111 -
   2.112 -    /**
   2.113 -     * Set the UserConfig listener with which we are associated.
   2.114 -     *
   2.115 -     * @param userConfig The new UserConfig listener
   2.116 -     */
   2.117 -    public void setUserConfig(UserConfig userConfig) {
   2.118 -        this.userConfig = userConfig;
   2.119 -    }
   2.120 -
   2.121 -    /**
   2.122 -     * Returns Iterator for the list of users.
   2.123 -     */
   2.124 -    public Iterator<User> iterator() {
   2.125 -        File homeBase = new File(userConfig.getHomeBase());
   2.126 -
   2.127 -        if (!homeBase.exists() || !homeBase.isDirectory()) {
   2.128 -            // PENDING: throw Exception instead?
   2.129 -            return Collections.<User>emptyList().iterator();
   2.130 -        }
   2.131 -
   2.132 -        return new UserIterator(homeBase);
   2.133 -    }
   2.134 -}
     3.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     3.2 +++ b/src/kryshen/catalina/startup/PasswdUserConfig.java	Sun Nov 01 05:41:39 2009 +0300
     3.3 @@ -0,0 +1,40 @@
     3.4 +/*
     3.5 + * To change this template, choose Tools | Templates
     3.6 + * and open the template in the editor.
     3.7 + */
     3.8 +
     3.9 +package kryshen.catalina.startup;
    3.10 +
    3.11 +/**
    3.12 + *
    3.13 + * @author Mikhail Kryshen
    3.14 + */
    3.15 +public class PasswdUserConfig extends UserConfig {
    3.16 +
    3.17 +    private static final String PASSWD_DATABASE = "passwd";
    3.18 +
    3.19 +    /**
    3.20 +     * Command for retrieving passwd database.
    3.21 +     */
    3.22 +    private String getent = "getent";
    3.23 +
    3.24 +    /**
    3.25 +     * Get command for retrieving passwd database.
    3.26 +     */
    3.27 +    public String getGetent() {
    3.28 +        return getent;
    3.29 +    }
    3.30 +
    3.31 +    /**
    3.32 +     * Set command for retrieving passwd database.
    3.33 +     */
    3.34 +    public void setGetent(String getent) {
    3.35 +        this.getent = getent;
    3.36 +    }
    3.37 +
    3.38 +    @Override
    3.39 +    protected void deployUserApps() {
    3.40 +        // TODO
    3.41 +    }
    3.42 +
    3.43 +}
     4.1 --- a/src/kryshen/catalina/startup/UserConfig.java	Sun Nov 01 04:25:39 2009 +0300
     4.2 +++ b/src/kryshen/catalina/startup/UserConfig.java	Sun Nov 01 05:41:39 2009 +0300
     4.3 @@ -7,87 +7,11 @@
     4.4   *
     4.5   * @author Mikhail Kryshen
     4.6   */
     4.7 -public class UserConfig extends HostConfig {
     4.8 -
     4.9 -    /**
    4.10 -     * The directory name to be searched for within each user home directory.
    4.11 -     */
    4.12 -    private String directoryName = "public_webapps";
    4.13 -
    4.14 -    /**
    4.15 -     * The base directory containing user home directories.
    4.16 -     */
    4.17 -    private String homeBase = null;
    4.18 -
    4.19 -    /**
    4.20 -     * The Java class name of the user database class we should use.
    4.21 -     */
    4.22 -    private String userClass =
    4.23 -            "org.apache.catalina.startup.PasswdUserDatabase";
    4.24 -
    4.25 -    /**
    4.26 -     * Return the directory name for user web applications.
    4.27 -     */
    4.28 -    public String getDirectoryName() {
    4.29 -        return (this.directoryName);
    4.30 -    }
    4.31 -
    4.32 -    /**
    4.33 -     * Set the directory name for user web applications.
    4.34 -     *
    4.35 -     * @param directoryName The new directory name
    4.36 -     */
    4.37 -    public void setDirectoryName(String directoryName) {
    4.38 -        this.directoryName = directoryName;
    4.39 -    }
    4.40 -
    4.41 -    /**
    4.42 -     * Return the base directory containing user home directories.
    4.43 -     */
    4.44 -    public String getHomeBase() {
    4.45 -        return (this.homeBase);
    4.46 -    }
    4.47 -
    4.48 -    /**
    4.49 -     * Set the base directory containing user home directories.
    4.50 -     *
    4.51 -     * @param homeBase The new base directory
    4.52 -     */
    4.53 -    public void setHomeBase(String homeBase) {
    4.54 -        this.homeBase = homeBase;
    4.55 -    }
    4.56 -
    4.57 -    /** 
    4.58 -     * Return the user database class name for this component. 
    4.59 -     */
    4.60 -    public String getUserClass() {
    4.61 -        return (this.userClass);
    4.62 -    }
    4.63 -
    4.64 -    /** 
    4.65 -     * Set the user database class name for this component. 
    4.66 -     */
    4.67 -    public void setUserClass(String userClass) {
    4.68 -        this.userClass = userClass;
    4.69 -    }
    4.70 +public abstract class UserConfig extends HostConfig {
    4.71  
    4.72      @Override
    4.73      protected void deployApps() {       
    4.74 -        // Load the user database object for this host
    4.75 -        UserDatabase database = null;
    4.76 -        try {
    4.77 -            Class clazz = Class.forName(userClass);
    4.78 -            database = (UserDatabase) clazz.newInstance();
    4.79 -            database.setUserConfig(this);
    4.80 -        } catch (Exception e) {
    4.81 -            host.getLogger().error(sm.getString("userConfig.database"), e);
    4.82 -            return;
    4.83 -        }
    4.84 -
    4.85 -        // Deploy the web application (if any) for each defined user
    4.86 -        for (UserDatabase.User user : database) {
    4.87 -            deployUserApps(user.getName(), user.getHome());
    4.88 -        }
    4.89 +        deployUserApps();
    4.90      }
    4.91  
    4.92      @Override
    4.93 @@ -96,16 +20,15 @@
    4.94                  ("deployApps(String) is not supported.");
    4.95      }
    4.96  
    4.97 -    protected void deployUserApps(String user, File home) {
    4.98 -        File base = new File(home, directoryName);
    4.99 +    protected abstract void deployUserApps();
   4.100  
   4.101 +    protected void deployUserApps(String user, File base) {
   4.102          if (!base.exists() || !base.isDirectory() || !base.canRead()) {
   4.103              return;
   4.104          }
   4.105  
   4.106 -// TODO: deployWARs
   4.107 -//        // Deploy WARs, and loop if additional descriptors are found
   4.108 -//        deployWARs(appBase, appBase.list());
   4.109 +        // TODO: deployWARs
   4.110 +        // deployWARs(appBase, appBase.list());
   4.111  
   4.112          // Deploy expanded folders
   4.113          deployDirectories(user, base, base.list());
     5.1 --- a/src/kryshen/catalina/startup/UserDatabase.java	Sun Nov 01 04:25:39 2009 +0300
     5.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
     5.3 @@ -1,34 +0,0 @@
     5.4 -package kryshen.catalina.startup;
     5.5 -
     5.6 -import java.io.File;
     5.7 -import java.util.Iterator;
     5.8 -
     5.9 -/**
    5.10 - *
    5.11 - * @author Mikhail Kryshen
    5.12 - */
    5.13 -public interface UserDatabase extends Iterable<UserDatabase.User> {
    5.14 -
    5.15 -    interface User {
    5.16 -        String getName();
    5.17 -
    5.18 -        File getHome();
    5.19 -    }
    5.20 -
    5.21 -    /**
    5.22 -     * Return the UserConfig listener with which we are associated.
    5.23 -     */
    5.24 -    UserConfig getUserConfig();
    5.25 -
    5.26 -    /**
    5.27 -     * Set the UserConfig listener with which we are associated.
    5.28 -     *
    5.29 -     * @param userConfig The new UserConfig listener
    5.30 -     */
    5.31 -    void setUserConfig(UserConfig userConfig);
    5.32 -
    5.33 -    /**
    5.34 -     * Returns Iterator for the list of users.
    5.35 -     */
    5.36 -    Iterator<User> iterator();
    5.37 -}