return new InternalSignatureReferenceVerifier((WSSSecurityProperties) securityProperties,
inputProcessorChain, referenceType, startElement);
}
private void detectReplayAttack(InputProcessorChain inputProcessorChain) throws WSSecurityException {
TimestampSecurityEvent timestampSecurityEvent =
inputProcessorChain.getSecurityContext().get(WSSConstants.PROP_TIMESTAMP_SECURITYEVENT);
ReplayCache replayCache =
((WSSSecurityProperties)getSecurityProperties()).getTimestampReplayCache();
if (timestampSecurityEvent != null && replayCache != null) {
final String cacheKey = String.valueOf(
timestampSecurityEvent.getCreated().getTimeInMillis()) +
"" + Arrays.hashCode(getSignatureType().getSignatureValue().getValue());
if (replayCache.contains(cacheKey)) {
throw new WSSecurityException(WSSecurityException.ErrorCode.MESSAGE_EXPIRED);
}
// Store the Timestamp/SignatureValue combination in the cache
Calendar expiresCal = timestampSecurityEvent.getExpires();
if (expiresCal != null) {
Date rightNow = new Date();
long currentTime = rightNow.getTime();
long expiresTime = expiresCal.getTimeInMillis();
replayCache.add(cacheKey, 1L + (expiresTime - currentTime) / 1000L);