|
1 |
| |
|
2 |
| |
|
3 |
| |
|
4 |
| |
|
5 |
| |
|
6 |
| |
|
7 |
| |
|
8 |
| |
|
9 |
| |
|
10 |
| |
|
11 |
| |
|
12 |
| |
|
13 |
| |
|
14 |
| |
|
15 |
| |
|
16 |
| package org.acegisecurity.intercept.web; |
|
17 |
| |
|
18 |
| import org.acegisecurity.ConfigAttributeDefinition; |
|
19 |
| import org.acegisecurity.ConfigAttributeEditor; |
|
20 |
| |
|
21 |
| import org.apache.commons.logging.Log; |
|
22 |
| import org.apache.commons.logging.LogFactory; |
|
23 |
| |
|
24 |
| import org.springframework.util.StringUtils; |
|
25 |
| |
|
26 |
| import java.beans.PropertyEditorSupport; |
|
27 |
| |
|
28 |
| import java.io.BufferedReader; |
|
29 |
| import java.io.IOException; |
|
30 |
| import java.io.StringReader; |
|
31 |
| |
|
32 |
| |
|
33 |
| |
|
34 |
| |
|
35 |
| |
|
36 |
| |
|
37 |
| |
|
38 |
| |
|
39 |
| |
|
40 |
| |
|
41 |
| |
|
42 |
| |
|
43 |
| |
|
44 |
| |
|
45 |
| |
|
46 |
| |
|
47 |
| |
|
48 |
| |
|
49 |
| |
|
50 |
| |
|
51 |
| |
|
52 |
| |
|
53 |
| |
|
54 |
| public class FilterInvocationDefinitionSourceEditor |
|
55 |
| extends PropertyEditorSupport { |
|
56 |
| |
|
57 |
| |
|
58 |
| private static final Log logger = LogFactory.getLog(FilterInvocationDefinitionSourceEditor.class); |
|
59 |
| |
|
60 |
| |
|
61 |
| |
|
62 |
33
| public void setAsText(String s) throws IllegalArgumentException {
|
|
63 |
33
| FilterInvocationDefinitionMap source = new RegExpBasedFilterInvocationDefinitionMap();
|
|
64 |
| |
|
65 |
33
| if ((s == null) || "".equals(s)) {
|
|
66 |
| |
|
67 |
| } else { |
|
68 |
| |
|
69 |
31
| if (s.lastIndexOf("PATTERN_TYPE_APACHE_ANT") != -1) {
|
|
70 |
20
| source = new PathBasedFilterInvocationDefinitionMap();
|
|
71 |
| |
|
72 |
20
| if (logger.isDebugEnabled()) {
|
|
73 |
0
| logger.debug(("Detected PATTERN_TYPE_APACHE_ANT directive; using Apache Ant style path expressions"));
|
|
74 |
| } |
|
75 |
| } |
|
76 |
| |
|
77 |
31
| BufferedReader br = new BufferedReader(new StringReader(s));
|
|
78 |
31
| int counter = 0;
|
|
79 |
31
| String line;
|
|
80 |
| |
|
81 |
31
| while (true) {
|
|
82 |
146
| counter++;
|
|
83 |
| |
|
84 |
146
| try {
|
|
85 |
146
| line = br.readLine();
|
|
86 |
| } catch (IOException ioe) { |
|
87 |
0
| throw new IllegalArgumentException(ioe.getMessage());
|
|
88 |
| } |
|
89 |
| |
|
90 |
146
| if (line == null) {
|
|
91 |
30
| break;
|
|
92 |
| } |
|
93 |
| |
|
94 |
116
| line = line.trim();
|
|
95 |
| |
|
96 |
116
| if (logger.isDebugEnabled()) {
|
|
97 |
0
| logger.debug("Line " + counter + ": " + line);
|
|
98 |
| } |
|
99 |
| |
|
100 |
116
| if (line.startsWith("//")) {
|
|
101 |
2
| continue;
|
|
102 |
| } |
|
103 |
| |
|
104 |
114
| if (line.equals("CONVERT_URL_TO_LOWERCASE_BEFORE_COMPARISON")) {
|
|
105 |
12
| if (logger.isDebugEnabled()) {
|
|
106 |
0
| logger.debug("Line " + counter
|
|
107 |
| + ": Instructing mapper to convert URLs to lowercase before comparison"); |
|
108 |
| } |
|
109 |
| |
|
110 |
12
| source.setConvertUrlToLowercaseBeforeComparison(true);
|
|
111 |
| |
|
112 |
12
| continue;
|
|
113 |
| } |
|
114 |
| |
|
115 |
102
| if (line.lastIndexOf('=') == -1) {
|
|
116 |
45
| continue;
|
|
117 |
| } |
|
118 |
| |
|
119 |
| |
|
120 |
57
| String[] nameValue = StringUtils.delimitedListToStringArray(line,
|
|
121 |
| "="); |
|
122 |
57
| String name = nameValue[0];
|
|
123 |
57
| String value = nameValue[1];
|
|
124 |
| |
|
125 |
| |
|
126 |
57
| ConfigAttributeEditor configAttribEd = new ConfigAttributeEditor();
|
|
127 |
57
| configAttribEd.setAsText(value);
|
|
128 |
| |
|
129 |
57
| ConfigAttributeDefinition attr = (ConfigAttributeDefinition) configAttribEd
|
|
130 |
| .getValue(); |
|
131 |
| |
|
132 |
| |
|
133 |
57
| source.addSecureUrl(name, attr);
|
|
134 |
| } |
|
135 |
| } |
|
136 |
| |
|
137 |
32
| setValue(source);
|
|
138 |
| } |
|
139 |
| } |