changeset 1:bd283605f2ae

First working version.
author Mikhail Kryshen <mikhail@kryshen.net>
date Thu, 29 Oct 2009 16:03:12 +0300
parents 006c54c8dfb8
children d11df03af52a
files nbproject/project.properties src/kryshen/catalina/startup/UserConfig2.java src/kryshen/catalina/userconfig/UserConfig.java
diffstat 3 files changed, 167 insertions(+), 17 deletions(-) [+]
line diff
     1.1 --- a/nbproject/project.properties	Wed Oct 28 17:03:05 2009 +0300
     1.2 +++ b/nbproject/project.properties	Thu Oct 29 16:03:12 2009 +0300
     1.3 @@ -24,10 +24,12 @@
     1.4  dist.javadoc.dir=${dist.dir}/javadoc
     1.5  excludes=
     1.6  file.reference.catalina.jar=${var.tomcat}/lib/catalina.jar
     1.7 +file.reference.tomcat-juli.jar=${var.tomcat}/bin/tomcat-juli.jar
     1.8  includes=**
     1.9  jar.compress=false
    1.10  javac.classpath=\
    1.11 -    ${file.reference.catalina.jar}
    1.12 +    ${file.reference.catalina.jar}:\
    1.13 +    ${file.reference.tomcat-juli.jar}
    1.14  # Space-separated list of extra javac options
    1.15  javac.compilerargs=
    1.16  javac.deprecation=false
     2.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     2.2 +++ b/src/kryshen/catalina/startup/UserConfig2.java	Thu Oct 29 16:03:12 2009 +0300
     2.3 @@ -0,0 +1,164 @@
     2.4 +package kryshen.catalina.startup;
     2.5 +
     2.6 +import java.io.File;
     2.7 +import java.util.Enumeration;
     2.8 +import org.apache.catalina.startup.UserDatabase;
     2.9 +import org.apache.catalina.startup.HostConfig;
    2.10 +import org.apache.catalina.startup.UserConfig;
    2.11 +
    2.12 +/**
    2.13 + *
    2.14 + * @author Mikhail Kryshen
    2.15 + */
    2.16 +public class UserConfig2 extends HostConfig {
    2.17 +
    2.18 +    /**
    2.19 +     * The directory name to be searched for within each user home directory.
    2.20 +     */
    2.21 +    private String directoryName = "public_webapps";
    2.22 +
    2.23 +    /**
    2.24 +     * The base directory containing user home directories.
    2.25 +     */
    2.26 +    private String homeBase = null;
    2.27 +
    2.28 +    /**
    2.29 +     * The Java class name of the user database class we should use.
    2.30 +     */
    2.31 +    private String userClass =
    2.32 +            "org.apache.catalina.startup.PasswdUserDatabase";
    2.33 +
    2.34 +    /**
    2.35 +     * UserConfig instance is required by UserDatabase.
    2.36 +     */
    2.37 +    private UserConfig userConfig = new UserConfig();
    2.38 +
    2.39 +    /**
    2.40 +     * Return the directory name for user web applications.
    2.41 +     */
    2.42 +    public String getDirectoryName() {
    2.43 +        return (this.directoryName);
    2.44 +    }
    2.45 +
    2.46 +    /**
    2.47 +     * Set the directory name for user web applications.
    2.48 +     *
    2.49 +     * @param directoryName The new directory name
    2.50 +     */
    2.51 +    public void setDirectoryName(String directoryName) {
    2.52 +        this.directoryName = directoryName;
    2.53 +        userConfig.setDirectoryName(directoryName);
    2.54 +    }
    2.55 +
    2.56 +    /**
    2.57 +     * Return the base directory containing user home directories.
    2.58 +     */
    2.59 +    public String getHomeBase() {
    2.60 +        return (this.homeBase);
    2.61 +    }
    2.62 +
    2.63 +    /**
    2.64 +     * Set the base directory containing user home directories.
    2.65 +     *
    2.66 +     * @param homeBase The new base directory
    2.67 +     */
    2.68 +    public void setHomeBase(String homeBase) {
    2.69 +        this.homeBase = homeBase;
    2.70 +        userConfig.setHomeBase(homeBase);
    2.71 +    }
    2.72 +
    2.73 +    /** 
    2.74 +     * Return the user database class name for this component. 
    2.75 +     */
    2.76 +    public String getUserClass() {
    2.77 +        return (this.userClass);
    2.78 +    }
    2.79 +
    2.80 +    /** 
    2.81 +     * Set the user database class name for this component. 
    2.82 +     */
    2.83 +    public void setUserClass(String userClass) {
    2.84 +        this.userClass = userClass;
    2.85 +        userConfig.setUserClass(userClass);
    2.86 +    }
    2.87 +
    2.88 +    @Override
    2.89 +    protected void deployApps() {       
    2.90 +        // Load the user database object for this host
    2.91 +        UserDatabase database = null;
    2.92 +        try {
    2.93 +            Class clazz = Class.forName(userClass);
    2.94 +            database = (UserDatabase) clazz.newInstance();
    2.95 +            database.setUserConfig(userConfig);
    2.96 +        } catch (Exception e) {
    2.97 +            host.getLogger().error(sm.getString("userConfig.database"), e);
    2.98 +            return;
    2.99 +        }
   2.100 +
   2.101 +        // Deploy the web application (if any) for each defined user
   2.102 +        Enumeration users = database.getUsers();
   2.103 +        while (users.hasMoreElements()) {
   2.104 +            String user = (String) users.nextElement();
   2.105 +            String home = database.getHome(user);
   2.106 +            deployUserApps(user, home);
   2.107 +        }
   2.108 +    }
   2.109 +
   2.110 +    @Override
   2.111 +    protected void deployApps(String name) {
   2.112 +        throw new UnsupportedOperationException
   2.113 +                ("deployApps(String) is not supported.");
   2.114 +    }
   2.115 +
   2.116 +    protected void deployUserApps(String user, String home) {
   2.117 +        File base = new File(home, directoryName);
   2.118 +
   2.119 +        if (!base.exists() || !base.isDirectory()) {
   2.120 +            return;
   2.121 +        }
   2.122 +
   2.123 +// TODO: deployWARs
   2.124 +//        // Deploy WARs, and loop if additional descriptors are found
   2.125 +//        deployWARs(appBase, appBase.list());
   2.126 +
   2.127 +        // Deploy expanded folders
   2.128 +        deployDirectories(user, base, base.list());
   2.129 +    }
   2.130 +
   2.131 +    /**
   2.132 +     * Deploy user webapp directories.
   2.133 +     */
   2.134 +    protected void deployDirectories(String user, File base, String[] files) {
   2.135 +
   2.136 +        if (files == null) {
   2.137 +            return;
   2.138 +        }
   2.139 +
   2.140 +        for (int i = 0; i < files.length; i++) {
   2.141 +            if (files[i].equalsIgnoreCase("META-INF")) {
   2.142 +                continue;
   2.143 +            }
   2.144 +
   2.145 +            if (files[i].equalsIgnoreCase("WEB-INF")) {
   2.146 +                continue;
   2.147 +            }
   2.148 +
   2.149 +            File dir = new File(base, files[i]);
   2.150 +            if (dir.isDirectory()) {
   2.151 +                String contextPath;
   2.152 +                
   2.153 +                if (files[i].equals("ROOT")) {
   2.154 +                    contextPath = "/~" + user;
   2.155 +                } else {
   2.156 +                    contextPath = "/~" + user + '/' + files[i].replace('#', '/');
   2.157 +                }
   2.158 +
   2.159 +                if (isServiced(contextPath)) {
   2.160 +                    continue;
   2.161 +                }
   2.162 +
   2.163 +                deployDirectory(contextPath, dir, dir.getAbsolutePath());
   2.164 +            }
   2.165 +        }
   2.166 +    }
   2.167 +}
     3.1 --- a/src/kryshen/catalina/userconfig/UserConfig.java	Wed Oct 28 17:03:05 2009 +0300
     3.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
     3.3 @@ -1,16 +0,0 @@
     3.4 -package kryshen.catalina.userconfig;
     3.5 -
     3.6 -import org.apache.catalina.LifecycleEvent;
     3.7 -import org.apache.catalina.LifecycleListener;
     3.8 -
     3.9 -/**
    3.10 - *
    3.11 - * @author Mikhail Kryshen
    3.12 - */
    3.13 -public class UserConfig implements LifecycleListener {
    3.14 -
    3.15 -    public void lifecycleEvent(LifecycleEvent event) {
    3.16 -        throw new UnsupportedOperationException("Not supported yet.");
    3.17 -    }
    3.18 -
    3.19 -}