/
TimestampValidationCallback.java
154 lines (124 loc) · 4.55 KB
/
TimestampValidationCallback.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
/*
* Copyright (c) 1997, 2022 Oracle and/or its affiliates. All rights reserved.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Distribution License v. 1.0, which is available at
* http://www.eclipse.org/org/documents/edl-v10.php.
*
* SPDX-License-Identifier: BSD-3-Clause
*/
/*
* TimestampValidationCallback.java
*
* Created on July 12, 2005, 12:54 AM
*
* This callback is intended for Timestamp validation.
* A validator that implements the TimestampValidator interface should
* set on the callback by callback handler.
*/
package com.sun.xml.wss.impl.callback;
import javax.security.auth.callback.Callback;
/**
*
* @author abhijit.das@Sun.COM
*/
public class TimestampValidationCallback extends XWSSCallback implements Callback {
private Request request;
private TimestampValidator validator;
/** Creates a new instance of TimestampValidationCallback */
public TimestampValidationCallback(Request request) {
this.request = request;
}
public void getResult() throws TimestampValidationException {
if (validator == null) {
throw new TimestampValidationException("A Required TimestampValidator object was not set by the CallbackHandler");
}
validator.validate(request);
}
/**
* The CallbackHandler handling this callbacl should set the validator.
*
*/
public void setValidator(TimestampValidator validator) {
this.validator = validator;
if (this.validator instanceof ValidatorExtension) {
((ValidatorExtension)this.validator).setRuntimeProperties(this.getRuntimeProperties());
}
}
public interface Request {
}
public static class UTCTimestampRequest implements Request {
private String created;
private String expired;
private long maxClockSkew = 0;
private long timestampFreshnessLimit = 0;
private boolean isUsernameToken = false;
/**
* Set it to true if the Created Timestamp present inside
* UsernameToken needs to be validated.
*
*/
public void isUsernameToken(boolean isUsernameToken) {
this.isUsernameToken = true;
}
/**
* Check if the Timestamp Created value is coming from UsernameToken
* @return true if Created is inside UsernameToken else false
*/
public boolean isUsernameToken() {
return isUsernameToken;
}
/**
* Constructor.
*
* @param created <code>java.lang.String</code> representaion of Creation time.
* @param expired <code>java.lang.String</code> representation of Expiration time.
* @param maxClockSkew representing the max time difference between sender's
* system time and receiver's system time in milliseconds.
* @param timestampFreshnessLimit representing the maximum time interval for nonce
* cache removal.
*
*/
public UTCTimestampRequest(String created,
String expired,
long maxClockSkew,
long timestampFreshnessLimit) {
this.created = created;
this.expired = expired;
this.maxClockSkew = maxClockSkew;
this.timestampFreshnessLimit = timestampFreshnessLimit;
}
public String getCreated() {
return created;
}
public String getExpired() {
return expired;
}
public long getMaxClockSkew() {
return maxClockSkew;
}
public long getTimestampFreshnessLimit() {
return timestampFreshnessLimit;
}
}
public static class TimestampValidationException extends Exception {
private static final long serialVersionUID = 5390126265884591759L;
public TimestampValidationException(String message) {
super(message);
}
public TimestampValidationException(String message, Throwable cause) {
super(message, cause);
}
public TimestampValidationException(Throwable cause) {
super(cause);
}
}
public interface TimestampValidator {
/**
* Timestamp validation method.
*
* @throws TimestampValidationException if validation does not succeed.
*/
void validate(Request request) throws TimestampValidationException;
}
}