|
| 1 | +/** |
| 2 | + * Provides classes for working with resource loading in Spring. |
| 3 | + */ |
| 4 | + |
| 5 | +import java |
| 6 | +private import semmle.code.java.dataflow.ExternalFlow |
| 7 | +private import semmle.code.java.dataflow.FlowSources |
| 8 | + |
| 9 | +/** A class for class path resources in the Spring framework. */ |
| 10 | +class ClassPathResource extends Class { |
| 11 | + ClassPathResource() { this.hasQualifiedName("org.springframework.core.io", "ClassPathResource") } |
| 12 | +} |
| 13 | + |
| 14 | +/** An interface for objects that are sources for an InputStream in the Spring framework. */ |
| 15 | +class InputStreamResource extends RefType { |
| 16 | + InputStreamResource() { |
| 17 | + this.hasQualifiedName("org.springframework.core.io", "InputStreamSource") |
| 18 | + } |
| 19 | +} |
| 20 | + |
| 21 | +/** An interface that abstracts from the underlying resource, such as a file or class path resource in the Spring framework. */ |
| 22 | +class Resource extends RefType { |
| 23 | + Resource() { this.hasQualifiedName("org.springframework.core.io", "Resource") } |
| 24 | +} |
| 25 | + |
| 26 | +/** A utility class for resolving resource locations to files in the file system in the Spring framework. */ |
| 27 | +class ResourceUtils extends Class { |
| 28 | + ResourceUtils() { this.hasQualifiedName("org.springframework.util", "ResourceUtils") } |
| 29 | +} |
| 30 | + |
| 31 | +/** |
| 32 | + * The method `getInputStream()` declared in Spring `ClassPathResource`. |
| 33 | + */ |
| 34 | +class GetClassPathResourceInputStreamMethod extends Method { |
| 35 | + GetClassPathResourceInputStreamMethod() { |
| 36 | + this.getDeclaringType().getASupertype*() instanceof ClassPathResource and |
| 37 | + this.hasName("getInputStream") |
| 38 | + } |
| 39 | +} |
| 40 | + |
| 41 | +/** |
| 42 | + * Resource loading method declared in Spring `Resource` with `getInputStream` inherited from the parent interface. |
| 43 | + */ |
| 44 | +class GetResourceMethod extends Method { |
| 45 | + GetResourceMethod() { |
| 46 | + ( |
| 47 | + this.getDeclaringType() instanceof InputStreamResource or |
| 48 | + this.getDeclaringType() instanceof Resource |
| 49 | + ) and |
| 50 | + this.hasName(["getFile", "getFilename", "getInputStream", "getURI", "getURL"]) |
| 51 | + } |
| 52 | +} |
| 53 | + |
| 54 | +/** |
| 55 | + * Resource loading method declared in Spring `ResourceUtils`. |
| 56 | + */ |
| 57 | +class GetResourceUtilsMethod extends Method { |
| 58 | + GetResourceUtilsMethod() { |
| 59 | + this.getDeclaringType().getASupertype*() instanceof ResourceUtils and |
| 60 | + this.hasName(["extractArchiveURL", "extractJarFileURL", "getFile", "getURL", "toURI"]) |
| 61 | + } |
| 62 | +} |
0 commit comments