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