├── .gitignore
├── INSTALL.md
├── LICENSE
├── README.md
├── Using_Crypt.md
├── bin
├── vault.bat
└── vault.sh
├── examples
├── README.md
├── valve
│ ├── pom.xml
│ └── src
│ │ └── main
│ │ └── java
│ │ └── org
│ │ └── tomcat
│ │ └── example
│ │ └── MyValve.java
└── webapp
│ ├── pom.xml
│ └── src
│ └── main
│ ├── java
│ └── org
│ │ └── tomcat
│ │ └── example
│ │ ├── MyFilter.java
│ │ └── MyServlet.java
│ └── webapp
│ ├── META-INF
│ └── context.xml
│ ├── WEB-INF
│ └── web.xml
│ └── resources
│ └── examples.properties
├── pom.xml
└── src
├── main
├── java
│ └── org
│ │ └── apache
│ │ └── tomcat
│ │ └── vault
│ │ ├── VaultInteraction.java
│ │ ├── VaultInteractiveSession.java
│ │ ├── VaultSession.java
│ │ ├── VaultTool.java
│ │ ├── security
│ │ ├── Base64Utils.java
│ │ ├── ExternalPasswordCache.java
│ │ ├── PasswordCache.java
│ │ ├── Util.java
│ │ ├── plugins
│ │ │ └── PBEUtils.java
│ │ └── vault
│ │ │ ├── PicketBoxSecurityVault.java
│ │ │ ├── SecurityActions.java
│ │ │ ├── SecurityVault.java
│ │ │ ├── SecurityVaultData.java
│ │ │ ├── SecurityVaultException.java
│ │ │ └── SecurityVaultFactory.java
│ │ └── util
│ │ ├── EncryptionUtil.java
│ │ ├── KeyStoreUtil.java
│ │ ├── PropertyFileManager.java
│ │ ├── PropertySourceVault.java
│ │ ├── SecurityActions.java
│ │ └── StringUtil.java
└── resources
│ └── org
│ └── apache
│ └── tomcat
│ └── vault
│ └── security
│ ├── LocalStrings.properties
│ ├── plugins
│ └── LocalStrings.properties
│ ├── resources
│ └── LocalStrings.properties
│ └── vault
│ └── LocalStrings.properties
└── test
├── java
└── unit
│ └── org
│ └── apache
│ └── tomcat
│ └── vault
│ ├── VaultToolTest.java
│ └── util
│ └── EncryptionUtilTest.java
└── resources
└── mockito-extensions
└── org.mockito.plugins.MockMaker
/.gitignore:
--------------------------------------------------------------------------------
1 | modules/system/layers/base/tomcat-vault/main/tomcat-vault.jar
2 | lib
3 | bin/tomcat-juli.jar
4 | target
5 | .idea
6 | **/*.iml
7 | vault.properties
8 |
--------------------------------------------------------------------------------
/INSTALL.md:
--------------------------------------------------------------------------------
1 | PicketLink Vault extension for Apache Tomcat.
2 |
3 | See the LICENSE file distributed with this work for information
4 | regarding licensing.
5 |
6 | =====================================================================
7 |
8 | Requirements:
9 | -------------
10 |
11 | * Tomcat Vault tarball or source repository
12 | * Apache Tomcat
13 | * Apache Maven
14 |
15 | Prequisites:
16 | ------------
17 |
18 | Configure the `CATALINA_BASE` environment variable to point to your Tomcat installation's `CATALINA_BASE`.
19 |
20 | Building and Configuring Your Vault:
21 | ------------------------------------
22 |
23 | 1. Install Apache Tomcat (from an RPM, by hand, or however you prefer)
24 |
25 | 2. Compile Tomcat Vault from its source directory:
26 |
27 | ~~~
28 | $ mvn package
29 | ~~~
30 |
31 | 3. Copy the generated tomcat-vault JAR to `$CATALINA_BASE/lib/`:
32 |
33 | ~~~
34 | $ cp lib/tomcat-vault.jar $CATALINA_BASE/lib/
35 | ~~~
36 |
37 | 4. Add the following line to `$CATALINA_BASE/conf/catalina.properties` so that Tomcat's Digester uses the tomcat-vault PropertySource implementation:
38 |
39 | ~~~
40 | org.apache.tomcat.util.digester.PROPERTY_SOURCE=org.apache.tomcat.vault.util.PropertySourceVault
41 | org.apache.tomcat.util.digester.REPLACE_SYSTEM_PROPERTIES=true
42 | ~~~
43 |
44 | 5. Setup your Vault using `./bin/vault.sh`. Here is an example creating a keystore for the Vault and initializing it in `/tmp/vault`:
45 |
46 | ~~~
47 | # Make a directory for the Vault to live
48 | $ mkdir /tmp/vault
49 |
50 | # Create a keystore for the Vault
51 | $ keytool -genseckey -keystore /tmp/vault/vault.keystore -alias my_vault -storetype jceks -keyalg AES -keysize 128 -storepass my_password123 -keypass my_password123 -validity 730
52 |
53 | # Initialize the Vault and save vault.properties
54 | $ bin/vault.sh --keystore /tmp/vault/vault.keystore --keystore-password my_password123 --alias my_vault --enc-dir /tmp/vault/ --iteration 44 --salt 1234abcd -g $CATALINA_BASE/conf/vault.properties
55 | ~~~
56 |
57 | **Note:** When creating a keystore with keytool the storepass and keypass argument values must match.
58 |
59 | **Note:** You can also initialize the Vault in an interactive mode by executing bin/vault.sh with no arguments. If you do this, then you will need to create a file named vault.properties in `$CATALINA_BASE/conf` containing your Vault information as below (all of these keys must be defined and **NOT** empty). This information is provided by the interactive session at the end of the initialization.
60 |
61 | ~~~
62 | KEYSTORE_URL=..
63 | KEYSTORE_PASSWORD=..
64 | KEYSTORE_ALIAS=..
65 | SALT=..
66 | ITERATION_COUNT=..
67 | ENC_FILE_DIR=..
68 | ~~~
69 |
70 | 7. Start Apache Tomcat!
71 |
72 | Using Your New Vault:
73 | ---------------------
74 |
75 | Now that the Vault has been initialized and Tomcat is loading it, you can start using the vault to store encrypted passwords in your configuration files.
76 |
77 | Before you can do this, you will need to add the attributes that you'd like to encrypt to your vault. An example of how to add a secured attribute is listed below:
78 |
79 | ~~~
80 | # Add a secured attribute to the Vault
81 | $ bin/vault.sh --keystore /tmp/vault/vault.keystore --keystore-password my_password123 --alias my_vault --enc-dir /tmp/vault/ --iteration 120 --salt 1234abcd --vault-block my_block --attribute manager_password --sec-attr P@SSW0#D
82 | ~~~
83 |
84 | Once the attribute has been added to the Vault, simply replace whatever property value you would like to hide in any Apache Tomcat configuration file with `${attribute_name}`. As an example, let's say that you wanted to use the password that we put into the Vault above (P@SSW0#D) as your tomcat user's password in the manager-gui role. To do that you would change the user in tomcat-users.xml from:
85 |
86 | ~~~
87 |
88 | ~~~
89 |
90 | to:
91 |
92 | ~~~
93 |
94 | ~~~
95 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | Apache License
2 | Version 2.0, January 2004
3 | http://www.apache.org/licenses/
4 |
5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6 |
7 | 1. Definitions.
8 |
9 | "License" shall mean the terms and conditions for use, reproduction,
10 | and distribution as defined by Sections 1 through 9 of this document.
11 |
12 | "Licensor" shall mean the copyright owner or entity authorized by
13 | the copyright owner that is granting the License.
14 |
15 | "Legal Entity" shall mean the union of the acting entity and all
16 | other entities that control, are controlled by, or are under common
17 | control with that entity. For the purposes of this definition,
18 | "control" means (i) the power, direct or indirect, to cause the
19 | direction or management of such entity, whether by contract or
20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the
21 | outstanding shares, or (iii) beneficial ownership of such entity.
22 |
23 | "You" (or "Your") shall mean an individual or Legal Entity
24 | exercising permissions granted by this License.
25 |
26 | "Source" form shall mean the preferred form for making modifications,
27 | including but not limited to software source code, documentation
28 | source, and configuration files.
29 |
30 | "Object" form shall mean any form resulting from mechanical
31 | transformation or translation of a Source form, including but
32 | not limited to compiled object code, generated documentation,
33 | and conversions to other media types.
34 |
35 | "Work" shall mean the work of authorship, whether in Source or
36 | Object form, made available under the License, as indicated by a
37 | copyright notice that is included in or attached to the work
38 | (an example is provided in the Appendix below).
39 |
40 | "Derivative Works" shall mean any work, whether in Source or Object
41 | form, that is based on (or derived from) the Work and for which the
42 | editorial revisions, annotations, elaborations, or other modifications
43 | represent, as a whole, an original work of authorship. For the purposes
44 | of this License, Derivative Works shall not include works that remain
45 | separable from, or merely link (or bind by name) to the interfaces of,
46 | the Work and Derivative Works thereof.
47 |
48 | "Contribution" shall mean any work of authorship, including
49 | the original version of the Work and any modifications or additions
50 | to that Work or Derivative Works thereof, that is intentionally
51 | submitted to Licensor for inclusion in the Work by the copyright owner
52 | or by an individual or Legal Entity authorized to submit on behalf of
53 | the copyright owner. For the purposes of this definition, "submitted"
54 | means any form of electronic, verbal, or written communication sent
55 | to the Licensor or its representatives, including but not limited to
56 | communication on electronic mailing lists, source code control systems,
57 | and issue tracking systems that are managed by, or on behalf of, the
58 | Licensor for the purpose of discussing and improving the Work, but
59 | excluding communication that is conspicuously marked or otherwise
60 | designated in writing by the copyright owner as "Not a Contribution."
61 |
62 | "Contributor" shall mean Licensor and any individual or Legal Entity
63 | on behalf of whom a Contribution has been received by Licensor and
64 | subsequently incorporated within the Work.
65 |
66 | 2. Grant of Copyright License. Subject to the terms and conditions of
67 | this License, each Contributor hereby grants to You a perpetual,
68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69 | copyright license to reproduce, prepare Derivative Works of,
70 | publicly display, publicly perform, sublicense, and distribute the
71 | Work and such Derivative Works in Source or Object form.
72 |
73 | 3. Grant of Patent License. Subject to the terms and conditions of
74 | this License, each Contributor hereby grants to You a perpetual,
75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76 | (except as stated in this section) patent license to make, have made,
77 | use, offer to sell, sell, import, and otherwise transfer the Work,
78 | where such license applies only to those patent claims licensable
79 | by such Contributor that are necessarily infringed by their
80 | Contribution(s) alone or by combination of their Contribution(s)
81 | with the Work to which such Contribution(s) was submitted. If You
82 | institute patent litigation against any entity (including a
83 | cross-claim or counterclaim in a lawsuit) alleging that the Work
84 | or a Contribution incorporated within the Work constitutes direct
85 | or contributory patent infringement, then any patent licenses
86 | granted to You under this License for that Work shall terminate
87 | as of the date such litigation is filed.
88 |
89 | 4. Redistribution. You may reproduce and distribute copies of the
90 | Work or Derivative Works thereof in any medium, with or without
91 | modifications, and in Source or Object form, provided that You
92 | meet the following conditions:
93 |
94 | (a) You must give any other recipients of the Work or
95 | Derivative Works a copy of this License; and
96 |
97 | (b) You must cause any modified files to carry prominent notices
98 | stating that You changed the files; and
99 |
100 | (c) You must retain, in the Source form of any Derivative Works
101 | that You distribute, all copyright, patent, trademark, and
102 | attribution notices from the Source form of the Work,
103 | excluding those notices that do not pertain to any part of
104 | the Derivative Works; and
105 |
106 | (d) If the Work includes a "NOTICE" text file as part of its
107 | distribution, then any Derivative Works that You distribute must
108 | include a readable copy of the attribution notices contained
109 | within such NOTICE file, excluding those notices that do not
110 | pertain to any part of the Derivative Works, in at least one
111 | of the following places: within a NOTICE text file distributed
112 | as part of the Derivative Works; within the Source form or
113 | documentation, if provided along with the Derivative Works; or,
114 | within a display generated by the Derivative Works, if and
115 | wherever such third-party notices normally appear. The contents
116 | of the NOTICE file are for informational purposes only and
117 | do not modify the License. You may add Your own attribution
118 | notices within Derivative Works that You distribute, alongside
119 | or as an addendum to the NOTICE text from the Work, provided
120 | that such additional attribution notices cannot be construed
121 | as modifying the License.
122 |
123 | You may add Your own copyright statement to Your modifications and
124 | may provide additional or different license terms and conditions
125 | for use, reproduction, or distribution of Your modifications, or
126 | for any such Derivative Works as a whole, provided Your use,
127 | reproduction, and distribution of the Work otherwise complies with
128 | the conditions stated in this License.
129 |
130 | 5. Submission of Contributions. Unless You explicitly state otherwise,
131 | any Contribution intentionally submitted for inclusion in the Work
132 | by You to the Licensor shall be under the terms and conditions of
133 | this License, without any additional terms or conditions.
134 | Notwithstanding the above, nothing herein shall supersede or modify
135 | the terms of any separate license agreement you may have executed
136 | with Licensor regarding such Contributions.
137 |
138 | 6. Trademarks. This License does not grant permission to use the trade
139 | names, trademarks, service marks, or product names of the Licensor,
140 | except as required for reasonable and customary use in describing the
141 | origin of the Work and reproducing the content of the NOTICE file.
142 |
143 | 7. Disclaimer of Warranty. Unless required by applicable law or
144 | agreed to in writing, Licensor provides the Work (and each
145 | Contributor provides its Contributions) on an "AS IS" BASIS,
146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147 | implied, including, without limitation, any warranties or conditions
148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149 | PARTICULAR PURPOSE. You are solely responsible for determining the
150 | appropriateness of using or redistributing the Work and assume any
151 | risks associated with Your exercise of permissions under this License.
152 |
153 | 8. Limitation of Liability. In no event and under no legal theory,
154 | whether in tort (including negligence), contract, or otherwise,
155 | unless required by applicable law (such as deliberate and grossly
156 | negligent acts) or agreed to in writing, shall any Contributor be
157 | liable to You for damages, including any direct, indirect, special,
158 | incidental, or consequential damages of any character arising as a
159 | result of this License or out of the use or inability to use the
160 | Work (including but not limited to damages for loss of goodwill,
161 | work stoppage, computer failure or malfunction, or any and all
162 | other commercial damages or losses), even if such Contributor
163 | has been advised of the possibility of such damages.
164 |
165 | 9. Accepting Warranty or Additional Liability. While redistributing
166 | the Work or Derivative Works thereof, You may choose to offer,
167 | and charge a fee for, acceptance of support, warranty, indemnity,
168 | or other liability obligations and/or rights consistent with this
169 | License. However, in accepting such obligations, You may act only
170 | on Your own behalf and on Your sole responsibility, not on behalf
171 | of any other Contributor, and only if You agree to indemnify,
172 | defend, and hold each Contributor harmless for any liability
173 | incurred by, or claims asserted against, such Contributor by reason
174 | of your accepting any such warranty or additional liability.
175 |
176 | END OF TERMS AND CONDITIONS
177 |
178 | APPENDIX: How to apply the Apache License to your work.
179 |
180 | To apply the Apache License to your work, attach the following
181 | boilerplate notice, with the fields enclosed by brackets "{}"
182 | replaced with your own identifying information. (Don't include
183 | the brackets!) The text should be enclosed in the appropriate
184 | comment syntax for the file format. We also recommend that a
185 | file or class name and description of purpose be included on the
186 | same "printed page" as the copyright notice for easier
187 | identification within third-party archives.
188 |
189 | Copyright {yyyy} {name of copyright owner}
190 |
191 | Licensed under the Apache License, Version 2.0 (the "License");
192 | you may not use this file except in compliance with the License.
193 | You may obtain a copy of the License at
194 |
195 | http://www.apache.org/licenses/LICENSE-2.0
196 |
197 | Unless required by applicable law or agreed to in writing, software
198 | distributed under the License is distributed on an "AS IS" BASIS,
199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200 | See the License for the specific language governing permissions and
201 | limitations under the License.
202 |
203 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # Vault for Apache Tomcat
2 | Tomcat-vault is a PicketLink vault extension for Apache Tomcat. It allows you to place sensitive information, such as passwords, inside of a vault instead of the Tomcat configuration files.
3 |
4 | # Installation
5 | See the [INSTALL](./INSTALL.md) file for instructions on installation and usage.
6 |
7 | # How it works
8 | At start up, the Tomcat digester module parses configuration files and references the vault keystore when a ${parameter} is found within a Tomcat configuration file. If the ${parameter} is found within the vault, then the ${parameter} is replaced with the value of the corresponding attribute.
9 |
10 | # HOW TO TEST
11 | simply run `mvn test` in the directory that contains pom.xml file
12 |
13 | # Links
14 | Tomcat System Properties :
15 | https://tomcat.apache.org/tomcat-9.0-doc/config/systemprops.html
16 |
--------------------------------------------------------------------------------
/Using_Crypt.md:
--------------------------------------------------------------------------------
1 | ## Using CRYPT With the Vault
2 |
3 | A new feature was added to the Vault which allows users to utilize encrypted values in configuration files which are **not** stored in the vault.
4 |
5 | ### Installing the Vault
6 |
7 | See the [INSTALL](./INSTALL.md) file for instructions on installation and usage of the vault (minus the CRYPT feature, which is fully documented here).
8 |
9 | ### Using the CRYPT feature
10 |
11 | #### Configuring Tomcat
12 |
13 | Configure Tomcat to use your password from an encrypted or plain text string:
14 |
15 | - **Encrypted**: Add the encryption password to the vault:
16 |
17 | ~~~
18 | $ bin/vault.sh --keystore /path/to/vault.keystore --keystore-password my_password123 --alias my_vault --enc-dir /path/to/vault/encryption_dir/ --iteration 120 --salt 1234abcd --vault-block my_block --attribute my_encryption_password --sec-attr MyEncryptionPassword
19 | ~~~
20 |
21 | then, put the VAULT reference in your vault.properties as follows:
22 |
23 | ~~~
24 | ENCRYPTION_PASSWORD=VAULT::my_block::my_encryption_password::
25 | ~~~
26 |
27 | - **Plain Text**: Add the password to conf/catalina.properties, or pass it in as a system property to java:
28 |
29 | ~~~
30 | org.apache.tomcat.vault.util.ENCRYPTION_PASSWORD=MyEncryptionPassword
31 | ~~~
32 |
33 | **Note: Setting ENCRYPTION_PASSWORD in vault.properties will override org.apache.tomcat.vault.util.ENCRYPTION_PASSWORD.**
34 |
35 | Now that you have a password configured, you can encrypt some value and put the resulting string in your configuration file to be decrypted on the fly:
36 |
37 | #### Encrypting Values for Use
38 |
39 | You can encrypt values one of two ways.
40 |
41 | Method 1, using a plain text encryption password:
42 | ~~~
43 | $ bin/vault.sh --encrypt MyEncryptionPassword MyPassword
44 | =========================================================================
45 |
46 | Tomcat Vault
47 |
48 | VAULT_HOME: /path/to/tomcat-vault/lib
49 |
50 | JAVA: java
51 |
52 | =========================================================================
53 |
54 | Encrypted value: CRYPT::a33AiwJkF4dMx9Uq9oxElYT6LdjXLJxf
55 | ~~~
56 |
57 | Method 2, using an encryption password which is stored in the vault:
58 |
59 | ~~~
60 | $ bin/vault.sh --keystore /path/to/vault.keystore --keystore-password my_password123 --alias my_vault --enc-dir /path/to/vault/encryption_dir/ --encrypt VAULT::my_block::my_encryption_password:: MyPassword
61 | =========================================================================
62 |
63 | Tomcat Vault
64 |
65 | VAULT_HOME: /path/to/tomcat-vault/lib
66 |
67 | JAVA: java
68 |
69 | =========================================================================
70 |
71 | Dec 06, 2017 12:54:30 PM org.apache.tomcat.vault.security.vault.PicketBoxSecurityVault init
72 | INFO: Default Security Vault Implementation Initialized and Ready
73 | Encrypted value: CRYPT::z9zbQSywH7iqmNJOW/wM++TKfF13U8/e
74 | ~~~
75 |
76 | #### Two Usage Examples
77 |
78 | Once you have the encrypted string (copied from the command output above), place that string into your configuration inside of brackets, such as ${}, so that Tomcat's Digester correctly interpolates it.
79 |
80 | An XML example would look like:
81 |
82 | ~~~
83 | $ tail -n2 conf/tomcat-users.xml | head -n1
84 |
85 | ~~~
86 |
87 | A properties file example would look like:
88 |
89 | ~~~
90 | $ tail -n1 conf/catalina.properties
91 | test.property=${CRYPT::a33AiwJkF4dMx9Uq9oxElYT6LdjXLJxf}
92 | ~~~
93 |
94 | Note that the properties file does **not** need quotations marks.
95 |
--------------------------------------------------------------------------------
/bin/vault.bat:
--------------------------------------------------------------------------------
1 | @echo off
2 | rem -------------------------------------------------------------------------
3 | rem Vault tool script for Windows
4 | rem -------------------------------------------------------------------------
5 | rem
6 | rem A tool for management securing sensitive strings
7 |
8 | @if not "%ECHO%" == "" echo %ECHO%
9 | @if "%OS%" == "Windows_NT" setlocal
10 |
11 | if "%OS%" == "Windows_NT" (
12 | set "DIRNAME=%~dp0%"
13 | ) else (
14 | set DIRNAME=.\
15 | )
16 |
17 | pushd "%DIRNAME%.."
18 | set "VAULT_HOME=%CD%"
19 | popd
20 |
21 | rem Setup Tomcat specific properties
22 | if "x%JAVA_HOME%" == "x" (
23 | set JAVA=java
24 | echo JAVA_HOME is not set. Unexpected results may occur.
25 | echo Set JAVA_HOME to the directory of your local JDK to avoid this message.
26 | ) else (
27 | set "JAVA=%JAVA_HOME%\bin\java"
28 | )
29 |
30 | rem Find tomcat-vault.jar, or we can't continue
31 | set "VAULT_RUNJAR=%VAULT_HOME%\lib\tomcat-vault.jar"
32 | if not exist "%VAULT_RUNJAR%" (
33 | echo Could not locate "%VAULT_RUNJAR%".
34 | echo Please check that you are in the bin directory when running this script.
35 | goto END
36 | )
37 |
38 | rem Set classpath with Tomcat jars
39 | if "x%VAULT_CLASSPATH%" == "x" (
40 | set "VAULT_CLASSPATH=%VAULT_RUNJAR%;%VAULT_HOME%\lib\tomcat-util.jar;%VAULT_HOME%\bin\tomcat-juli.jar"
41 | )
42 |
43 | rem Display our environment
44 | set help=F
45 | if "%*" == "-h" set help=T
46 | if "%*" == "--help" set help=T
47 | if "%help%" == "F" (
48 | echo =========================================================================
49 | echo.
50 | echo Tomcat Vault Tool
51 | echo.
52 | echo VAULT_HOME: "%VAULT_HOME%"
53 | echo.
54 | echo JAVA: "%JAVA%"
55 | echo.
56 | echo JAVA_OPTS: "%JAVA_OPTS%"
57 | echo.
58 | echo =========================================================================
59 | echo.
60 | )
61 |
62 | "%JAVA%" %JAVA_OPTS% ^
63 | -cp "%VAULT_CLASSPATH%" ^
64 | org.apache.tomcat.vault.VaultTool ^
65 | %*
66 |
67 | :END
68 |
--------------------------------------------------------------------------------
/bin/vault.sh:
--------------------------------------------------------------------------------
1 | #!/bin/sh
2 |
3 | DIRNAME=`dirname "$0"`
4 | PROGNAME=`basename "$0"`
5 | GREP="grep"
6 |
7 | # Use the maximum available, or set MAX_FD != -1 to use that
8 | MAX_FD="maximum"
9 |
10 | #
11 | # Helper to complain.
12 | #
13 | warn() {
14 | echo "${PROGNAME}: $*"
15 | }
16 |
17 | #
18 | # Helper to puke.
19 | #
20 | die() {
21 | warn $*
22 | exit 1
23 | }
24 |
25 | # OS specific support (must be 'true' or 'false').
26 | cygwin=false;
27 | darwin=false;
28 | linux=false;
29 | case "`uname`" in
30 | CYGWIN*)
31 | cygwin=true
32 | ;;
33 |
34 | Darwin*)
35 | darwin=true
36 | ;;
37 |
38 | Linux)
39 | linux=true
40 | ;;
41 | esac
42 |
43 | # For Cygwin, ensure paths are in UNIX format before anything is touched
44 | if $cygwin ; then
45 | [ -n "$VAULT_HOME" ] &&
46 | VAULT_HOME=`cygpath --unix "$VAULT_HOME"`
47 | [ -n "$JAVA_HOME" ] &&
48 | JAVA_HOME=`cygpath --unix "$JAVA_HOME"`
49 | [ -n "$JAVAC_JAR" ] &&
50 | JAVAC_JAR=`cygpath --unix "$JAVAC_JAR"`
51 | fi
52 |
53 | # Setup VAULT_HOME
54 | VAULT_HOME=`cd "$DIRNAME/.."; pwd`
55 | export VAULT_HOME
56 |
57 | # Setup the JVM
58 | if [ "x$JAVA" = "x" ]; then
59 | if [ "x$JAVA_HOME" != "x" ]; then
60 | JAVA="$JAVA_HOME/bin/java"
61 | else
62 | JAVA="java"
63 | fi
64 | fi
65 |
66 | # Setup the classpath for vault that contains the tomcat jars
67 | if [ "x$VAULT_CLASSPATH" = "x" ]; then
68 | if [ -d "$VAULT_HOME/share/java" ];then
69 | # rpm or zip install
70 | VAULT_HOME="$VAULT_HOME/share/java"
71 | VAULT_CLASSPATH="$VAULT_HOME/tomcat/tomcat-util.jar:$VAULT_HOME/../tomcat/bin/tomcat-juli.jar"
72 | elif [ -d "$VAULT_HOME/lib" ];then
73 | VAULT_CLASSPATH="$VAULT_HOME/lib/tomcat-util.jar:$VAULT_HOME/bin/tomcat-juli.jar"
74 | VAULT_HOME="$VAULT_HOME/lib"
75 | else
76 | VAULT_HOME="/usr/share/java"
77 | VAULT_CLASSPATH="/usr/share/java/tomcat/tomcat-util.jar:/usr/share/tomcat/bin/tomcat-juli.jar"
78 | fi
79 | fi
80 |
81 | ###
82 | # Setup the Tomcat Vault Tool classpath
83 | ###
84 |
85 | # For Cygwin, switch paths to Windows format before running java
86 | if $cygwin; then
87 | VAULT_HOME=`cygpath --path --windows "$VAULT_HOME"`
88 | VAULT_CLASSPATH=`cygpath --path --windows "$VAULT_CLASSPATH"`
89 | fi
90 |
91 | # Display our environment
92 | if [[ "$@" != "-h" && "$@" != "--help" ]]; then
93 | echo "========================================================================="
94 | echo ""
95 | echo " Tomcat Vault"
96 | echo ""
97 | echo " VAULT_HOME: $VAULT_HOME"
98 | echo ""
99 | echo " JAVA: $JAVA"
100 | echo ""
101 | echo "========================================================================="
102 | echo ""
103 | fi
104 |
105 | eval \"$JAVA\" $JAVA_OPTS \
106 | -cp \"$VAULT_HOME/tomcat-vault.jar:$VAULT_CLASSPATH\" \
107 | org.apache.tomcat.vault.VaultTool \
108 | '"$@"'
109 |
110 |
--------------------------------------------------------------------------------
/examples/README.md:
--------------------------------------------------------------------------------
1 | # just an example to use the vault with a web.xml and context.xml
2 | to use the example:
3 |
4 | build the valve and copy the jar in the ${catalina.base}/lib directory.
5 |
6 | build the webapp and copy the war in the ${catalina.base}/webapps directory.
7 |
8 | the trace output is going in the catalina.out and in the header vault.param
9 |
10 |
11 |
12 |
13 |
14 |
--------------------------------------------------------------------------------
/examples/valve/pom.xml:
--------------------------------------------------------------------------------
1 |
3 | 4.0.0
4 | org.tomcat.example
5 | demo
6 | jar
7 | 1.0-SNAPSHOT
8 | demo Maven Webapp
9 | http://maven.apache.org
10 |
11 | 9.0.96
12 |
13 |
14 |
15 | org.apache.tomcat
16 | tomcat-servlet-api
17 | ${tomcat.version}
18 | provided
19 |
20 |
21 | org.apache.tomcat
22 | tomcat-catalina
23 | ${tomcat.version}
24 | provided
25 |
26 |
27 |
28 |
--------------------------------------------------------------------------------
/examples/valve/src/main/java/org/tomcat/example/MyValve.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Licensed to the Apache Software Foundation (ASF) under one or more
3 | * contributor license agreements. See the NOTICE file distributed with
4 | * this work for additional information regarding copyright ownership.
5 | * The ASF licenses this file to You under the Apache License, Version 2.0
6 | * (the "License"); you may not use this file except in compliance with
7 | * the License. You may obtain a copy of the License at
8 | *
9 | * http://www.apache.org/licenses/LICENSE-2.0
10 | *
11 | * Unless required by applicable law or agreed to in writing, software
12 | * distributed under the License is distributed on an "AS IS" BASIS,
13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 | * See the License for the specific language governing permissions and
15 | * limitations under the License.
16 | */
17 | package org.tomcat.example;
18 |
19 | import java.io.IOException;
20 | import java.io.PrintWriter;
21 | import java.util.Enumeration;
22 | import java.io.IOException;
23 |
24 | import javax.servlet.ServletException;
25 | import org.apache.catalina.valves.ValveBase;
26 | import org.apache.catalina.connector.Request;
27 | import org.apache.catalina.connector.Response;
28 |
29 | /*
30 | * RequestDumperValve valve.
31 | * Read header and dump them in catalina.out
32 | */
33 |
34 | public class MyValve
35 | extends ValveBase {
36 |
37 | private String vaultparam = "default";
38 | public String getVaultparam() {
39 | return vaultparam;
40 | }
41 | public void setVaultparam(String vaultparam) {
42 | this.vaultparam = vaultparam;
43 | }
44 |
45 | public void invoke(Request request, Response response) throws IOException, ServletException {
46 | System.out.println("in the valve from the context.xml in webapp: Vaultparam: " + vaultparam);
47 | getNext().invoke(request, response);
48 | }
49 | }
50 |
--------------------------------------------------------------------------------
/examples/webapp/pom.xml:
--------------------------------------------------------------------------------
1 |
3 | 4.0.0
4 | org.tomcat.example
5 | demo
6 | war
7 | 1.0-SNAPSHOT
8 | demo Maven Webapp
9 | http://maven.apache.org
10 |
11 | 9.0.36
12 |
13 |
14 |
15 | org.apache.tomcat
16 | tomcat-servlet-api
17 | ${tomcat.version}
18 | provided
19 |
20 |
21 |
22 |
--------------------------------------------------------------------------------
/examples/webapp/src/main/java/org/tomcat/example/MyFilter.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Licensed to the Apache Software Foundation (ASF) under one or more
3 | * contributor license agreements. See the NOTICE file distributed with
4 | * this work for additional information regarding copyright ownership.
5 | * The ASF licenses this file to You under the Apache License, Version 2.0
6 | * (the "License"); you may not use this file except in compliance with
7 | * the License. You may obtain a copy of the License at
8 | *
9 | * http://www.apache.org/licenses/LICENSE-2.0
10 | *
11 | * Unless required by applicable law or agreed to in writing, software
12 | * distributed under the License is distributed on an "AS IS" BASIS,
13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 | * See the License for the specific language governing permissions and
15 | * limitations under the License.
16 | */
17 |
18 | package org.tomcat.example;
19 |
20 | import java.io.IOException;
21 |
22 | import javax.servlet.Filter;
23 | import javax.servlet.FilterChain;
24 | import javax.servlet.FilterConfig;
25 | import javax.servlet.ServletException;
26 | import javax.servlet.ServletRequest;
27 | import javax.servlet.ServletResponse;
28 |
29 | import javax.servlet.http.HttpServletRequest;
30 | import javax.servlet.http.HttpServletResponse;
31 |
32 | /*
33 | * example to read a parameter processed by the vault logic
34 | */
35 | public class MyFilter implements Filter {
36 |
37 | String vaultparam;
38 |
39 | @Override
40 | public void init(FilterConfig filterConfig) {
41 | vaultparam = filterConfig.getInitParameter("vault.param");
42 | System.out.println("init() from web.xml filter parameter vault.param: " + vaultparam);
43 | }
44 |
45 | @Override
46 | public void doFilter(
47 | ServletRequest request,
48 | ServletResponse response,
49 | FilterChain chain)
50 | throws IOException, ServletException {
51 |
52 | HttpServletResponse httpResponse = (HttpServletResponse) response;
53 | httpResponse.addHeader("myHeader", "myHeaderValue");
54 | httpResponse.addHeader("vault.param", vaultparam);
55 | chain.doFilter(request, httpResponse);
56 | }
57 |
58 | @Override
59 | public void destroy() {
60 | }
61 | }
62 |
--------------------------------------------------------------------------------
/examples/webapp/src/main/java/org/tomcat/example/MyServlet.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Licensed to the Apache Software Foundation (ASF) under one or more
3 | * contributor license agreements. See the NOTICE file distributed with
4 | * this work for additional information regarding copyright ownership.
5 | * The ASF licenses this file to You under the Apache License, Version 2.0
6 | * (the "License"); you may not use this file except in compliance with
7 | * the License. You may obtain a copy of the License at
8 | *
9 | * http://www.apache.org/licenses/LICENSE-2.0
10 | *
11 | * Unless required by applicable law or agreed to in writing, software
12 | * distributed under the License is distributed on an "AS IS" BASIS,
13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 | * See the License for the specific language governing permissions and
15 | * limitations under the License.
16 | */
17 |
18 | package org.tomcat.example;
19 |
20 | import java.io.IOException;
21 | import java.io.PrintWriter;
22 | import java.util.Enumeration;
23 | import java.util.Properties;
24 |
25 | import javax.servlet.ServletException;
26 |
27 | import javax.servlet.http.HttpServlet;
28 | import javax.servlet.http.HttpServletRequest;
29 | import javax.servlet.http.HttpServletResponse;
30 |
31 | public class MyServlet extends HttpServlet {
32 | public void doGet(HttpServletRequest request, HttpServletResponse response)
33 | throws IOException, ServletException {
34 | // Set the response message's MIME type
35 | response.setContentType("text/html;charset=UTF-8");
36 | // Allocate a output writer to write the response message into the network socket
37 | PrintWriter out = response.getWriter();
38 |
39 | // Read properties
40 | Properties properties = new Properties();
41 | properties.load(getServletContext().getResourceAsStream("/resources/examples.properties"));
42 | Enumeration> enumeration =properties.propertyNames();
43 | while (enumeration.hasMoreElements()) {
44 | String key = (String) enumeration.nextElement();
45 | System.out.println("properties file in webapps Key: "+key+" Value: "+ properties.getProperty(key));
46 | System.out.println("system properties in (conf/catalina.properties ) Key: "+key+" Value: "+ System.getProperty(key));
47 | }
48 |
49 | // Write the response message, in an HTML page
50 | try {
51 | out.println("");
52 | out.println("