changeset 18:1915c9c69129

Rename package.
author Mikhail Kryshen <mikhail@kryshen.net>
date Tue, 03 Nov 2009 03:42:30 +0300
parents 012d66bbc61f
children d3495301ca01
files dist/README src/kryshen/catalina/startup/HomesUserConfig.java src/kryshen/catalina/startup/PasswdUserConfig.java src/kryshen/catalina/startup/UserConfig.java src/kryshen/catalina/userconfig/HomesUserConfig.java src/kryshen/catalina/userconfig/PasswdUserConfig.java src/kryshen/catalina/userconfig/UserConfig.java
diffstat 7 files changed, 398 insertions(+), 398 deletions(-) [+]
line wrap: on
line diff
--- a/dist/README	Tue Nov 03 03:32:45 2009 +0300
+++ b/dist/README	Tue Nov 03 03:42:30 2009 +0300
@@ -15,11 +15,11 @@
 element in the Tomcat configuration file (server.xml).
 
 Listener that uses passwd database to list users:
-    <Listener className="kryshen.catalina.startup.PasswdUserConfig"/>
+    <Listener className="kryshen.catalina.userconfig.PasswdUserConfig"/>
 
 Listener that considers all home directories in the specified base
 directory:
-    <Listener className="kryshen.catalina.startup.HomesUserConfig"/>
+    <Listener className="kryshen.catalina.userconfig.HomesUserConfig"/>
 
 = Listener properties =
 
