View Javadoc

    1   /* Copyright 2004, 2005 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.acegisecurity;
    17
    18  import org.acegisecurity.providers.anonymous.AnonymousAuthenticationToken;
    19  import org.acegisecurity.providers.rememberme.RememberMeAuthenticationToken;
    20
    21
    22  /***
    23   * Basic implementation of {@link AuthenticationTrustResolver}.
    24   *
    25   * <p>
    26   * Makes trust decisions based on whether the passed
    27   * <code>Authentication</code> is an instance of a defined class.
    28   * </p>
    29   *
    30   * <p>
    31   * If {@link #anonymousClass} or {@link #rememberMeClass} is <code>null</code>,
    32   * the corresponding method will always return <code>false</code>.
    33   * </p>
    34   *
    35   * @author Ben Alex
    36   * @version $Id: AuthenticationTrustResolverImpl.java,v 1.4 2005/11/17 00:55:49 benalex Exp $
    37   */
    38  public class AuthenticationTrustResolverImpl
    39      implements AuthenticationTrustResolver {
    40      //~ Instance fields ========================================================
    41
    42      private Class anonymousClass = AnonymousAuthenticationToken.class;
    43      private Class rememberMeClass = RememberMeAuthenticationToken.class;
    44
    45      //~ Methods ================================================================
    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 void setAnonymousClass(Class anonymousClass) {
    56          this.anonymousClass = anonymousClass;
    57      }
    58
    59      public Class getAnonymousClass() {
    60          return anonymousClass;
    61      }
    62
    63      public boolean isRememberMe(Authentication authentication) {
    64          if ((rememberMeClass == null) || (authentication == null)) {
    65              return false;
    66          }
    67
    68          return rememberMeClass.isAssignableFrom(authentication.getClass());
    69      }
    70
    71      public void setRememberMeClass(Class rememberMeClass) {
    72          this.rememberMeClass = rememberMeClass;
    73      }
    74
    75      public Class getRememberMeClass() {
    76          return rememberMeClass;
    77      }
    78  }