2017-01-13 66 views
0

領域我有以下XML響應:如何檢索XML響應

String response = 
+"<saml:AuthnStatement AuthnInstant=\"2016-12-14T12:22:26Z\" SessionIndex=\"s2f1ae3bd7397f10c6fd6b3b3f02d8b0611b2da501\">" 
+"<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=\"uid\">" 
        +"<saml:AttributeValue xmlns:xs=\"http://www.w3.org/2001/XMLSchema\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xsi:type=\"xs:string\">testing1</saml:AttributeValue>" 
        +"</saml:Attribute>" 
        +"<saml:Attribute Name=\"SecurityLevel\">" 
        +"<saml:AttributeValue xmlns:xs=\"http://www.w3.org/2001/XMLSchema\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xsi:type=\"xs:string\">testing2</saml:AttributeValue>" 
        +"</saml:Attribute>" 
        +"<saml:Attribute Name=\"Culture\">" 
        +"<saml:AttributeValue xmlns:xs=\"http://www.w3.org/2001/XMLSchema\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xsi:type=\"xs:string\">testing3</saml:AttributeValue>" 
        +"</saml:Attribute>" 
        +"<saml:Attribute Name=\"AuthMethod\">" 
        +"<saml:AttributeValue xmlns:xs=\"http://www.w3.org/2001/XMLSchema\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xsi:type=\"xs:string\">testing4</saml:AttributeValue>" 
        +"</saml:Attribute>" 
       +"</saml:AttributeStatement>" 
      +"</saml:Assertion>"; 

使用普通字符串函數,子,長,我可以從領域retreive數據。但它是一個漫長而不便的過程。

我如何使用一些java庫來處理這個響應,並從字段中獲取信息?

+0

您可以使用OpenSAML庫來處理SAML消息。你可以在[這裏]找到文檔(https://wiki.shibboleth.net/confluence/display/OpenSAML/Home) – nille85

回答