我正在使用 OpenSAML 库来生成 SAML2 令牌。我的印象是令牌的验证签名也会检查它的到期情况,显然情况并非如此。是否有库提供的 API 可用于检查过期?就像checkIfExpired()
在下面的代码片段中一样:
public static boolean validateSignature(String token, Credential credential)
{
try {
InputStream in = new ByteArrayInputStream(token.getBytes());
Document inCommonMDDoc = ppMgr.parse(in);
AssertionUnmarshaller unmarshaller = new AssertionUnmarshaller();
Assertion assertion = (Assertion) unmarshaller
.unmarshall(inCommonMDDoc.getDocumentElement());
SignatureValidator validator = new SignatureValidator(credential);
try {
validator.validate(assertion.getSignature());
return checkIfExpired(assertion) ; // -- Checks if assertion has expired and return true/false
} catch (ValidationException e) {
log.error("Invalid Signature", e);
return false;
}
} catch (Exception e) {
log.error("Unable to perform Signature Validation", e);
}
}
注意:如果 OpenSAML 已经有 API,我想避免手动操作。