|
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.ConfigAttribute; |
|
21 |
| import org.acegisecurity.ConfigAttributeDefinition; |
|
22 |
| |
|
23 |
| import org.apache.commons.logging.Log; |
|
24 |
| import org.apache.commons.logging.LogFactory; |
|
25 |
| |
|
26 |
| import java.util.Iterator; |
|
27 |
| |
|
28 |
| |
|
29 |
| |
|
30 |
| |
|
31 |
| |
|
32 |
| |
|
33 |
| |
|
34 |
| public class UnanimousBased extends AbstractAccessDecisionManager { |
|
35 |
| |
|
36 |
| |
|
37 |
| private static final Log logger = LogFactory.getLog(UnanimousBased.class); |
|
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 |
7
| public void decide(Authentication authentication, Object object,
|
|
68 |
| ConfigAttributeDefinition config) throws AccessDeniedException { |
|
69 |
7
| int grant = 0;
|
|
70 |
7
| int deny = 0;
|
|
71 |
7
| int abstain = 0;
|
|
72 |
| |
|
73 |
7
| Iterator configIter = config.getConfigAttributes();
|
|
74 |
| |
|
75 |
7
| while (configIter.hasNext()) {
|
|
76 |
10
| ConfigAttributeDefinition thisDef = new ConfigAttributeDefinition();
|
|
77 |
10
| thisDef.addConfigAttribute((ConfigAttribute) configIter.next());
|
|
78 |
| |
|
79 |
10
| Iterator voters = this.getDecisionVoters().iterator();
|
|
80 |
| |
|
81 |
10
| while (voters.hasNext()) {
|
|
82 |
30
| AccessDecisionVoter voter = (AccessDecisionVoter) voters.next();
|
|
83 |
30
| int result = voter.vote(authentication, object, thisDef);
|
|
84 |
| |
|
85 |
30
| switch (result) {
|
|
86 |
6
| case AccessDecisionVoter.ACCESS_GRANTED:
|
|
87 |
6
| grant++;
|
|
88 |
| |
|
89 |
6
| break;
|
|
90 |
| |
|
91 |
2
| case AccessDecisionVoter.ACCESS_DENIED:
|
|
92 |
2
| deny++;
|
|
93 |
| |
|
94 |
2
| break;
|
|
95 |
| |
|
96 |
22
| default:
|
|
97 |
22
| abstain++;
|
|
98 |
| |
|
99 |
22
| break;
|
|
100 |
| } |
|
101 |
| } |
|
102 |
| } |
|
103 |
| |
|
104 |
7
| if (deny > 0) {
|
|
105 |
2
| throw new AccessDeniedException(messages.getMessage(
|
|
106 |
| "AbstractAccessDecisionManager.accessDenied", |
|
107 |
| "Access is denied")); |
|
108 |
| } |
|
109 |
| |
|
110 |
| |
|
111 |
5
| if (grant > 0) {
|
|
112 |
3
| return;
|
|
113 |
| } |
|
114 |
| |
|
115 |
| |
|
116 |
2
| if (this.isAllowIfAllAbstainDecisions()) {
|
|
117 |
1
| return;
|
|
118 |
| } else { |
|
119 |
1
| throw new AccessDeniedException(messages.getMessage(
|
|
120 |
| "AbstractAccessDecisionManager.accessDenied", |
|
121 |
| "Access is denied")); |
|
122 |
| } |
|
123 |
| } |
|
124 |
| } |