diff --git a/INSTALL.md b/INSTALL.md
index d7a1011..9384e32 100644
--- a/INSTALL.md
+++ b/INSTALL.md
@@ -28,6 +28,13 @@ Building and Configuring Your Vault:
$ mvn package
~~~
+By default, the Tomcat major version this tool builds against is Tomcat 9 (exact version is specified in the `pom.xml` file). If you wish to build with a different exact version, please update the file accordingly and then add the appropriate `-Pprofile-name` command line argument to the command if you are targeting a different Tomcat major version. For example, if you wish to build for Tomcat 10, you would run:
+
+ ~~~
+ $ mvn package -Ptomcat-10
+ ~~~
+
+
3. Copy the generated tomcat-vault JAR to `$CATALINA_BASE/lib/`:
~~~
diff --git a/pom.xml b/pom.xml
index 4ccaa51..a7bd33c 100644
--- a/pom.xml
+++ b/pom.xml
@@ -10,11 +10,39 @@
Vault extension for Apache Tomcat
- 9.0.76
- 1.8
- 1.8
+ 3.5.3
+
+
+ tomcat-85
+
+ 8.5.100
+ 1.8
+ 1.8
+
+
+
+ tomcat-9
+
+ true
+
+
+ 9.0.105
+ 1.8
+ 1.8
+
+
+
+ tomcat-10
+
+ 10.1.41
+ 21
+ 21
+
+
+
+
org.apache.tomcat
@@ -68,7 +96,7 @@
org.apache.maven.pluginsmaven-surefire-plugin
- 3.0.0-M5
+ ${maven.surefire.plugin.version}false
diff --git a/src/main/java/org/apache/tomcat/vault/security/ExternalPasswordCache.java b/src/main/java/org/apache/tomcat/vault/security/ExternalPasswordCache.java
index 6cbb5e1..4a427e6 100644
--- a/src/main/java/org/apache/tomcat/vault/security/ExternalPasswordCache.java
+++ b/src/main/java/org/apache/tomcat/vault/security/ExternalPasswordCache.java
@@ -1,24 +1,24 @@
/*
-* JBoss, Home of Professional Open Source
-* Copyright 2005, JBoss Inc., and individual contributors as indicated
-* by the @authors tag. See the copyright.txt in the distribution for a
-* full listing of individual contributors.
-*
-* This is free software; you can redistribute it and/or modify it
-* under the terms of the GNU Lesser General Public License as
-* published by the Free Software Foundation; either version 2.1 of
-* the License, or (at your option) any later version.
-*
-* This software is distributed in the hope that it will be useful,
-* but WITHOUT ANY WARRANTY; without even the implied warranty of
-* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-* Lesser General Public License for more details.
-*
-* You should have received a copy of the GNU Lesser General Public
-* License along with this software; if not, write to the Free
-* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
-* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
-*/
+ * JBoss, Home of Professional Open Source
+ * Copyright 2005, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
package org.apache.tomcat.vault.security;
@@ -60,10 +60,6 @@ private ExternalPasswordCache() {
}
public static ExternalPasswordCache getExternalPasswordCacheInstance() {
- SecurityManager sm = System.getSecurityManager();
- if (sm != null) {
- sm.checkPermission(new RuntimePermission(ExternalPasswordCache.class.getName() + ".getExternalPasswordCacheInstance"));
- }
return PASSWORD_CACHE;
}
@@ -131,13 +127,9 @@ public void reset() {
log.trace(sm.getString("externalPasswordCache.resettingCache"));
cache.clear();
}
-
-
}
class PasswordRecord {
-
long timeOut;
char[] password;
-
-}
+}
\ No newline at end of file
diff --git a/src/main/java/org/apache/tomcat/vault/security/Util.java b/src/main/java/org/apache/tomcat/vault/security/Util.java
index e5890c2..019620c 100644
--- a/src/main/java/org/apache/tomcat/vault/security/Util.java
+++ b/src/main/java/org/apache/tomcat/vault/security/Util.java
@@ -29,9 +29,6 @@
import java.io.BufferedReader;
import java.io.InputStream;
import java.io.InputStreamReader;
-import java.security.AccessController;
-import java.security.PrivilegedActionException;
-import java.security.PrivilegedExceptionAction;
import java.security.Provider;
import java.security.Security;
import java.util.StringTokenizer;
@@ -71,12 +68,7 @@ public class Util {
* @return the password characters
* @throws Exception
*/
- public static char[] loadPassword(String passwordCmd)
- throws Exception {
- SecurityManager sm = System.getSecurityManager();
- if (sm != null) {
- sm.checkPermission(new RuntimePermission(Util.class.getName() + ".loadPassword"));
- }
+ public static char[] loadPassword(String passwordCmd) throws Exception {
char[] password = null;
String passwordCmdType = null;
@@ -150,14 +142,7 @@ private static char[] execPasswordCmd(String passwordCmd)
}
private static String execCmd(String cmd) throws Exception {
- SecurityManager sm = System.getSecurityManager();
- String line;
- if (sm != null) {
- line = RuntimeActions.PRIVILEGED.execCmd(cmd);
- } else {
- line = RuntimeActions.NON_PRIVILEGED.execCmd(cmd);
- }
- return line;
+ return RuntimeActions.execCmd(cmd);
}
/**
@@ -170,108 +155,65 @@ private static String execCmd(String cmd) throws Exception {
*/
private static char[] execPBBasedPasswordCommand(String passwordCmd) throws Exception {
log.trace(strm.getString("util.beginExecPasswordCmd", passwordCmd));
- SecurityManager sm = System.getSecurityManager();
- String password;
- if (sm != null) {
- password = RuntimeActions.PB_BASED_PRIVILEGED.execCmd(passwordCmd);
- } else {
- password = RuntimeActions.PB_BASED_NON_PRIVILEGED.execCmd(passwordCmd);
- }
+ String password = RuntimeActions.execPBBasedCmd(passwordCmd);
return password.toCharArray();
}
+ /**
+ * Simplified RuntimeActions - removed privileged variants
+ */
+ static class RuntimeActions {
- interface RuntimeActions {
- RuntimeActions PRIVILEGED = new RuntimeActions() {
- public String execCmd(final String cmd)
- throws Exception {
- try {
- String line = AccessController.doPrivileged(
- new PrivilegedExceptionAction() {
- public String run() throws Exception {
- return NON_PRIVILEGED.execCmd(cmd);
- }
- }
- );
- return line;
- } catch (PrivilegedActionException e) {
- throw e.getException();
- }
+ public static String execCmd(final String cmd) throws Exception {
+ Runtime rt = Runtime.getRuntime();
+ Process p = rt.exec(cmd);
+ InputStream stdin = null;
+ String line;
+ BufferedReader reader = null;
+ try {
+ stdin = p.getInputStream();
+ reader = new BufferedReader(new InputStreamReader(stdin));
+ line = reader.readLine();
+ } finally {
+ if (reader != null)
+ reader.close();
+ if (stdin != null)
+ stdin.close();
}
- };
- RuntimeActions NON_PRIVILEGED = new RuntimeActions() {
- public String execCmd(final String cmd)
- throws Exception {
- Runtime rt = Runtime.getRuntime();
- Process p = rt.exec(cmd);
- InputStream stdin = null;
- String line;
- BufferedReader reader = null;
- try {
- stdin = p.getInputStream();
- reader = new BufferedReader(new InputStreamReader(stdin));
- line = reader.readLine();
- } finally {
- if (reader != null)
- reader.close();
- if (stdin != null)
- stdin.close();
- }
- int exitCode = p.waitFor();
- log.trace(strm.getString("util.endExecPasswordCmd", exitCode));
- return line;
- }
- };
- RuntimeActions PB_BASED_PRIVILEGED = new RuntimeActions() {
- public String execCmd(final String command)
- throws Exception {
- try {
- String password = AccessController.doPrivileged(
- new PrivilegedExceptionAction() {
- public String run() throws Exception {
- return PB_BASED_NON_PRIVILEGED.execCmd(command);
- }
- }
- );
- return password;
- } catch (PrivilegedActionException e) {
- throw e.getException();
- }
- }
- };
- RuntimeActions PB_BASED_NON_PRIVILEGED = new RuntimeActions() {
- public String execCmd(final String command) throws Exception {
- final String[] parsedCommand = parseCommand(command);
- final ProcessBuilder builder = new ProcessBuilder(parsedCommand);
- final Process process = builder.start();
- final String line;
- BufferedReader reader = null;
- try {
- reader = new BufferedReader(new InputStreamReader(process.getInputStream()));
- line = reader.readLine();
- } finally {
- if (reader != null)
- reader.close();
- }
+ int exitCode = p.waitFor();
+ log.trace(strm.getString("util.endExecPasswordCmd", exitCode));
+ return line;
+ }
- int exitCode = process.waitFor();
- log.trace(strm.getString("util.endExecPasswordCmd", exitCode));
- return line;
+ public static String execPBBasedCmd(final String command) throws Exception {
+ final String[] parsedCommand = parseCommand(command);
+ final ProcessBuilder builder = new ProcessBuilder(parsedCommand);
+ final Process process = builder.start();
+ final String line;
+ BufferedReader reader = null;
+ try {
+ reader = new BufferedReader(new InputStreamReader(process.getInputStream()));
+ line = reader.readLine();
+ } finally {
+ if (reader != null)
+ reader.close();
}
- protected String[] parseCommand(String command) {
- // comma can be backslashed
- final String[] parsedCommand = command.split("(? loadClass(final Class> clazz, final String fqn) {
- return AccessController.doPrivileged(new PrivilegedAction>() {
- public Class> run() {
- ClassLoader cl = clazz.getClassLoader();
- Class> loadedClass = null;
- try {
- loadedClass = cl.loadClass(fqn);
- } catch (ClassNotFoundException e) {
- }
- if (loadedClass == null) {
- try {
- loadedClass = Thread.currentThread().getContextClassLoader().loadClass(fqn);
- } catch (ClassNotFoundException e) {
- }
- }
- return loadedClass;
+ ClassLoader cl = clazz.getClassLoader();
+ Class> loadedClass = null;
+
+ // Try with the given class's classloader first
+ try {
+ loadedClass = cl.loadClass(fqn);
+ } catch (ClassNotFoundException e) {
+ // Ignore and try context classloader
+ }
+
+ // If not found, try with thread context classloader
+ if (loadedClass == null) {
+ try {
+ loadedClass = Thread.currentThread().getContextClassLoader().loadClass(fqn);
+ } catch (ClassNotFoundException e) {
+ // Ignore - will return null
}
- });
+ }
+ return loadedClass;
}
+ /**
+ * Load a class using the given classloader
+ *
+ * @param classLoader the classloader to use
+ * @param fqn the fully qualified name of the class to load
+ * @return the loaded class, or null if not found
+ */
static Class> loadClass(final ClassLoader classLoader, final String fqn) {
- return AccessController.doPrivileged(new PrivilegedAction>() {
- public Class> run() {
- try {
- return classLoader.loadClass(fqn);
- } catch (ClassNotFoundException e) {
- }
- return null;
- }
- });
+ try {
+ return classLoader.loadClass(fqn);
+ } catch (ClassNotFoundException e) {
+ return null;
+ }
}
-}
+}
\ No newline at end of file
diff --git a/src/main/java/org/apache/tomcat/vault/security/vault/SecurityVaultData.java b/src/main/java/org/apache/tomcat/vault/security/vault/SecurityVaultData.java
index 229a717..56d1501 100644
--- a/src/main/java/org/apache/tomcat/vault/security/vault/SecurityVaultData.java
+++ b/src/main/java/org/apache/tomcat/vault/security/vault/SecurityVaultData.java
@@ -72,7 +72,7 @@ public SecurityVaultData() {
* @throws IOException
*/
private void writeObject(ObjectOutputStream oos) throws IOException {
- oos.writeObject(new Integer(VERSION));
+ oos.writeObject(Integer.valueOf(VERSION));
oos.writeObject(vaultData);
}
diff --git a/src/main/java/org/apache/tomcat/vault/security/vault/SecurityVaultFactory.java b/src/main/java/org/apache/tomcat/vault/security/vault/SecurityVaultFactory.java
index 926a547..47b72a1 100644
--- a/src/main/java/org/apache/tomcat/vault/security/vault/SecurityVaultFactory.java
+++ b/src/main/java/org/apache/tomcat/vault/security/vault/SecurityVaultFactory.java
@@ -60,10 +60,6 @@ public static SecurityVault get() throws SecurityVaultException {
* @throws SecurityVaultException
*/
public static SecurityVault get(String fqn) throws SecurityVaultException {
- SecurityManager sm = System.getSecurityManager();
- if (sm != null) {
- sm.checkPermission(new RuntimePermission(SecurityVaultFactory.class.getName() + ".get"));
- }
if (fqn == null)
return get();
@@ -98,10 +94,7 @@ public static SecurityVault get(ClassLoader classLoader, String fqn) throws Secu
if (fqn == null) {
throw new IllegalArgumentException(msm.getString("invalidNullArgument", "fqn"));
}
- SecurityManager sm = System.getSecurityManager();
- if (sm != null) {
- sm.checkPermission(new RuntimePermission(SecurityVaultFactory.class.getName() + ".get"));
- }
+
if (vault == null) {
Class> vaultClass = SecurityActions.loadClass(classLoader, fqn);
if (vaultClass == null)
@@ -120,4 +113,4 @@ public static SecurityVault get(ClassLoader classLoader, String fqn) throws Secu
private static void secondVaultInfo(String module, String className) {
log.warn(sm.getString("securityVaultFactory.attemptToCreateSecondVault", module != null ? className + " @ " + module : className));
}
-}
+}
\ No newline at end of file
diff --git a/src/main/java/org/apache/tomcat/vault/util/SecurityActions.java b/src/main/java/org/apache/tomcat/vault/util/SecurityActions.java
index 0b0884c..5eb2463 100644
--- a/src/main/java/org/apache/tomcat/vault/util/SecurityActions.java
+++ b/src/main/java/org/apache/tomcat/vault/util/SecurityActions.java
@@ -2,7 +2,7 @@
* JBoss, Home of Professional Open Source.
* Copyright 2008, Red Hat Middleware LLC, and individual contributors
* as indicated by the @author tags. See the copyright.txt file in the
- * distribution for a full listing of individual contributors.
+ * distribution for a full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
@@ -23,96 +23,86 @@
package org.apache.tomcat.vault.util;
import java.net.URL;
-import java.security.AccessController;
-import java.security.PrivilegedAction;
/**
- * Privileged Blocks
+ * Security Actions
*
* @author Anil.Saldhana@redhat.com
* @since Dec 9, 2008
*/
class SecurityActions {
+
+ /**
+ * Load a class using the given class's classloader, fallback to thread context classloader
+ *
+ * @param theClass the class to use for classloader lookup
+ * @param fqn the fully qualified name of the class to load
+ * @return the loaded class, or null if not found
+ */
static Class> loadClass(final Class> theClass, final String fqn) {
- return AccessController.doPrivileged(new PrivilegedAction>() {
- public Class> run() {
- ClassLoader classLoader = theClass.getClassLoader();
+ ClassLoader classLoader = theClass.getClassLoader();
- Class> clazz = loadClass(classLoader, fqn);
- if (clazz == null) {
- classLoader = Thread.currentThread().getContextClassLoader();
- clazz = loadClass(classLoader, fqn);
- }
- return clazz;
- }
- });
+ Class> clazz = loadClass(classLoader, fqn);
+ if (clazz == null) {
+ classLoader = Thread.currentThread().getContextClassLoader();
+ clazz = loadClass(classLoader, fqn);
+ }
+ return clazz;
}
+ /**
+ * Load a class using the given classloader
+ *
+ * @param cl the classloader to use
+ * @param fqn the fully qualified name of the class to load
+ * @return the loaded class, or null if not found
+ */
static Class> loadClass(final ClassLoader cl, final String fqn) {
- return AccessController.doPrivileged(new PrivilegedAction>() {
- public Class> run() {
- try {
- return cl.loadClass(fqn);
- } catch (ClassNotFoundException e) {
- }
- return null;
- }
- });
+ try {
+ return cl.loadClass(fqn);
+ } catch (ClassNotFoundException e) {
+ return null;
+ }
}
/**
* Set the system property
*
- * @param key
- * @param value
- * @return
+ * @param key the property key
+ * @param value the property value
*/
static void setSystemProperty(final String key, final String value) {
- AccessController.doPrivileged(new PrivilegedAction