forked from github/codeql
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCamel.qll
More file actions
92 lines (85 loc) · 2.88 KB
/
Copy pathCamel.qll
File metadata and controls
92 lines (85 loc) · 2.88 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
/**
* Apache Camel messaging framework.
*/
import java
import semmle.code.java.frameworks.spring.SpringCamel
import semmle.code.java.frameworks.camel.CamelJavaDSL
import semmle.code.java.frameworks.camel.CamelJavaAnnotations
/**
* A string describing a URI specified in an Apache Camel "to" declaration.
*/
class CamelToURI extends string {
CamelToURI() {
exists(SpringCamelXMLToElement toXMLElement | this = toXMLElement.getURI()) or
exists(CamelJavaDSLToDecl toJavaDSL | this = toJavaDSL.getURI())
}
}
/**
* A string describing a URI specified in an Apache Camel "to" declaration that maps to a
* SpringBean.
*/
class CamelToBeanURI extends CamelToURI {
CamelToBeanURI() {
// A `<to>` element references a bean if the URI starts with "bean:", or there is no scheme.
matches("bean:%") or
not exists(indexOf(":"))
}
/**
* Gets the identifier of the Spring Bean that is the target of this URI.
*
* The URI is of the form: `bean:BeanName?method", where the "bean:" scheme and "?methodname"
* parameter parts are optional.
*/
string getBeanIdentifier() {
if not exists(indexOf(":"))
then result = this
else
exists(int start | start = indexOf(":", 0, 0) + 1 |
if not exists(indexOf("?"))
then result = suffix(start)
else result = substring(start, indexOf("?", 0, 0))
)
}
/**
* Gets the bean referenced by this URI.
*/
SpringBean getRefBean() { result.getBeanIdentifier() = this.getBeanIdentifier() }
}
/**
* A Class whose methods may be called in response to an Apache Camel message.
*/
class CamelTargetClass extends Class {
CamelTargetClass() {
exists(SpringCamelXMLBeanRef camelXMLBeanRef |
// A target may be defined by referencing an existing Spring Bean.
this = camelXMLBeanRef.getRefBean().getClass()
or
// A target may be defined by referencing a class, which Apache Camel will create into a bean.
this = camelXMLBeanRef.getBeanType()
)
or
exists(CamelToBeanURI toBeanURI | this = toBeanURI.getRefBean().getClass())
or
exists(SpringCamelXMLMethodElement xmlMethod |
this = xmlMethod.getRefBean().getClass() or
this = xmlMethod.getBeanType()
)
or
exists(CamelJavaDSLMethodDecl methodDecl | this = methodDecl.getABean())
or
// Any beans referred to in Java DSL bean or beanRef elements are considered as possible
// targets. Whether the route builder is ever constructed or called is not considered.
exists(CamelJavaDSLBeanDecl beanDecl | this = beanDecl.getABeanClass())
or
exists(CamelJavaDSLBeanRefDecl beanRefDecl | this = beanRefDecl.getABeanClass())
}
/**
* Gets a method that may be called by Apache Camel.
*
* Any public method inherited by this class is assumed to be callable by Apache Camel.
*/
Method getACamelCalledMethod() {
this.inherits(result) and
result.isPublic()
}
}