| 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 |
5 |
public class AuthenticatedVoter implements AccessDecisionVoter { |
| 45 |
|
|
| 46 |
|
|
| 47 |
|
public static final String IS_AUTHENTICATED_FULLY = "IS_AUTHENTICATED_FULLY"; |
| 48 |
|
public static final String IS_AUTHENTICATED_REMEMBERED = "IS_AUTHENTICATED_REMEMBERED"; |
| 49 |
|
public static final String IS_AUTHENTICATED_ANONYMOUSLY = "IS_AUTHENTICATED_ANONYMOUSLY"; |
| 50 |
|
|
| 51 |
|
|
| 52 |
5 |
private AuthenticationTrustResolver authenticationTrustResolver = new AuthenticationTrustResolverImpl(); |
| 53 |
|
|
| 54 |
|
|
| 55 |
|
|
| 56 |
|
private boolean isFullyAuthenticated(Authentication authentication) { |
| 57 |
7 |
return (!authenticationTrustResolver.isAnonymous(authentication) |
| 58 |
|
&& !authenticationTrustResolver.isRememberMe(authentication)); |
| 59 |
|
} |
| 60 |
|
|
| 61 |
|
public void setAuthenticationTrustResolver(AuthenticationTrustResolver authenticationTrustResolver) { |
| 62 |
1 |
Assert.notNull(authenticationTrustResolver, "AuthenticationTrustResolver cannot be set to null"); |
| 63 |
0 |
this.authenticationTrustResolver = authenticationTrustResolver; |
| 64 |
0 |
} |
| 65 |
|
|
| 66 |
|
public boolean supports(ConfigAttribute attribute) { |
| 67 |
13 |
if ((attribute.getAttribute() != null) |
| 68 |
|
&& (IS_AUTHENTICATED_FULLY.equals(attribute.getAttribute()) |
| 69 |
|
|| IS_AUTHENTICATED_REMEMBERED.equals(attribute.getAttribute()) |
| 70 |
|
|| IS_AUTHENTICATED_ANONYMOUSLY.equals(attribute.getAttribute()))) { |
| 71 |
12 |
return true; |
| 72 |
|
} else { |
| 73 |
1 |
return false; |
| 74 |
|
} |
| 75 |
|
} |
| 76 |
|
|
| 77 |
|
|
| 78 |
|
|
| 79 |
|
|
| 80 |
|
|
| 81 |
|
|
| 82 |
|
|
| 83 |
|
|
| 84 |
|
public boolean supports(Class clazz) { |
| 85 |
1 |
return true; |
| 86 |
|
} |
| 87 |
|
|
| 88 |
|
public int vote(Authentication authentication, Object object, ConfigAttributeDefinition config) { |
| 89 |
9 |
int result = ACCESS_ABSTAIN; |
| 90 |
9 |
Iterator iter = config.getConfigAttributes(); |
| 91 |
|
|
| 92 |
12 |
while (iter.hasNext()) { |
| 93 |
9 |
ConfigAttribute attribute = (ConfigAttribute) iter.next(); |
| 94 |
|
|
| 95 |
9 |
if (this.supports(attribute)) { |
| 96 |
9 |
result = ACCESS_DENIED; |
| 97 |
|
|
| 98 |
9 |
if (IS_AUTHENTICATED_FULLY.equals(attribute.getAttribute())) { |
| 99 |
3 |
if (isFullyAuthenticated(authentication)) { |
| 100 |
1 |
return ACCESS_GRANTED; |
| 101 |
|
} |
| 102 |
|
} |
| 103 |
|
|
| 104 |
8 |
if (IS_AUTHENTICATED_REMEMBERED.equals(attribute.getAttribute())) { |
| 105 |
3 |
if (authenticationTrustResolver.isRememberMe(authentication) |
| 106 |
|
|| isFullyAuthenticated(authentication)) { |
| 107 |
2 |
return ACCESS_GRANTED; |
| 108 |
|
} |
| 109 |
|
} |
| 110 |
|
|
| 111 |
6 |
if (IS_AUTHENTICATED_ANONYMOUSLY.equals(attribute.getAttribute())) { |
| 112 |
3 |
if (authenticationTrustResolver.isAnonymous(authentication) || isFullyAuthenticated(authentication) |
| 113 |
|
|| authenticationTrustResolver.isRememberMe(authentication)) { |
| 114 |
3 |
return ACCESS_GRANTED; |
| 115 |
|
} |
| 116 |
|
} |
| 117 |
|
} |
| 118 |
3 |
} |
| 119 |
|
|
| 120 |
3 |
return result; |
| 121 |
|
} |
| 122 |
|
} |