View Javadoc

    1   /* Copyright 2004 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 java.io.Serializable;
    19
    20
    21  /***
    22   * Basic concrete implementation of a {@link GrantedAuthority}.
    23   *
    24   * <p>
    25   * Stores a <code>String</code> representation of an authority granted to  the
    26   * {@link Authentication} object.
    27   * </p>
    28   *
    29   * @author Ben Alex
    30   * @version $Id: GrantedAuthorityImpl.java,v 1.5 2005/11/17 00:55:49 benalex Exp $
    31   */
    32  public class GrantedAuthorityImpl implements GrantedAuthority, Serializable {
    33      //~ Instance fields ========================================================
    34
    35      private String role;
    36
    37      //~ Constructors ===========================================================
    38
    39      public GrantedAuthorityImpl(String role) {
    40          super();
    41          this.role = role;
    42      }
    43
    44      protected GrantedAuthorityImpl() {
    45          throw new IllegalArgumentException("Cannot use default constructor");
    46      }
    47
    48      //~ Methods ================================================================
    49
    50      public String getAuthority() {
    51          return this.role;
    52      }
    53
    54      public boolean equals(Object obj) {
    55          if (obj instanceof String) {
    56              return obj.equals(this.role);
    57          }
    58
    59          if (obj instanceof GrantedAuthority) {
    60              GrantedAuthority attr = (GrantedAuthority) obj;
    61
    62              return this.role.equals(attr.getAuthority());
    63          }
    64
    65          return false;
    66      }
    67
    68      public int hashCode() {
    69          return this.role.hashCode();
    70      }
    71
    72      public String toString() {
    73          return this.role;
    74      }
    75  }