|
1 |
| |
|
2 |
| |
|
3 |
| |
|
4 |
| |
|
5 |
| |
|
6 |
| |
|
7 |
| |
|
8 |
| |
|
9 |
| |
|
10 |
| |
|
11 |
| |
|
12 |
| |
|
13 |
| |
|
14 |
| |
|
15 |
| |
|
16 |
| package org.acegisecurity.intercept.method; |
|
17 |
| |
|
18 |
| import org.acegisecurity.ConfigAttribute; |
|
19 |
| import org.acegisecurity.ConfigAttributeDefinition; |
|
20 |
| |
|
21 |
| import org.springframework.metadata.Attributes; |
|
22 |
| |
|
23 |
| import java.lang.reflect.Method; |
|
24 |
| |
|
25 |
| import java.util.Collection; |
|
26 |
| import java.util.Iterator; |
|
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 |
| public class MethodDefinitionAttributes extends AbstractMethodDefinitionSource { |
|
72 |
| |
|
73 |
| |
|
74 |
| private Attributes attributes; |
|
75 |
| |
|
76 |
| |
|
77 |
| |
|
78 |
12
| public void setAttributes(Attributes attributes) {
|
|
79 |
12
| this.attributes = attributes;
|
|
80 |
| } |
|
81 |
| |
|
82 |
2
| public Iterator getConfigAttributeDefinitions() {
|
|
83 |
2
| return null;
|
|
84 |
| } |
|
85 |
| |
|
86 |
12
| protected ConfigAttributeDefinition lookupAttributes(Method method) {
|
|
87 |
12
| ConfigAttributeDefinition definition = new ConfigAttributeDefinition();
|
|
88 |
| |
|
89 |
12
| Class interceptedClass = method.getDeclaringClass();
|
|
90 |
| |
|
91 |
| |
|
92 |
12
| addClassAttributes(definition, interceptedClass);
|
|
93 |
| |
|
94 |
| |
|
95 |
12
| addClassAttributes(definition, interceptedClass.getInterfaces());
|
|
96 |
| |
|
97 |
| |
|
98 |
12
| addMethodAttributes(definition, method);
|
|
99 |
| |
|
100 |
| |
|
101 |
12
| addInterfaceMethodAttributes(definition, method);
|
|
102 |
| |
|
103 |
12
| if (definition.size() == 0) {
|
|
104 |
1
| return null;
|
|
105 |
| } else { |
|
106 |
11
| return definition;
|
|
107 |
| } |
|
108 |
| } |
|
109 |
| |
|
110 |
30
| private void add(ConfigAttributeDefinition definition, Collection attribs) {
|
|
111 |
30
| for (Iterator iter = attribs.iterator(); iter.hasNext();) {
|
|
112 |
34
| Object o = (Object) iter.next();
|
|
113 |
| |
|
114 |
34
| if (o instanceof ConfigAttribute) {
|
|
115 |
32
| definition.addConfigAttribute((ConfigAttribute) o);
|
|
116 |
| } |
|
117 |
| } |
|
118 |
| } |
|
119 |
| |
|
120 |
12
| private void addClassAttributes(ConfigAttributeDefinition definition,
|
|
121 |
| Class clazz) { |
|
122 |
12
| addClassAttributes(definition, new Class[] {clazz});
|
|
123 |
| } |
|
124 |
| |
|
125 |
24
| private void addClassAttributes(ConfigAttributeDefinition definition,
|
|
126 |
| Class[] clazz) { |
|
127 |
24
| for (int i = 0; i < clazz.length; i++) {
|
|
128 |
18
| Collection classAttributes = attributes.getAttributes(clazz[i]);
|
|
129 |
| |
|
130 |
18
| if (classAttributes != null) {
|
|
131 |
14
| add(definition, classAttributes);
|
|
132 |
| } |
|
133 |
| } |
|
134 |
| } |
|
135 |
| |
|
136 |
12
| private void addInterfaceMethodAttributes(
|
|
137 |
| ConfigAttributeDefinition definition, Method method) { |
|
138 |
12
| Class[] interfaces = method.getDeclaringClass().getInterfaces();
|
|
139 |
| |
|
140 |
12
| for (int i = 0; i < interfaces.length; i++) {
|
|
141 |
6
| Class clazz = interfaces[i];
|
|
142 |
| |
|
143 |
6
| try {
|
|
144 |
6
| Method m = clazz.getDeclaredMethod(method.getName(),
|
|
145 |
| (Class[]) method.getParameterTypes()); |
|
146 |
6
| addMethodAttributes(definition, m);
|
|
147 |
| } catch (Exception e) { |
|
148 |
| |
|
149 |
| |
|
150 |
| } |
|
151 |
| } |
|
152 |
| } |
|
153 |
| |
|
154 |
18
| private void addMethodAttributes(ConfigAttributeDefinition definition,
|
|
155 |
| Method method) { |
|
156 |
| |
|
157 |
18
| Collection methodAttributes = attributes.getAttributes(method);
|
|
158 |
| |
|
159 |
18
| if (methodAttributes != null) {
|
|
160 |
16
| add(definition, methodAttributes);
|
|
161 |
| } |
|
162 |
| } |
|
163 |
| } |