@@ -53,77 +53,76 @@ public void loadXmlFromBase64(String response) throws ParserConfigurationExcepti
5353 loadXml (decodedS );
5454 }
5555
56- public boolean isValid () throws Exception {
57- NodeList nodes = xmlDoc .getElementsByTagNameNS (XMLSignature .XMLNS , "Signature" );
56+ public boolean isValid () throws Exception {
57+ NodeList nodes = xmlDoc .getElementsByTagNameNS (XMLSignature .XMLNS , "Signature" );
5858
59- if (nodes == null || nodes .getLength () == 0 ) {
60- throw new Exception ("Can't find signature in document." );
61- }
59+ if (nodes == null || nodes .getLength () == 0 ) {
60+ throw new Exception ("Can't find signature in document." );
61+ }
6262
63- if (setIdAttributeExists ()) {
64- tagIdAttributes (xmlDoc );
65- }
63+ if (setIdAttributeExists ()) {
64+ tagIdAttributes (xmlDoc );
65+ }
6666
67- X509Certificate cert = certificate .getX509Cert ();
68- DOMValidateContext ctx = new DOMValidateContext (cert .getPublicKey (), nodes .item (0 ));
69- XMLSignatureFactory sigF = XMLSignatureFactory .getInstance ("DOM" );
70- XMLSignature xmlSignature = sigF .unmarshalXMLSignature (ctx );
67+ X509Certificate cert = certificate .getX509Cert ();
68+ DOMValidateContext ctx = new DOMValidateContext (cert .getPublicKey (), nodes .item (0 ));
69+ XMLSignatureFactory sigF = XMLSignatureFactory .getInstance ("DOM" );
70+ XMLSignature xmlSignature = sigF .unmarshalXMLSignature (ctx );
7171
72- return xmlSignature .validate (ctx );
73- }
72+ return xmlSignature .validate (ctx );
73+ }
7474
7575 public String getNameId () throws Exception {
76- NodeList nodes = xmlDoc .getElementsByTagNameNS ("urn:oasis:names:tc:SAML:2.0:assertion" , "NameID" );
76+ NodeList nodes = xmlDoc .getElementsByTagNameNS ("urn:oasis:names:tc:SAML:2.0:assertion" , "NameID" );
7777
78- if (nodes .getLength ()==0 ){
79- throw new Exception ("No name id found in document" );
80- }
78+ if (nodes .getLength ()==0 ){
79+ throw new Exception ("No name id found in document" );
80+ }
8181
82- return nodes .item (0 ).getTextContent ();
82+ return nodes .item (0 ).getTextContent ();
8383 }
8484
85- public String getAttribute (String name ) {
86- HashMap attributes = getAttributes ();
87- if (!attributes .isEmpty ()) {
88- return attributes .get (name ).toString ();
89- }
90- return null ;
91- }
85+ public String getAttribute (String name ) {
86+ HashMap attributes = getAttributes ();
87+ if (!attributes .isEmpty ()) {
88+ return attributes .get (name ).toString ();
89+ }
90+ return null ;
91+ }
9292
93- public HashMap getAttributes () {
94- HashMap <String ,ArrayList > attributes = new HashMap <>();
95- NodeList nodes = xmlDoc .getElementsByTagNameNS ("urn:oasis:names:tc:SAML:2.0:assertion" , "Attribute" );
96-
97- if (nodes .getLength ()!=0 ){
98- for (int i = 0 ; i < nodes .getLength (); i ++) {
99- NamedNodeMap attrName = nodes .item (i ).getAttributes ();
100- String attName = attrName .getNamedItem ("Name" ).getNodeValue ();
101- NodeList children = nodes .item (i ).getChildNodes ();
102-
103- ArrayList <String > attrValues = new ArrayList <String >();
104- for (int j = 0 ; j < children .getLength (); j ++) {
105- attrValues .add (children .item (j ).getTextContent ());
106- }
107- attributes .put (attName , attrValues );
108- }
109- } else
110- return null ;
111- return attributes ;
93+ public HashMap getAttributes () {
94+ HashMap <String ,ArrayList > attributes = new HashMap <>();
95+ NodeList nodes = xmlDoc .getElementsByTagNameNS ("urn:oasis:names:tc:SAML:2.0:assertion" , "Attribute" );
96+
97+ if (nodes .getLength ()!=0 ){
98+ for (int i = 0 ; i < nodes .getLength (); i ++) {
99+ NamedNodeMap attrName = nodes .item (i ).getAttributes ();
100+ String attName = attrName .getNamedItem ("Name" ).getNodeValue ();
101+ NodeList children = nodes .item (i ).getChildNodes ();
102+
103+ ArrayList <String > attrValues = new ArrayList <String >();
104+ for (int j = 0 ; j < children .getLength (); j ++) {
105+ attrValues .add (children .item (j ).getTextContent ());
106+ }
107+ attributes .put (attName , attrValues );
108+ }
109+ } else {
110+ return null ;
111+ }
112+ return attributes ;
112113 }
113114
114- private boolean setIdAttributeExists () {
115- for (Method method : Element .class .getDeclaredMethods ()) {
116- if (method .getName ().equals ("setIdAttribute" )) {
117- return true ;
118- }
119- }
120- return false ;
121- }
122-
123- private void tagIdAttributes (Document xmlDoc ) {
124- throw new UnsupportedOperationException ("Not supported yet." ); //To change body of generated methods, choose Tools | Templates.
125- }
126-
127-
115+ private boolean setIdAttributeExists () {
116+ for (Method method : Element .class .getDeclaredMethods ()) {
117+ if (method .getName ().equals ("setIdAttribute" )) {
118+ return true ;
119+ }
120+ }
121+ return false ;
122+ }
128123
124+ private void tagIdAttributes (Document xmlDoc ) {
125+ throw new UnsupportedOperationException ("Not supported yet." ); //To change body of generated methods, choose Tools | Templates.
126+ }
129127}
128+
0 commit comments