--- a/src/kryshen/catalina/startup/HomesUserConfig.java	Tue Nov 03 03:32:45 2009 +0300
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,78 +0,0 @@
-/*
- * Copyright 2009 Mikhail Kryshen
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *     http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package kryshen.catalina.startup;
-
-import java.io.File;
-import org.apache.juli.logging.LogFactory;
-
-/**
- * Event listener for Host that deploys and updates applications 
- * provided by users. Files in the specified base directory are 
- * considered tp be user home directories.
- *
- * @author Mikhail Kryshen
- */
-public class HomesUserConfig extends UserConfig {
-
-    /**
-     * The base directory containing user home directories.
-     */
-    private String homeBase = "/home";
-
-
-    public HomesUserConfig() {
-        log = LogFactory.getLog(HomesUserConfig.class);
-    }
-
-    /**
-     * Return the base directory containing user home directories.
-     */
-    public String getHomeBase() {
-        return homeBase;
-    }
-
-    /**
-     * Set the base directory containing user home directories.
-     *
-     * @param homeBase The new base directory
-     */
-    public void setHomeBase(String homeBase) {
-        this.homeBase = homeBase;
-    }
-
-    @Override
-    protected void deployUserApps() {
-        File homeBaseFile = new File(homeBase);
-
-        if (!homeBaseFile.isDirectory()) {
-            log.error("Invalid home base.");
-            return;
-        }
-
-        String[] homes = homeBaseFile.list();
-
-        for (String name : homes) {
-            File home = new File(homeBaseFile, name);
-            
-            if (!home.isDirectory() /* || !home.canExecute() */) {
-                continue;
-            }
-
-            deployUserApps(name, home);
-        }
-    }
-}
--- a/src/kryshen/catalina/startup/PasswdUserConfig.java	Tue Nov 03 03:32:45 2009 +0300
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,126 +0,0 @@
-/*
- * Copyright 2009 Mikhail Kryshen
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *     http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package kryshen.catalina.startup;
-
-import java.io.BufferedReader;
-import java.io.File;
-import java.io.FileReader;
-import java.io.IOException;
-import java.io.InputStreamReader;
-import java.util.regex.Pattern;
-import org.apache.juli.logging.LogFactory;
-
-/**
- * Event listener for Host that deploys and updates applications 
- * provided by users listed in passwd database.
- *
- * @author Mikhail Kryshen
- */
-public class PasswdUserConfig extends UserConfig {
-
-    private static final String PASSWD_DATABASE = "passwd";
-
-    /* Passwd format details. */
-    private static final Pattern PASSWD_SPLIT_PATTERN = Pattern.compile(":");
-    private static final int PASSWD_FIELD_USERNAME = 0;
-    private static final int PASSWD_FIELD_HOME = 5;
-
-    /**
-     * Command for retrieving passwd database.
-     */
-    private String getent = null;
-
-    /**
-     * Path to local passwd file.
-     */
-    private String passwd = "/etc/passwd";
-
-    
-    public PasswdUserConfig() {
-        log = LogFactory.getLog(PasswdUserConfig.class);
-    }
-
-    /**
-     * Get command for retrieving passwd database.
-     */
-    public String getGetent() {
-        return getent;
-    }
-
-    /**
-     * Set command for retrieving passwd database.
-     */
-    public void setGetent(String getent) {
-        this.getent = getent;
-    }
-
-    /**
-     * Get path to local passwd file.
-     */
-    public String getPasswd() {
-        return passwd;
-    }
-
-    /**
-     * Set path to local passwd file.
-     */
-    public void setPasswd(String passwd) {
-        this.passwd = passwd;
-    }
-
-    @Override
-    protected void deployUserApps() {
-        BufferedReader in;
-
-        try {
-            if (getent == null) {
-                in = new BufferedReader(new FileReader(passwd));
-            } else {
-                Process process = Runtime.getRuntime().exec(
-                       new String[] {getent, PASSWD_DATABASE});
-
-                in = new BufferedReader(
-                        new InputStreamReader(process.getInputStream()));
-            }
-
-            String line;
-
-            try {
-                while ((line = in.readLine()) != null) {
-                    String[] fields = PASSWD_SPLIT_PATTERN.split(line);
-
-                    String name = fields[PASSWD_FIELD_USERNAME];
-                    File home = new File(fields[PASSWD_FIELD_HOME]);
-
-                    if (!home.isDirectory()) {
-                        //log.warn("Invalid home directory for user "
-                        //        + name + ": " + home.getPath() + ".");
-                        continue;
-                    }
-
-                    deployUserApps(name, home);
-                }
-            } finally {
-                in.close();
-            }
-        } catch (IOException e) {
-            log.error("Error reading passwd database.", e);
-        } catch (ArrayIndexOutOfBoundsException e) {
-            log.error("Invalid passwd format.", e);
-        }
-    }
-}
--- a/src/kryshen/catalina/startup/UserConfig.java	Tue Nov 03 03:32:45 2009 +0300
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,192 +0,0 @@
-/*
- * Copyright 2009 Mikhail Kryshen
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *     http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package kryshen.catalina.startup;
-
-import java.io.File;
-import org.apache.catalina.startup.HostConfig;
-import org.apache.juli.logging.LogFactory;
-
-/**
- * Event listener for Host that deploys and updates applications
- * provided by users. In multi-app mode (appsPerUser property &gt 1)
- * each user's application is mapped to "/~username/application" path,
- * ROOT is mapped to "/~username". In single-app mode (appsPerUser = 1)
- * each user could have single webapp mapped to "/~username".
- *
- * @author Mikhail Kryshen
- */
-public abstract class UserConfig extends HostConfig {
-
-    /**
-     * The directory name to be searched for within each user home directory.
-     */
-    private String directoryName = "public_webapps";
-
-    /**
-     * Maximum number of application each user is allowed to deploy.
-     */
-    private int appsPerUser = -1;
-
-
-    protected UserConfig() {
-        log = LogFactory.getLog(UserConfig.class);
-    }
-
-    /**
-     *  Returns the directory name to be searched for webapps for each user
-     *  (relative to the user's home direcotry).
-     */
-    public String getDirectoryName() {
-        return directoryName;
-    }
-
-    /**
-     *  Set the directory name to be searched for webapps for each user
-     *  (relative to the user's home direcotry).
-     * 
-     * @param directoryName The new directory name.
-     */
-    public void setDirectoryName(String directoryName) {
-        this.directoryName = directoryName;
-    }
-
-    
-    /**
-     * Returns the maximum number of application each user is allowed to
-     * deploy.
-     */
-    public int getAppsPerUser() {
-        return appsPerUser;
-    }
-
-    /**
-     * Set the maximum number of application each user is allowed to deploy.
-     */
-    public void setAppsPerUser(int appsPerUser) {
-        if (appsPerUser < 1 && appsPerUser != -1) {
-            throw new IllegalArgumentException("Invalid appsPerUser value.");
-        }
-
-        this.appsPerUser = appsPerUser;
-    }
-
-
-    @Override
-    protected void deployApps() {       
-        deployUserApps();
-    }
-
-    @Override
-    protected void deployApps(String name) {
-        throw new UnsupportedOperationException
-                ("deployApps(String) is not supported.");
-    }
-
-    /**
-     * Deploy applications for all available users.
-     */
-    protected abstract void deployUserApps();
-
-    /**
-     * Deploy applications (if any) for specific user.
-     *
-     * @param user Username.
-     * @param home User home directory.
-     */
-    protected void deployUserApps(String user, File home) {
-        File base = new File(home, directoryName);
-
-        if (!base.isDirectory() || !base.canRead()) {
-            return;
-        }
-
-        String[] files = base.list();
-
-        if (files == null) {
-            log.warn("Error reading base directory: " + base.getPath() + ".");
-            return;
-        }
-
-        // TODO: deployWars
-
-        if (appsPerUser == 1) {
-            // Single application mode.
-            deployUserApp(user, base, "ROOT");
-        } else {
-            // Multiple applications mode.
-            deployUserDirectories(user, base, files);
-        }
-    }
-
-    /**
-     * Deploy user application directories.
-     *
-     * @param user Username.
-     * @param base Application base directory.
-     * @param files Array of directories to deploy.
-     */
-    protected void deployUserDirectories(String user, File base, 
-            String[] files) {
-
-        int appsNum = files.length;
-
-        if (appsNum > appsPerUser) {
-            appsNum = appsPerUser;
-        }
-
-        for (int i = 0; i < appsNum; i++) {
-            if (files[i].equalsIgnoreCase("META-INF")) {
-                continue;
-            }
-
-            if (files[i].equalsIgnoreCase("WEB-INF")) {
-                continue;
-            }
-
-            File dir = new File(base, files[i]);
-
-            if (!dir.isDirectory() || !dir.canRead()) {
-                continue;
-            }
-
-            deployUserApp(user, dir, files[i]);
-        }
-    }
-
-    /**
-     * Deploy user application.
-     *
-     * @param user Username.
-     * @param dir Application directory.
-     * @param app Application name.
-     */
-    protected void deployUserApp(String user, File dir, String app) {
-        String contextPath;
-
-        if (app.equals("ROOT")) {
-            contextPath = "/~" + user;
-        } else {
-            contextPath = "/~" + user + '/' + app.replace('#', '/');
-        }
-
-        if (isServiced(contextPath)) {
-            return;
-        }
-
-        deployDirectory(contextPath, dir, dir.getAbsolutePath());
-    }
-}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/kryshen/catalina/userconfig/HomesUserConfig.java	Tue Nov 03 03:42:30 2009 +0300
@@ -0,0 +1,78 @@
+/*
+ * Copyright 2009 Mikhail Kryshen
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package kryshen.catalina.userconfig;
+
+import java.io.File;
+import org.apache.juli.logging.LogFactory;
+
+/**
+ * Event listener for Host that deploys and updates applications 
+ * provided by users. Files in the specified base directory are 
+ * considered tp be user home directories.
+ *
+ * @author Mikhail Kryshen
+ */
+public class HomesUserConfig extends UserConfig {
+
+    /**
+     * The base directory containing user home directories.
+     */
+    private String homeBase = "/home";
+
+
+    public HomesUserConfig() {
+        log = LogFactory.getLog(HomesUserConfig.class);
+    }
+
+    /**
+     * Return the base directory containing user home directories.
+     */
+    public String getHomeBase() {
+        return homeBase;
+    }
+
+    /**
+     * Set the base directory containing user home directories.
+     *
+     * @param homeBase The new base directory
+     */
+    public void setHomeBase(String homeBase) {
+        this.homeBase = homeBase;
+    }
+
+    @Override
+    protected void deployUserApps() {
+        File homeBaseFile = new File(homeBase);
+
+        if (!homeBaseFile.isDirectory()) {
+            log.error("Invalid home base.");
+            return;
+        }
+
+        String[] homes = homeBaseFile.list();
+
+        for (String name : homes) {
+            File home = new File(homeBaseFile, name);
+            
+            if (!home.isDirectory() /* || !home.canExecute() */) {
+                continue;
+            }
+
+            deployUserApps(name, home);
+        }
+    }
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/kryshen/catalina/userconfig/PasswdUserConfig.java	Tue Nov 03 03:42:30 2009 +0300
@@ -0,0 +1,126 @@
+/*
+ * Copyright 2009 Mikhail Kryshen
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package kryshen.catalina.userconfig;
+
+import java.io.BufferedReader;
+import java.io.File;
+import java.io.FileReader;
+import java.io.IOException;
+import java.io.InputStreamReader;
+import java.util.regex.Pattern;
+import org.apache.juli.logging.LogFactory;
+
+/**
+ * Event listener for Host that deploys and updates applications 
+ * provided by users listed in passwd database.
+ *
+ * @author Mikhail Kryshen
+ */
+public class PasswdUserConfig extends UserConfig {
+
+    private static final String PASSWD_DATABASE = "passwd";
+
+    /* Passwd format details. */
+    private static final Pattern PASSWD_SPLIT_PATTERN = Pattern.compile(":");
+    private static final int PASSWD_FIELD_USERNAME = 0;
+    private static final int PASSWD_FIELD_HOME = 5;
+
+    /**
+     * Command for retrieving passwd database.
+     */
+    private String getent = null;
+
+    /**
+     * Path to local passwd file.
+     */
+    private String passwd = "/etc/passwd";
+
+    
+    public PasswdUserConfig() {
+        log = LogFactory.getLog(PasswdUserConfig.class);
+    }
+
+    /**
+     * Get command for retrieving passwd database.
+     */
+    public String getGetent() {
+        return getent;
+    }
+
+    /**
+     * Set command for retrieving passwd database.
+     */
+    public void setGetent(String getent) {
+        this.getent = getent;
+    }
+
+    /**
+     * Get path to local passwd file.
+     */
+    public String getPasswd() {
+        return passwd;
+    }
+
+    /**
+     * Set path to local passwd file.
+     */
+    public void setPasswd(String passwd) {
+        this.passwd = passwd;
+    }
+
+    @Override
+    protected void deployUserApps() {
+        BufferedReader in;
+
+        try {
+            if (getent == null) {
+                in = new BufferedReader(new FileReader(passwd));
+            } else {
+                Process process = Runtime.getRuntime().exec(
+                       new String[] {getent, PASSWD_DATABASE});
+
+                in = new BufferedReader(
+                        new InputStreamReader(process.getInputStream()));
+            }
+
+            String line;
+
+            try {
+                while ((line = in.readLine()) != null) {
+                    String[] fields = PASSWD_SPLIT_PATTERN.split(line);
+
+                    String name = fields[PASSWD_FIELD_USERNAME];
+                    File home = new File(fields[PASSWD_FIELD_HOME]);
+
+                    if (!home.isDirectory()) {
+                        //log.warn("Invalid home directory for user "
+                        //        + name + ": " + home.getPath() + ".");
+                        continue;
+                    }
+
+                    deployUserApps(name, home);
+                }
+            } finally {
+                in.close();
+            }
+        } catch (IOException e) {
+            log.error("Error reading passwd database.", e);
+        } catch (ArrayIndexOutOfBoundsException e) {
+            log.error("Invalid passwd format.", e);
+        }
+    }
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/kryshen/catalina/userconfig/UserConfig.java	Tue Nov 03 03:42:30 2009 +0300
@@ -0,0 +1,192 @@
+/*
+ * Copyright 2009 Mikhail Kryshen
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package kryshen.catalina.userconfig;
+
+import java.io.File;
+import org.apache.catalina.startup.HostConfig;
+import org.apache.juli.logging.LogFactory;
+
+/**
+ * Event listener for Host that deploys and updates applications
+ * provided by users. In multi-app mode (appsPerUser property &gt 1)
+ * each user's application is mapped to "/~username/application" path,
+ * ROOT is mapped to "/~username". In single-app mode (appsPerUser = 1)
+ * each user could have single webapp mapped to "/~username".
+ *
+ * @author Mikhail Kryshen
+ */
+public abstract class UserConfig extends HostConfig {
+
+    /**
+     * The directory name to be searched for within each user home directory.
+     */
+    private String directoryName = "public_webapps";
+
+    /**
+     * Maximum number of application each user is allowed to deploy.
+     */
+    private int appsPerUser = -1;
+
+
+    protected UserConfig() {
+        log = LogFactory.getLog(UserConfig.class);
+    }
+
+    /**
+     *  Returns the directory name to be searched for webapps for each user
+     *  (relative to the user's home direcotry).
+     */
+    public String getDirectoryName() {
+        return directoryName;
+    }
+
+    /**
+     *  Set the directory name to be searched for webapps for each user
+     *  (relative to the user's home direcotry).
+     * 
+     * @param directoryName The new directory name.
+     */
+    public void setDirectoryName(String directoryName) {
+        this.directoryName = directoryName;
+    }
+
+    
+    /**
+     * Returns the maximum number of application each user is allowed to
+     * deploy.
+     */
+    public int getAppsPerUser() {
+        return appsPerUser;
+    }
+
+    /**
+     * Set the maximum number of application each user is allowed to deploy.
+     */
+    public void setAppsPerUser(int appsPerUser) {
+        if (appsPerUser < 1 && appsPerUser != -1) {
+            throw new IllegalArgumentException("Invalid appsPerUser value.");
+        }
+
+        this.appsPerUser = appsPerUser;
+    }
+
+
+    @Override
+    protected void deployApps() {       
+        deployUserApps();
+    }
+
+    @Override
+    protected void deployApps(String name) {
+        throw new UnsupportedOperationException
+                ("deployApps(String) is not supported.");
+    }
+
+    /**
+     * Deploy applications for all available users.
+     */
+    protected abstract void deployUserApps();
+
+    /**
+     * Deploy applications (if any) for specific user.
+     *
+     * @param user Username.
+     * @param home User home directory.
+     */
+    protected void deployUserApps(String user, File home) {
+        File base = new File(home, directoryName);
+
+        if (!base.isDirectory() || !base.canRead()) {
+            return;
+        }
+
+        String[] files = base.list();
+
+        if (files == null) {
+            log.warn("Error reading base directory: " + base.getPath() + ".");
+            return;
+        }
+
+        // TODO: deployWars
+
+        if (appsPerUser == 1) {
+            // Single application mode.
+            deployUserApp(user, base, "ROOT");
+        } else {
+            // Multiple applications mode.
+            deployUserDirectories(user, base, files);
+        }
+    }
+
+    /**
+     * Deploy user application directories.
+     *
+     * @param user Username.
+     * @param base Application base directory.
+     * @param files Array of directories to deploy.
+     */
+    protected void deployUserDirectories(String user, File base, 
+            String[] files) {
+
+        int appsNum = files.length;
+
+        if (appsNum > appsPerUser) {
+            appsNum = appsPerUser;
+        }
+
+        for (int i = 0; i < appsNum; i++) {
+            if (files[i].equalsIgnoreCase("META-INF")) {
+                continue;
+            }
+
+            if (files[i].equalsIgnoreCase("WEB-INF")) {
+                continue;
+            }
+
+            File dir = new File(base, files[i]);
+
+            if (!dir.isDirectory() || !dir.canRead()) {
+                continue;
+            }
+
+            deployUserApp(user, dir, files[i]);
+        }
+    }
+
+    /**
+     * Deploy user application.
+     *
+     * @param user Username.
+     * @param dir Application directory.
+     * @param app Application name.
+     */
+    protected void deployUserApp(String user, File dir, String app) {
+        String contextPath;
+
+        if (app.equals("ROOT")) {
+            contextPath = "/~" + user;
+        } else {
+            contextPath = "/~" + user + '/' + app.replace('#', '/');
+        }
+
+        if (isServiced(contextPath)) {
+            return;
+        }
+
+        deployDirectory(contextPath, dir, dir.getAbsolutePath());
+    }
+}