Java OpenSAML库中是否有用于检查SAML2令牌过期的API?

Java OpenSAML库中是否有用于检查SAML2令牌过期的API?,java,opensaml,Java,Opensaml,我正在使用OpenSAML库生成SAML2令牌。我的印象是,令牌的验证签名也会检查其到期时间,但情况显然并非如此。库是否提供了API,我可以使用它来检查过期情况? 类似于以下代码段中的checkIfExpired(): public static boolean validateSignature(String token, Credential credential) { try { InputStream in = new ByteArrayInput

我正在使用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,我希望避免手动执行此操作。

检查断言是否过期的方法是检查断言中的条件。像这样的

if (assertion.getConditions().getNotBefore() != null && assertion.getConditions().getNotBefore().isAfterNow()) {
    throw new ValidationException("Condition states that assertion is not yet valid (is the server time correct?)");
}

if (assertion.getConditions().getNotOnOrAfter() != null
                && (assertion.getConditions().getNotOnOrAfter().isBeforeNow() || assertion.getConditions().getNotOnOrAfter().isEqualNow())) {
    throw new ValidationException("Condition states that assertion is no longer valid (is the server time correct?)");
}

就我现在所知,没有更简单的方法可以做到这一点。正确的方法可能是编写一个验证器,或者扩展ConditionsSpecValidator。此验证器不会自行验证所有条件

谢谢Stefan。这很有用。因为这是一个非常常见的用例,我希望他们能将它合并到他们的标准API中。我会在他们的邮件列表上给他们发封邮件,看看他们怎么说。发布一个缺少如此重要的东西的验证器似乎很奇怪。我已经与开发团队联系过,他们已经在以后的版本中将验证器一起删除了。这是邮件线索