01: /* Copyright 2004, 2005, 2006 Acegi Technology Pty Limited
02: *
03: * Licensed under the Apache License, Version 2.0 (the "License");
04: * you may not use this file except in compliance with the License.
05: * You may obtain a copy of the License at
06: *
07: * http://www.apache.org/licenses/LICENSE-2.0
08: *
09: * Unless required by applicable law or agreed to in writing, software
10: * distributed under the License is distributed on an "AS IS" BASIS,
11: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12: * See the License for the specific language governing permissions and
13: * limitations under the License.
14: */
15:
16: package org.acegisecurity;
17:
18: import org.acegisecurity.providers.anonymous.AnonymousAuthenticationToken;
19: import org.acegisecurity.providers.rememberme.RememberMeAuthenticationToken;
20:
21: /**
22: * Basic implementation of {@link AuthenticationTrustResolver}.<p>Makes trust decisions based on whether the passed
23: * <code>Authentication</code> is an instance of a defined class.</p>
24: * <p>If {@link #anonymousClass} or {@link #rememberMeClass} is <code>null</code>, the corresponding method will
25: * always return <code>false</code>.</p>
26: *
27: * @author Ben Alex
28: * @version $Id: AuthenticationTrustResolverImpl.java 1496 2006-05-23 13:38:33Z benalex $
29: */
30: public class AuthenticationTrustResolverImpl implements
31: AuthenticationTrustResolver {
32: //~ Instance fields ================================================================================================
33:
34: private Class anonymousClass = AnonymousAuthenticationToken.class;
35: private Class rememberMeClass = RememberMeAuthenticationToken.class;
36:
37: //~ Methods ========================================================================================================
38:
39: public Class getAnonymousClass() {
40: return anonymousClass;
41: }
42:
43: public Class getRememberMeClass() {
44: return rememberMeClass;
45: }
46:
47: public boolean isAnonymous(Authentication authentication) {
48: if ((anonymousClass == null) || (authentication == null)) {
49: return false;
50: }
51:
52: return anonymousClass.isAssignableFrom(authentication
53: .getClass());
54: }
55:
56: public boolean isRememberMe(Authentication authentication) {
57: if ((rememberMeClass == null) || (authentication == null)) {
58: return false;
59: }
60:
61: return rememberMeClass.isAssignableFrom(authentication
62: .getClass());
63: }
64:
65: public void setAnonymousClass(Class anonymousClass) {
66: this .anonymousClass = anonymousClass;
67: }
68:
69: public void setRememberMeClass(Class rememberMeClass) {
70: this.rememberMeClass = rememberMeClass;
71: }
72: }
|