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