|
1 |
| |
|
2 |
| |
|
3 |
| |
|
4 |
| |
|
5 |
| |
|
6 |
| |
|
7 |
| |
|
8 |
| |
|
9 |
| |
|
10 |
| |
|
11 |
| |
|
12 |
| |
|
13 |
| |
|
14 |
| |
|
15 |
| |
|
16 |
| package org.acegisecurity.vote; |
|
17 |
| |
|
18 |
| import org.acegisecurity.AccessDeniedException; |
|
19 |
| import org.acegisecurity.Authentication; |
|
20 |
| import org.acegisecurity.ConfigAttributeDefinition; |
|
21 |
| |
|
22 |
| import org.apache.commons.logging.Log; |
|
23 |
| import org.apache.commons.logging.LogFactory; |
|
24 |
| |
|
25 |
| import java.util.Iterator; |
|
26 |
| |
|
27 |
| |
|
28 |
| |
|
29 |
| |
|
30 |
| |
|
31 |
| |
|
32 |
| |
|
33 |
| public class ConsensusBased extends AbstractAccessDecisionManager { |
|
34 |
| |
|
35 |
| |
|
36 |
| private static final Log logger = LogFactory.getLog(ConsensusBased.class); |
|
37 |
| |
|
38 |
| |
|
39 |
| |
|
40 |
| private boolean allowIfEqualGrantedDeniedDecisions = true; |
|
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 |
7
| public void decide(Authentication authentication, Object object,
|
|
69 |
| ConfigAttributeDefinition config) throws AccessDeniedException { |
|
70 |
7
| Iterator iter = this.getDecisionVoters().iterator();
|
|
71 |
7
| int grant = 0;
|
|
72 |
7
| int deny = 0;
|
|
73 |
7
| int abstain = 0;
|
|
74 |
| |
|
75 |
7
| while (iter.hasNext()) {
|
|
76 |
21
| AccessDecisionVoter voter = (AccessDecisionVoter) iter.next();
|
|
77 |
21
| int result = voter.vote(authentication, object, config);
|
|
78 |
| |
|
79 |
21
| switch (result) {
|
|
80 |
4
| case AccessDecisionVoter.ACCESS_GRANTED:
|
|
81 |
4
| grant++;
|
|
82 |
| |
|
83 |
4
| break;
|
|
84 |
| |
|
85 |
3
| case AccessDecisionVoter.ACCESS_DENIED:
|
|
86 |
3
| deny++;
|
|
87 |
| |
|
88 |
3
| break;
|
|
89 |
| |
|
90 |
14
| default:
|
|
91 |
14
| abstain++;
|
|
92 |
| |
|
93 |
14
| break;
|
|
94 |
| } |
|
95 |
| } |
|
96 |
| |
|
97 |
7
| if (grant > deny) {
|
|
98 |
2
| return;
|
|
99 |
| } |
|
100 |
| |
|
101 |
5
| if (deny > grant) {
|
|
102 |
1
| throw new AccessDeniedException(messages.getMessage(
|
|
103 |
| "AbstractAccessDecisionManager.accessDenied", |
|
104 |
| "Access is denied")); |
|
105 |
| } |
|
106 |
| |
|
107 |
4
| if ((grant == deny) && (grant != 0)) {
|
|
108 |
2
| if (this.allowIfEqualGrantedDeniedDecisions) {
|
|
109 |
1
| return;
|
|
110 |
| } else { |
|
111 |
1
| throw new AccessDeniedException(messages.getMessage(
|
|
112 |
| "AbstractAccessDecisionManager.accessDenied", |
|
113 |
| "Access is denied")); |
|
114 |
| } |
|
115 |
| } |
|
116 |
| |
|
117 |
| |
|
118 |
2
| if (this.isAllowIfAllAbstainDecisions()) {
|
|
119 |
1
| return;
|
|
120 |
| } else { |
|
121 |
1
| throw new AccessDeniedException(messages.getMessage(
|
|
122 |
| "AbstractAccessDecisionManager.accessDenied", |
|
123 |
| "Access is denied")); |
|
124 |
| } |
|
125 |
| } |
|
126 |
| |
|
127 |
2
| public boolean isAllowIfEqualGrantedDeniedDecisions() {
|
|
128 |
2
| return allowIfEqualGrantedDeniedDecisions;
|
|
129 |
| } |
|
130 |
| |
|
131 |
1
| public void setAllowIfEqualGrantedDeniedDecisions(
|
|
132 |
| boolean allowIfEqualGrantedDeniedDecisions) { |
|
133 |
1
| this.allowIfEqualGrantedDeniedDecisions = allowIfEqualGrantedDeniedDecisions;
|
|
134 |
| } |
|
135 |
| } |