View Javadoc

    1   /*
    2    * Copyright 2006 University Corporation for Advanced Internet Development, Inc.
    3    *
    4    * Licensed under the Apache License, Version 2.0 (the "License");
    5    * you may not use this file except in compliance with the License.
    6    * You may obtain a copy of the License at
    7    *
    8    * http://www.apache.org/licenses/LICENSE-2.0
    9    *
    10   * Unless required by applicable law or agreed to in writing, software
    11   * distributed under the License is distributed on an "AS IS" BASIS,
    12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    13   * See the License for the specific language governing permissions and
    14   * limitations under the License.
    15   */
    16
    17  package edu.internet2.middleware.shibboleth.idp.session.impl;
    18
    19  import org.joda.time.DateTime;
    20  import org.joda.time.chrono.ISOChronology;
    21
    22  import edu.internet2.middleware.shibboleth.idp.session.AuthenticationMethodInformation;
    23  import edu.internet2.middleware.shibboleth.idp.session.ServiceInformation;
    24
    25  /** Information about a service a user has logged in to. */
    26  public class ServiceInformationImpl implements ServiceInformation {
    27
    28      /** Serial version UID. */
    29      private static final long serialVersionUID = 1185342879825302743L;
    30
    31      /** Entity ID of the service. */
    32      private String entityID;
    33
    34      /** Instant the user was authenticated to the service. */
    35      private long authenticationInstant;
    36
    37      /** Authentication method used to authenticate the user to the service. */
    38      private AuthenticationMethodInformation methodInfo;
    39
    40      /**
    41       * Default constructor.
    42       *
    43       * @param id unique identifier for the service.
    44       * @param loginInstant time the user logged in to the service.
    45       * @param method authentication method used to log into the service.
    46       */
    47      public ServiceInformationImpl(String id, DateTime loginInstant, AuthenticationMethodInformation method) {
    48          entityID = id;
    49          authenticationInstant = loginInstant.toDateTime(ISOChronology.getInstanceUTC()).getMillis();
    50          methodInfo = method;
    51      }
    52
    53      /** {@inheritDoc} */
    54      public synchronized String getEntityID() {
    55          return entityID;
    56      }
    57
    58      /** {@inheritDoc} */
    59      public synchronized DateTime getLoginInstant() {
    60          return new DateTime(authenticationInstant, ISOChronology.getInstanceUTC());
    61      }
    62
    63      /** {@inheritDoc} */
    64      public synchronized AuthenticationMethodInformation getAuthenticationMethod() {
    65          return methodInfo;
    66      }
    67
    68      /** {@inheritDoc} */
    69      public synchronized int hashCode() {
    70          return entityID.hashCode();
    71      }
    72
    73      /** {@inheritDoc} */
    74      public synchronized boolean equals(Object obj) {
    75          if (obj == this) {
    76              return true;
    77          }
    78
    79          if (!(obj instanceof ServiceInformation)) {
    80              return false;
    81          }
    82
    83          ServiceInformation si = (ServiceInformation) obj;
    84          return entityID.equals(si.getEntityID());
    85      }
    86  }