簡體   English   中英

OpenSaml加密的ID驗證失敗

[英]OpenSaml encryptedID Validation Failed

我需要加密nameId並在AuthnRequest中發送它。 我遇到了openSaml(v 2.6.1)驗證程序SubjectShemaValidator的問題。 請求驗證失敗,錯誤為“需要ID或SubjectConfirmation”,因為沒有BaseID,BaseID或SubjectConfirmations。

這是我的真實要求:

<saml2p:AuthnRequest AssertionConsumerServiceURL="https:..." ForceAuthn="false" ID="4ed1e8875b99" IssueInstant="2016-01-27T15:39:26.195Z" ProtocolBinding="POST" Version="2.0" xmlns:saml2p="urn:oasis:names:tc:SAML:2.0:protocol"><saml2:Issuer xmlns:saml2="urn:oasis:names:tc:SAML:2.0:assertion">APPLICATION</saml2:Issuer><saml2:Subject xmlns:saml2="urn:oasis:names:tc:SAML:2.0:assertion"><saml2:EncryptedID><xenc:EncryptedData Id="_b8b7761b84db0c4c5254b4f4c3ef9d1d" Type="http://www.w3.org/2001/04/xmlenc#Element" xmlns:xenc="http://www.w3.org/2001/04/xmlenc#"><xenc:EncryptionMethod Algorithm="http://www.w3.org/2001/04/xmlenc#aes128-cbc" xmlns:xenc="http://www.w3.org/2001/04/xmlenc#"/><ds:KeyInfo xmlns:ds="http://www.w3.org/2000/09/xmldsig#"><xenc:EncryptedKey Id="_922bd10322d761ca1a5450213da896ea" xmlns:xenc="http://www.w3.org/2001/04/xmlenc#"><xenc:EncryptionMethod Algorithm="http://www.w3.org/2001/04/xmlenc#rsa-oaep-mgf1p" xmlns:xenc="http://www.w3.org/2001/04/xmlenc#"><ds:DigestMethod Algorithm="http://www.w3.org/2000/09/xmldsig#sha1" xmlns:ds="http://www.w3.org/2000/09/xmldsig#"/></xenc:EncryptionMethod><xenc:CipherData xmlns:xenc="http://www.w3.org/2001/04/xmlenc#"><xenc:CipherValue>ABCD</xenc:CipherValue></xenc:CipherData></xenc:EncryptedKey></ds:KeyInfo><xenc:CipherData xmlns:xenc="http://www.w3.org/2001/04/xmlenc#"><xenc:CipherValue>EFGH</xenc:CipherValue></xenc:CipherData></xenc:EncryptedData></saml2:EncryptedID><saml2:SubjectConfirmation Method="urn:oasis:names:tc:SAML:2.0:cm:bearer"/></saml2:Subject></saml2p:AuthnRequest>

這是OpenSAML驗證程序的錯誤,因為它不檢查EncryptedID嗎? 還是我錯過了什么?

代替nameId的加密,您可以像這樣直接輸入

AuthnRequest request = buildSAMLObject(AuthnRequest.class);


        NameIDPolicy nameIdPolicy = buildSAMLObject(NameIDPolicy.class);
        nameIdPolicy.setAllowCreate(true);
        nameIdPolicy.setFormat(NameIDType.EMAIL);
        request.setNameIDPolicy(nameIdPolicy);


public static <T> T buildSAMLObject(final Class<T> clazz) {
        T object = null;
        try {
            XMLObjectBuilderFactory builderFactory = Configuration
                    .getBuilderFactory();
            QName defaultElementName = (QName) clazz.getDeclaredField(
                    "DEFAULT_ELEMENT_NAME").get(null);
            object = (T) builderFactory.getBuilder(defaultElementName)
                    .buildObject(defaultElementName);
        } catch (IllegalAccessException e) {
            throw new IllegalArgumentException("Could not create SAML object");
        } catch (NoSuchFieldException e) {
            throw new IllegalArgumentException("Could not create SAML object");
        }

        return object;
    }

要變通解決此問題,我必須注銷默認的主題驗證器,並注冊自定義的驗證器(包括EncryptedID)。

validatorSuite = Configuration.getValidatorSuite(SAML_VALIDATOR_SUITE_ID);
    // deregister default subject validator and register customized validator (including EncryptedID).
    List<Validator> validators = validatorSuite.getValidators(Subject.DEFAULT_ELEMENT_NAME);
    if (validators != null && validators.size() > 0) {
        validatorSuite.deregisterValidator(Subject.DEFAULT_ELEMENT_NAME, validators.get(0));
    }
    validatorSuite.registerValidator(Subject.DEFAULT_ELEMENT_NAME, new SubjectSchemaValidator());

希望能幫助到你。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM