Lines 20-28
Link Here
|
20 |
import java.io.FileInputStream; |
20 |
import java.io.FileInputStream; |
21 |
import java.io.IOException; |
21 |
import java.io.IOException; |
22 |
import java.io.InputStream; |
22 |
import java.io.InputStream; |
23 |
import java.util.ArrayList; |
23 |
import java.util.HashSet; |
24 |
import java.util.Iterator; |
24 |
import java.util.Iterator; |
25 |
import java.util.Locale; |
25 |
import java.util.Locale; |
|
|
26 |
import java.util.Set; |
26 |
import java.util.StringTokenizer; |
27 |
import java.util.StringTokenizer; |
27 |
import java.util.jar.JarInputStream; |
28 |
import java.util.jar.JarInputStream; |
28 |
import java.util.jar.Manifest; |
29 |
import java.util.jar.Manifest; |
Lines 46-55
Link Here
|
46 |
* @author Greg Murray |
47 |
* @author Greg Murray |
47 |
* @author Justyna Horwat |
48 |
* @author Justyna Horwat |
48 |
*/ |
49 |
*/ |
49 |
public final class ExtensionValidator { |
50 |
public class ExtensionValidator { |
50 |
|
51 |
|
51 |
private static final Log log = LogFactory.getLog(ExtensionValidator.class); |
52 |
private static final Log log = LogFactory.getLog(ExtensionValidator.class); |
52 |
|
53 |
|
|
|
54 |
public static final ExtensionValidator DEFAULT = new ExtensionValidator(){ |
55 |
@Override |
56 |
public void addSystemResource(File jarFile) throws IOException { |
57 |
throw new UnsupportedOperationException("this is a read-only ExtensionValidator"); |
58 |
} |
59 |
}; |
60 |
|
53 |
/** |
61 |
/** |
54 |
* The string resources for this package. |
62 |
* The string resources for this package. |
55 |
*/ |
63 |
*/ |
Lines 56-72
Link Here
|
56 |
private static final StringManager sm = |
64 |
private static final StringManager sm = |
57 |
StringManager.getManager("org.apache.catalina.util"); |
65 |
StringManager.getManager("org.apache.catalina.util"); |
58 |
|
66 |
|
59 |
private static volatile ArrayList<Extension> containerAvailableExtensions = |
67 |
private volatile Set<Extension> containerAvailableExtensions = |
60 |
null; |
68 |
null; |
61 |
private static final ArrayList<ManifestResource> containerManifestResources = |
69 |
private final Set<ManifestResource> containerManifestResources = |
62 |
new ArrayList<>(); |
70 |
new HashSet<>(); |
63 |
|
71 |
|
64 |
|
72 |
|
65 |
// ----------------------------------------------------- Static Initializer |
73 |
// ----------------------------------------------------- Constructor |
66 |
|
74 |
|
67 |
|
75 |
|
68 |
/** |
76 |
/** |
69 |
* This static initializer loads the container level extensions that are |
77 |
* This constructor loads the container level extensions that are |
70 |
* available to all web applications. This method scans all extension |
78 |
* available to all web applications. This method scans all extension |
71 |
* directories available via the "java.ext.dirs" System property. |
79 |
* directories available via the "java.ext.dirs" System property. |
72 |
* |
80 |
* |
Lines 73-79
Link Here
|
73 |
* The System Class-Path is also scanned for jar files that may contain |
81 |
* The System Class-Path is also scanned for jar files that may contain |
74 |
* available extensions. |
82 |
* available extensions. |
75 |
*/ |
83 |
*/ |
76 |
static { |
84 |
public ExtensionValidator(){ |
77 |
|
85 |
|
78 |
// check for container level optional packages |
86 |
// check for container level optional packages |
79 |
String systemClasspath = System.getProperty("java.class.path"); |
87 |
String systemClasspath = System.getProperty("java.class.path"); |
Lines 88-94
Link Here
|
88 |
File item = new File(classpathItem); |
96 |
File item = new File(classpathItem); |
89 |
if (item.isFile()) { |
97 |
if (item.isFile()) { |
90 |
try { |
98 |
try { |
91 |
addSystemResource(item); |
99 |
doAddSystemResource(item); |
92 |
} catch (IOException e) { |
100 |
} catch (IOException e) { |
93 |
log.error(sm.getString |
101 |
log.error(sm.getString |
94 |
("extensionValidator.failload", item), e); |
102 |
("extensionValidator.failload", item), e); |
Lines 123-135
Link Here
|
123 |
* @return true if all required extensions satisfied |
131 |
* @return true if all required extensions satisfied |
124 |
* @throws IOException Error reading resources needed for validation |
132 |
* @throws IOException Error reading resources needed for validation |
125 |
*/ |
133 |
*/ |
126 |
public static synchronized boolean validateApplication( |
134 |
public synchronized boolean validateApplication( |
127 |
WebResourceRoot resources, |
135 |
WebResourceRoot resources, |
128 |
Context context) |
136 |
Context context) |
129 |
throws IOException { |
137 |
throws IOException { |
130 |
|
138 |
|
131 |
String appName = context.getName(); |
139 |
String appName = context.getName(); |
132 |
ArrayList<ManifestResource> appManifestResources = new ArrayList<>(); |
140 |
Set<ManifestResource> appManifestResources = new HashSet<>(); |
133 |
|
141 |
|
134 |
// Web application manifest |
142 |
// Web application manifest |
135 |
WebResource resource = resources.getResource("/META-INF/MANIFEST.MF"); |
143 |
WebResource resource = resources.getResource("/META-INF/MANIFEST.MF"); |
Lines 171-185
Link Here
|
171 |
* @param jarFile The system JAR whose manifest to add |
179 |
* @param jarFile The system JAR whose manifest to add |
172 |
* @throws IOException Error reading JAR file |
180 |
* @throws IOException Error reading JAR file |
173 |
*/ |
181 |
*/ |
174 |
public static void addSystemResource(File jarFile) throws IOException { |
182 |
public void addSystemResource(File jarFile) throws IOException { |
175 |
try (InputStream is = new FileInputStream(jarFile)) { |
183 |
doAddSystemResource(jarFile); |
176 |
Manifest manifest = getManifest(is); |
|
|
177 |
if (manifest != null) { |
178 |
ManifestResource mre = new ManifestResource(jarFile.getAbsolutePath(), manifest, |
179 |
ManifestResource.SYSTEM); |
180 |
containerManifestResources.add(mre); |
181 |
} |
182 |
} |
183 |
} |
184 |
} |
184 |
|
185 |
|
185 |
|
186 |
|
Lines 205-220
Link Here
|
205 |
* |
206 |
* |
206 |
* @return true if manifest resource file requirements are met |
207 |
* @return true if manifest resource file requirements are met |
207 |
*/ |
208 |
*/ |
208 |
private static boolean validateManifestResources(String appName, |
209 |
private boolean validateManifestResources(String appName, |
209 |
ArrayList<ManifestResource> resources) { |
210 |
Set<ManifestResource> resources) { |
210 |
boolean passes = true; |
211 |
boolean passes = true; |
211 |
int failureCount = 0; |
212 |
int failureCount = 0; |
212 |
ArrayList<Extension> availableExtensions = null; |
213 |
Set<Extension> availableExtensions = null; |
213 |
|
214 |
|
214 |
Iterator<ManifestResource> it = resources.iterator(); |
215 |
Iterator<ManifestResource> it = resources.iterator(); |
215 |
while (it.hasNext()) { |
216 |
while (it.hasNext()) { |
216 |
ManifestResource mre = it.next(); |
217 |
ManifestResource mre = it.next(); |
217 |
ArrayList<Extension> requiredList = mre.getRequiredExtensions(); |
218 |
Set<Extension> requiredList = mre.getRequiredExtensions(); |
218 |
if (requiredList == null) { |
219 |
if (requiredList == null) { |
219 |
continue; |
220 |
continue; |
220 |
} |
221 |
} |
Lines 299-319
Link Here
|
299 |
* |
300 |
* |
300 |
* @return HashMap Map of available extensions |
301 |
* @return HashMap Map of available extensions |
301 |
*/ |
302 |
*/ |
302 |
private static ArrayList<Extension> buildAvailableExtensionsList( |
303 |
private Set<Extension> buildAvailableExtensionsList( |
303 |
ArrayList<ManifestResource> resources) { |
304 |
Set<ManifestResource> resources) { |
304 |
|
305 |
|
305 |
ArrayList<Extension> availableList = null; |
306 |
Set<Extension> availableList = null; |
306 |
|
307 |
|
307 |
Iterator<ManifestResource> it = resources.iterator(); |
308 |
Iterator<ManifestResource> it = resources.iterator(); |
308 |
while (it.hasNext()) { |
309 |
while (it.hasNext()) { |
309 |
ManifestResource mre = it.next(); |
310 |
ManifestResource mre = it.next(); |
310 |
ArrayList<Extension> list = mre.getAvailableExtensions(); |
311 |
Set<Extension> list = mre.getAvailableExtensions(); |
311 |
if (list != null) { |
312 |
if (list != null) { |
312 |
Iterator<Extension> values = list.iterator(); |
313 |
Iterator<Extension> values = list.iterator(); |
313 |
while (values.hasNext()) { |
314 |
while (values.hasNext()) { |
314 |
Extension ext = values.next(); |
315 |
Extension ext = values.next(); |
315 |
if (availableList == null) { |
316 |
if (availableList == null) { |
316 |
availableList = new ArrayList<>(); |
317 |
availableList = new HashSet<>(); |
317 |
availableList.add(ext); |
318 |
availableList.add(ext); |
318 |
} else { |
319 |
} else { |
319 |
availableList.add(ext); |
320 |
availableList.add(ext); |
Lines 331-337
Link Here
|
331 |
* @param inStream Input stream to a WAR or JAR file |
332 |
* @param inStream Input stream to a WAR or JAR file |
332 |
* @return The WAR's or JAR's manifest |
333 |
* @return The WAR's or JAR's manifest |
333 |
*/ |
334 |
*/ |
334 |
private static Manifest getManifest(InputStream inStream) throws IOException { |
335 |
private Manifest getManifest(InputStream inStream) throws IOException { |
335 |
Manifest manifest = null; |
336 |
Manifest manifest = null; |
336 |
try (JarInputStream jin = new JarInputStream(inStream)) { |
337 |
try (JarInputStream jin = new JarInputStream(inStream)) { |
337 |
manifest = jin.getManifest(); |
338 |
manifest = jin.getManifest(); |
Lines 343-349
Link Here
|
343 |
/** |
344 |
/** |
344 |
* Add the JARs specified to the extension list. |
345 |
* Add the JARs specified to the extension list. |
345 |
*/ |
346 |
*/ |
346 |
private static void addFolderList(String property) { |
347 |
private void addFolderList(String property) { |
347 |
|
348 |
|
348 |
// get the files in the extensions directory |
349 |
// get the files in the extensions directory |
349 |
String extensionsDir = System.getProperty(property); |
350 |
String extensionsDir = System.getProperty(property); |
Lines 363-369
Link Here
|
363 |
if (files[i].getName().toLowerCase(Locale.ENGLISH).endsWith(".jar") && |
364 |
if (files[i].getName().toLowerCase(Locale.ENGLISH).endsWith(".jar") && |
364 |
files[i].isFile()) { |
365 |
files[i].isFile()) { |
365 |
try { |
366 |
try { |
366 |
addSystemResource(files[i]); |
367 |
doAddSystemResource(files[i]); |
367 |
} catch (IOException e) { |
368 |
} catch (IOException e) { |
368 |
log.error |
369 |
log.error |
369 |
(sm.getString |
370 |
(sm.getString |
Lines 376-380
Link Here
|
376 |
|
377 |
|
377 |
} |
378 |
} |
378 |
|
379 |
|
379 |
|
380 |
/** |
|
|
381 |
* |
382 |
* @param jarFile |
383 |
* @throws IOException |
384 |
*/ |
385 |
private void doAddSystemResource(File jarFile) throws IOException { |
386 |
try (InputStream is = new FileInputStream(jarFile)) { |
387 |
Manifest manifest = getManifest(is); |
388 |
if (manifest != null) { |
389 |
ManifestResource mre = new ManifestResource(jarFile.getAbsolutePath(), manifest, |
390 |
ManifestResource.SYSTEM); |
391 |
containerManifestResources.add(mre); |
392 |
} |
393 |
} |
394 |
} |
380 |
} |
395 |
} |