1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18 package edu.internet2.middleware.shibboleth.idp.session.impl;
19
20 import java.security.Principal;
21
22 import javax.security.auth.Subject;
23
24 import org.joda.time.DateTime;
25 import org.joda.time.chrono.ISOChronology;
26
27 import edu.internet2.middleware.shibboleth.idp.session.AuthenticationMethodInformation;
28
29
30 public class AuthenticationMethodInformationImpl implements AuthenticationMethodInformation {
31
32
33 private static final long serialVersionUID = -2108905664641155003L;
34
35
36 private Subject authenticationSubject;
37
38
39 private Principal authenticationPrincipal;
40
41
42 private String authenticationMethod;
43
44
45 private long authenticationInstant;
46
47
48 private long authenticationDuration;
49
50
51 private long expirationInstant;
52
53
54
55
56
57
58
59
60
61
62 public AuthenticationMethodInformationImpl(Subject subject, Principal principal, String method, DateTime instant,
63 long duration) {
64
65 if (method == null || instant == null || duration < 0) {
66 throw new IllegalArgumentException("Authentication method, instant, and duration may not be null");
67 }
68
69 authenticationSubject = subject;
70 authenticationPrincipal = principal;
71 authenticationMethod = method;
72 authenticationInstant = instant.toDateTime(ISOChronology.getInstanceUTC()).getMillis();
73 authenticationDuration = duration;
74 expirationInstant = authenticationInstant + duration;
75 }
76
77
78 public synchronized Subject getAuthenticationSubject() {
79 return authenticationSubject;
80 }
81
82
83 public synchronized Principal getAuthenticationPrincipal() {
84 return authenticationPrincipal;
85 }
86
87
88 public synchronized String getAuthenticationMethod() {
89 return authenticationMethod;
90 }
91
92
93 public synchronized DateTime getAuthenticationInstant() {
94 return new DateTime(authenticationInstant, ISOChronology.getInstanceUTC());
95 }
96
97
98 public synchronized long getAuthenticationDuration() {
99 return authenticationDuration;
100 }
101
102
103 public synchronized boolean isExpired() {
104 return new DateTime(expirationInstant, ISOChronology.getInstanceUTC()).isBeforeNow();
105 }
106
107
108 public synchronized int hashCode() {
109 return authenticationMethod.hashCode();
110 }
111
112
113 public synchronized boolean equals(Object obj) {
114 if (obj == this) {
115 return true;
116 }
117
118 if (!(obj instanceof AuthenticationMethodInformation)) {
119 return false;
120 }
121
122 AuthenticationMethodInformation amInfo = (AuthenticationMethodInformation) obj;
123 return authenticationMethod.equals(amInfo.getAuthenticationMethod());
124 }
125 }