View Javadoc

1   /* Copyright 2004, 2005, 2006 Acegi Technology Pty Limited
2    *
3    * Licensed under the Apache License, Version 2.0 (the "License");
4    * you may not use this file except in compliance with the License.
5    * You may obtain a copy of the License at
6    *
7    *     http://www.apache.org/licenses/LICENSE-2.0
8    *
9    * 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.springframework.security;
17  
18  import org.springframework.security.providers.anonymous.AnonymousAuthenticationToken;
19  import org.springframework.security.providers.rememberme.RememberMeAuthenticationToken;
20  
21  
22  /**
23   * Basic implementation of {@link AuthenticationTrustResolver}.<p>Makes trust decisions based on whether the passed
24   * <code>Authentication</code> is an instance of a defined class.</p>
25   *  <p>If {@link #anonymousClass} or {@link #rememberMeClass} is <code>null</code>, the corresponding method will
26   * always return <code>false</code>.</p>
27   *
28   * @author Ben Alex
29   * @version $Id: AuthenticationTrustResolverImpl.java 2217 2007-10-27 00:45:30Z luke_t $
30   */
31  public class AuthenticationTrustResolverImpl implements 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.getClass());
53      }
54  
55      public boolean isRememberMe(Authentication authentication) {
56          if ((rememberMeClass == null) || (authentication == null)) {
57              return false;
58          }
59  
60          return rememberMeClass.isAssignableFrom(authentication.getClass());
61      }
62  
63      public void setAnonymousClass(Class anonymousClass) {
64          this.anonymousClass = anonymousClass;
65      }
66  
67      public void setRememberMeClass(Class rememberMeClass) {
68          this.rememberMeClass = rememberMeClass;
69      }
70  }