Mercurial > hg > tomcat-userconfig
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 wrap: on
line diff
--- a/nbproject/project.properties Wed Oct 28 17:03:05 2009 +0300 +++ b/nbproject/project.properties Thu Oct 29 16:03:12 2009 +0300 @@ -24,10 +24,12 @@ dist.javadoc.dir=${dist.dir}/javadoc excludes= file.reference.catalina.jar=${var.tomcat}/lib/catalina.jar +file.reference.tomcat-juli.jar=${var.tomcat}/bin/tomcat-juli.jar includes=** jar.compress=false javac.classpath=\ - ${file.reference.catalina.jar} + ${file.reference.catalina.jar}:\ + ${file.reference.tomcat-juli.jar} # Space-separated list of extra javac options javac.compilerargs= javac.deprecation=false
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/kryshen/catalina/startup/UserConfig2.java Thu Oct 29 16:03:12 2009 +0300 @@ -0,0 +1,164 @@ +package kryshen.catalina.startup; + +import java.io.File; +import java.util.Enumeration; +import org.apache.catalina.startup.UserDatabase; +import org.apache.catalina.startup.HostConfig; +import org.apache.catalina.startup.UserConfig; + +/** + * + * @author Mikhail Kryshen + */ +public class UserConfig2 extends HostConfig { + + /** + * The directory name to be searched for within each user home directory. + */ + private String directoryName = "public_webapps"; + + /** + * The base directory containing user home directories. + */ + private String homeBase = null; + + /** + * The Java class name of the user database class we should use. + */ + private String userClass = + "org.apache.catalina.startup.PasswdUserDatabase"; + + /** + * UserConfig instance is required by UserDatabase. + */ + private UserConfig userConfig = new UserConfig(); + + /** + * Return the directory name for user web applications. + */ + public String getDirectoryName() { + return (this.directoryName); + } + + /** + * Set the directory name for user web applications. + * + * @param directoryName The new directory name + */ + public void setDirectoryName(String directoryName) { + this.directoryName = directoryName; + userConfig.setDirectoryName(directoryName); + } + + /** + * Return the base directory containing user home directories. + */ + public String getHomeBase() { + return (this.homeBase); + } + + /** + * Set the base directory containing user home directories. + * + * @param homeBase The new base directory + */ + public void setHomeBase(String homeBase) { + this.homeBase = homeBase; + userConfig.setHomeBase(homeBase); + } + + /** + * Return the user database class name for this component. + */ + public String getUserClass() { + return (this.userClass); + } + + /** + * Set the user database class name for this component. + */ + public void setUserClass(String userClass) { + this.userClass = userClass; + userConfig.setUserClass(userClass); + } + + @Override + protected void deployApps() { + // Load the user database object for this host + UserDatabase database = null; + try { + Class clazz = Class.forName(userClass); + database = (UserDatabase) clazz.newInstance(); + database.setUserConfig(userConfig); + } catch (Exception e) { + host.getLogger().error(sm.getString("userConfig.database"), e); + return; + } + + // Deploy the web application (if any) for each defined user + Enumeration users = database.getUsers(); + while (users.hasMoreElements()) { + String user = (String) users.nextElement(); + String home = database.getHome(user); + deployUserApps(user, home); + } + } + + @Override + protected void deployApps(String name) { + throw new UnsupportedOperationException + ("deployApps(String) is not supported."); + } + + protected void deployUserApps(String user, String home) { + File base = new File(home, directoryName); + + if (!base.exists() || !base.isDirectory()) { + return; + } + +// TODO: deployWARs +// // Deploy WARs, and loop if additional descriptors are found +// deployWARs(appBase, appBase.list()); + + // Deploy expanded folders + deployDirectories(user, base, base.list()); + } + + /** + * Deploy user webapp directories. + */ + protected void deployDirectories(String user, File base, String[] files) { + + if (files == null) { + return; + } + + for (int i = 0; i < files.length; 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()) { + String contextPath; + + if (files[i].equals("ROOT")) { + contextPath = "/~" + user; + } else { + contextPath = "/~" + user + '/' + files[i].replace('#', '/'); + } + + if (isServiced(contextPath)) { + continue; + } + + deployDirectory(contextPath, dir, dir.getAbsolutePath()); + } + } + } +}
--- a/src/kryshen/catalina/userconfig/UserConfig.java Wed Oct 28 17:03:05 2009 +0300 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,16 +0,0 @@ -package kryshen.catalina.userconfig; - -import org.apache.catalina.LifecycleEvent; -import org.apache.catalina.LifecycleListener; - -/** - * - * @author Mikhail Kryshen - */ -public class UserConfig implements LifecycleListener { - - public void lifecycleEvent(LifecycleEvent event) { - throw new UnsupportedOperationException("Not supported yet."); - } - -}