|
1 |
| |
|
2 |
| |
|
3 |
| |
|
4 |
| |
|
5 |
| |
|
6 |
| |
|
7 |
| |
|
8 |
| |
|
9 |
| |
|
10 |
| |
|
11 |
| |
|
12 |
| |
|
13 |
| |
|
14 |
| |
|
15 |
| |
|
16 |
| package org.acegisecurity.vote; |
|
17 |
| |
|
18 |
| import java.util.Iterator; |
|
19 |
| import java.util.List; |
|
20 |
| |
|
21 |
| import org.acegisecurity.AccessDecisionManager; |
|
22 |
| import org.acegisecurity.AcegiMessageSource; |
|
23 |
| import org.acegisecurity.ConfigAttribute; |
|
24 |
| import org.springframework.beans.factory.InitializingBean; |
|
25 |
| import org.springframework.context.MessageSource; |
|
26 |
| import org.springframework.context.MessageSourceAware; |
|
27 |
| import org.springframework.context.support.MessageSourceAccessor; |
|
28 |
| import org.springframework.util.Assert; |
|
29 |
| |
|
30 |
| |
|
31 |
| |
|
32 |
| |
|
33 |
| |
|
34 |
| |
|
35 |
| |
|
36 |
| |
|
37 |
| |
|
38 |
| |
|
39 |
| |
|
40 |
| public abstract class AbstractAccessDecisionManager |
|
41 |
| implements AccessDecisionManager, InitializingBean, MessageSourceAware { |
|
42 |
| |
|
43 |
| |
|
44 |
| private List decisionVoters; |
|
45 |
| protected MessageSourceAccessor messages = AcegiMessageSource.getAccessor(); |
|
46 |
| private boolean allowIfAllAbstainDecisions = false; |
|
47 |
| |
|
48 |
| |
|
49 |
| |
|
50 |
1
| public void afterPropertiesSet() throws Exception {
|
|
51 |
1
| checkIfValidList(this.decisionVoters);
|
|
52 |
0
| Assert.notNull(this.messages, "A message source must be set");
|
|
53 |
| } |
|
54 |
| |
|
55 |
27
| private void checkIfValidList(List listToCheck) {
|
|
56 |
27
| if ((listToCheck == null) || (listToCheck.size() == 0)) {
|
|
57 |
3
| throw new IllegalArgumentException(
|
|
58 |
| "A list of AccessDecisionVoters is required"); |
|
59 |
| } |
|
60 |
| } |
|
61 |
| |
|
62 |
24
| public List getDecisionVoters() {
|
|
63 |
24
| return this.decisionVoters;
|
|
64 |
| } |
|
65 |
| |
|
66 |
14
| public boolean isAllowIfAllAbstainDecisions() {
|
|
67 |
14
| return allowIfAllAbstainDecisions;
|
|
68 |
| } |
|
69 |
| |
|
70 |
4
| public void setAllowIfAllAbstainDecisions(
|
|
71 |
| boolean allowIfAllAbstainDecisions) { |
|
72 |
4
| this.allowIfAllAbstainDecisions = allowIfAllAbstainDecisions;
|
|
73 |
| } |
|
74 |
| |
|
75 |
26
| public void setDecisionVoters(List newList) {
|
|
76 |
26
| checkIfValidList(newList);
|
|
77 |
| |
|
78 |
24
| Iterator iter = newList.iterator();
|
|
79 |
| |
|
80 |
24
| while (iter.hasNext()) {
|
|
81 |
68
| Object currentObject = null;
|
|
82 |
| |
|
83 |
68
| try {
|
|
84 |
68
| currentObject = iter.next();
|
|
85 |
| |
|
86 |
68
| AccessDecisionVoter attemptToCast = (AccessDecisionVoter) currentObject;
|
|
87 |
| } catch (ClassCastException cce) { |
|
88 |
1
| throw new IllegalArgumentException("AccessDecisionVoter "
|
|
89 |
| + currentObject.getClass().getName() |
|
90 |
| + " must implement AccessDecisionVoter"); |
|
91 |
| } |
|
92 |
| } |
|
93 |
| |
|
94 |
23
| this.decisionVoters = newList;
|
|
95 |
| } |
|
96 |
| |
|
97 |
0
| public void setMessageSource(MessageSource messageSource) {
|
|
98 |
0
| this.messages = new MessageSourceAccessor(messageSource);
|
|
99 |
| } |
|
100 |
| |
|
101 |
2
| public boolean supports(ConfigAttribute attribute) {
|
|
102 |
2
| Iterator iter = this.decisionVoters.iterator();
|
|
103 |
| |
|
104 |
2
| while (iter.hasNext()) {
|
|
105 |
4
| AccessDecisionVoter voter = (AccessDecisionVoter) iter.next();
|
|
106 |
| |
|
107 |
4
| if (voter.supports(attribute)) {
|
|
108 |
1
| return true;
|
|
109 |
| } |
|
110 |
| } |
|
111 |
| |
|
112 |
1
| return false;
|
|
113 |
| } |
|
114 |
| |
|
115 |
| |
|
116 |
| |
|
117 |
| |
|
118 |
| |
|
119 |
| |
|
120 |
| |
|
121 |
| |
|
122 |
| |
|
123 |
| |
|
124 |
| |
|
125 |
| |
|
126 |
| |
|
127 |
| |
|
128 |
2
| public boolean supports(Class clazz) {
|
|
129 |
2
| Iterator iter = this.decisionVoters.iterator();
|
|
130 |
| |
|
131 |
2
| while (iter.hasNext()) {
|
|
132 |
4
| AccessDecisionVoter voter = (AccessDecisionVoter) iter.next();
|
|
133 |
| |
|
134 |
4
| if (!voter.supports(clazz)) {
|
|
135 |
1
| return false;
|
|
136 |
| } |
|
137 |
| } |
|
138 |
| |
|
139 |
1
| return true;
|
|
140 |
| } |
|
141 |
| } |