|
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.Authentication; |
|
19 |
| import org.acegisecurity.AuthenticationTrustResolver; |
|
20 |
| import org.acegisecurity.AuthenticationTrustResolverImpl; |
|
21 |
| import org.acegisecurity.ConfigAttribute; |
|
22 |
| import org.acegisecurity.ConfigAttributeDefinition; |
|
23 |
| |
|
24 |
| import org.springframework.util.Assert; |
|
25 |
| |
|
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 |
| public class AuthenticatedVoter implements AccessDecisionVoter { |
|
59 |
| |
|
60 |
| |
|
61 |
| public static final String IS_AUTHENTICATED_FULLY = "IS_AUTHENTICATED_FULLY"; |
|
62 |
| public static final String IS_AUTHENTICATED_REMEMBERED = "IS_AUTHENTICATED_REMEMBERED"; |
|
63 |
| public static final String IS_AUTHENTICATED_ANONYMOUSLY = "IS_AUTHENTICATED_ANONYMOUSLY"; |
|
64 |
| |
|
65 |
| |
|
66 |
| |
|
67 |
| private AuthenticationTrustResolver authenticationTrustResolver = new AuthenticationTrustResolverImpl(); |
|
68 |
| |
|
69 |
| |
|
70 |
| |
|
71 |
1
| public void setAuthenticationTrustResolver(
|
|
72 |
| AuthenticationTrustResolver authenticationTrustResolver) { |
|
73 |
1
| Assert.notNull(authenticationTrustResolver,
|
|
74 |
| "AuthenticationTrustResolver cannot be set to null"); |
|
75 |
0
| this.authenticationTrustResolver = authenticationTrustResolver;
|
|
76 |
| } |
|
77 |
| |
|
78 |
13
| public boolean supports(ConfigAttribute attribute) {
|
|
79 |
13
| if ((attribute.getAttribute() != null)
|
|
80 |
| && (IS_AUTHENTICATED_FULLY.equals(attribute.getAttribute()) |
|
81 |
| || IS_AUTHENTICATED_REMEMBERED.equals(attribute.getAttribute()) |
|
82 |
| || IS_AUTHENTICATED_ANONYMOUSLY.equals(attribute.getAttribute()))) { |
|
83 |
12
| return true;
|
|
84 |
| } else { |
|
85 |
1
| return false;
|
|
86 |
| } |
|
87 |
| } |
|
88 |
| |
|
89 |
| |
|
90 |
| |
|
91 |
| |
|
92 |
| |
|
93 |
| |
|
94 |
| |
|
95 |
| |
|
96 |
| |
|
97 |
1
| public boolean supports(Class clazz) {
|
|
98 |
1
| return true;
|
|
99 |
| } |
|
100 |
| |
|
101 |
9
| public int vote(Authentication authentication, Object object,
|
|
102 |
| ConfigAttributeDefinition config) { |
|
103 |
9
| int result = ACCESS_ABSTAIN;
|
|
104 |
9
| Iterator iter = config.getConfigAttributes();
|
|
105 |
| |
|
106 |
9
| while (iter.hasNext()) {
|
|
107 |
9
| ConfigAttribute attribute = (ConfigAttribute) iter.next();
|
|
108 |
| |
|
109 |
9
| if (this.supports(attribute)) {
|
|
110 |
9
| result = ACCESS_DENIED;
|
|
111 |
| |
|
112 |
9
| if (IS_AUTHENTICATED_FULLY.equals(attribute.getAttribute())) {
|
|
113 |
3
| if (isFullyAuthenticated(authentication)) {
|
|
114 |
1
| return ACCESS_GRANTED;
|
|
115 |
| } |
|
116 |
| } |
|
117 |
| |
|
118 |
8
| if (IS_AUTHENTICATED_REMEMBERED.equals(attribute.getAttribute())) {
|
|
119 |
3
| if (authenticationTrustResolver.isRememberMe(authentication)
|
|
120 |
| || isFullyAuthenticated(authentication)) { |
|
121 |
2
| return ACCESS_GRANTED;
|
|
122 |
| } |
|
123 |
| } |
|
124 |
| |
|
125 |
6
| if (IS_AUTHENTICATED_ANONYMOUSLY.equals(
|
|
126 |
| attribute.getAttribute())) { |
|
127 |
3
| if (authenticationTrustResolver.isAnonymous(authentication)
|
|
128 |
| || isFullyAuthenticated(authentication) |
|
129 |
| || authenticationTrustResolver.isRememberMe( |
|
130 |
| authentication)) { |
|
131 |
3
| return ACCESS_GRANTED;
|
|
132 |
| } |
|
133 |
| } |
|
134 |
| } |
|
135 |
| } |
|
136 |
| |
|
137 |
3
| return result;
|
|
138 |
| } |
|
139 |
| |
|
140 |
7
| private boolean isFullyAuthenticated(Authentication authentication) {
|
|
141 |
7
| return (!authenticationTrustResolver.isAnonymous(authentication)
|
|
142 |
| && !authenticationTrustResolver.isRememberMe(authentication)); |
|
143 |
| } |
|
144 |
| } |