2014-09-12 51 views
2

我是(或者說,我使用的Net::SAML2庫)試圖規範化XML並獲取命名空間錯誤。我有一個印象,這是正確設置前綴列表的問題,但我不知道應該在什麼格式。(Net::SAML2似乎試圖生成一個列表,但出現空的。)示例代碼:使用XML前綴列表指定嵌套命名空間:: CanonicalizeXML

use XML::CanonicalizeXML; 

my $xml = '<saml:Assertion xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" Version="2.0" ID="pfx894bbcab-a4d3-7694-5b56-26dc207e3479" IssueInstant="2014-09-12T01:51:30Z"><saml:Issuer>http://example.com/metadata</saml:Issuer><saml:Subject><saml:NameID Format="urn:oasis:names:tc:SAML:2.0:nameid-format:transient">[email protected]</saml:NameID><saml:SubjectConfirmation Method="urn:oasis:names:tc:SAML:2.0:cm:bearer"><saml:SubjectConfirmationData NotOnOrAfter="2014-09-12T01:54:30Z" Recipient="{recipient}" InResponseTo="3e19c9272c04531d0c01643749e9dfda" /></saml:SubjectConfirmation></saml:Subject><saml:Conditions NotBefore="2014-09-12T01:48:30Z" NotOnOrAfter="2014-09-12T01:54:30Z"><saml:AudienceRestriction><saml:Audience>{audience}</saml:Audience></saml:AudienceRestriction></saml:Conditions><saml:AuthnStatement AuthnInstant="2014-09-12T01:51:29Z" SessionNotOnOrAfter="2014-09-13T01:51:30Z" SessionIndex="_59f97890-1bff-0132-6393-782bcb56fcaa"><saml:AuthnContext><saml:AuthnContextClassRef>urn:oasis:names:tc:SAML:2.0:ac:classes:PasswordProtectedTransport</saml:AuthnContextClassRef></saml:AuthnContext></saml:AuthnStatement><saml:AttributeStatement><saml:Attribute Name="first_name" NameFormat="urn:oasis:names:tc:SAML:2.0:attrname-format:basic"><saml:AttributeValue xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="xs:string">Billy</saml:AttributeValue></saml:Attribute></saml:AttributeStatement></saml:Assertion>'; 
my $xpath = '<XPath>(//. | //@* | //namespace::*)</XPath>'; 
my $prefixlist = ''; 
my $canon = XML::CanonicalizeXML::canonicalize($xml,$xpath,$prefixlist,1,0); 

產生這些警告:

namespace error : Namespace prefix saml on Assertion is not defined 
ID="pfx894bbcab-a4d3-7694-5b56-26dc207e3479" IssueInstant="2014-09-12T01:51:30Z" 
                      ^
namespace error : Namespace prefix saml on Issuer is not defined 
ab-a4d3-7694-5b56-26dc207e3479" IssueInstant="2014-09-12T01:51:30Z"><saml:Issuer 
                      ^
namespace error : Namespace prefix saml on Subject is not defined 
2T01:51:30Z"><saml:Issuer>http://example.com/metadata</saml:Issuer><saml:Subject 
                      ^
namespace error : Namespace prefix saml on NameID is not defined 
ubject><saml:NameID Format="urn:oasis:names:tc:SAML:2.0:nameid-format:transient" 
                      ^
namespace error : Namespace prefix saml on SubjectConfirmation is not defined 
:NameID><saml:SubjectConfirmation Method="urn:oasis:names:tc:SAML:2.0:cm:bearer" 
                      ^
namespace error : Namespace prefix saml on SubjectConfirmationData is not defined 
54:30Z" Recipient="{recipient}" InResponseTo="3e19c9272c04531d0c01643749e9dfda" 
                      ^
namespace error : Namespace prefix saml on Conditions is not defined 
:Conditions NotBefore="2014-09-12T01:48:30Z" NotOnOrAfter="2014-09-12T01:54:30Z" 
                      ^
namespace error : Namespace prefix saml on AudienceRestriction is not defined 
4-09-12T01:48:30Z" NotOnOrAfter="2014-09-12T01:54:30Z"><saml:AudienceRestriction 
                      ^
namespace error : Namespace prefix saml on Audience is not defined 
0Z" NotOnOrAfter="2014-09-12T01:54:30Z"><saml:AudienceRestriction><saml:Audience 
                      ^
namespace error : Namespace prefix saml on AuthnStatement is not defined 
fter="2014-09-13T01:51:30Z" SessionIndex="_59f97890-1bff-0132-6393-782bcb56fcaa" 
                      ^
namespace error : Namespace prefix saml on AuthnContext is not defined 
:51:30Z" SessionIndex="_59f97890-1bff-0132-6393-782bcb56fcaa"><saml:AuthnContext 
                      ^
namespace error : Namespace prefix saml on AuthnContextClassRef is not defined 
97890-1bff-0132-6393-782bcb56fcaa"><saml:AuthnContext><saml:AuthnContextClassRef 
                      ^
namespace error : Namespace prefix saml on AttributeStatement is not defined 
ntextClassRef></saml:AuthnContext></saml:AuthnStatement><saml:AttributeStatement 
                      ^
namespace error : Namespace prefix saml on Attribute is not defined 
Name="first_name" NameFormat="urn:oasis:names:tc:SAML:2.0:attrname-format:basic" 
                      ^
namespace error : Namespace prefix saml on AttributeValue is not defined 
Value xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="xs:string" 
                      ^

回答

0

你錯過

xmlns:saml="..." 

的價值?貌似

xmlns:saml="urn:oasis:names:tc:SAML:1.0:assertion" 

xmlns:saml="urn:oasis:names:tc:SAML:2.0:assertion" 

在文檔中urn:oasis:names:tc:SAML:2.0:...情況的羣衆基礎,這顯然是後者。

+0

是的,這個較大的文檔是一個片段,但我需要這個片段規範化。似乎有一種方法可以告訴規範者關於在外部範圍中聲明的名稱空間,但我不知道正確的語法。 – ysth 2014-09-14 03:17:01

+0

有一種方法來指定它,並且我展示了它是什麼。 XML文檔是獨立的。沒有更大的範圍。我不太清楚第三個參數是什麼,但它應該是一個逗號分隔*前綴列表*(傳遞給['xmlC14NExecute'](http://xmlsoft.org/html/libxml-c14n.html #xmlC14NExecute)),它確實用於*控制輸出*,不定義名稱空間。 – ikegami 2014-09-14 18:23:01