4

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 がある場合は、手動で行うことは避けたいと思います。

4

1 に答える 1

4

アサーションの有効期限が切れているかどうかを確認する方法は、アサーションの条件を確認することです。このようなもの。

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 を拡張します。この Validator 自体がすべての条件を検証するわけではありません

于 2013-05-24T07:29:00.767 に答える