📄 samlresponse.java
字号:
* @return The InResponseTo value */ public String getInResponseTo() { return inResponseTo; } /** * Sets the InResponseTo attribute * * @param inResponseTo The InResponseTo value */ public void setInResponseTo(String inResponseTo) { this.inResponseTo = inResponseTo; if (root != null) { ((Element)root).removeAttributeNS(null, "InResponseTo"); if (!XML.isEmpty(inResponseTo)) ((Element)root).setAttributeNS(null, "InResponseTo", inResponseTo); } } /** * Gets the issue timestamp of the SAML response * * @return The issue timestamp */ public Date getIssueInstant() { return issueInstant; } /** * Sets the issue timestamp of the response * * @param issueInstant The issue timestamp */ public void setIssueInstant(Date issueInstant) { if (issueInstant == null) throw new IllegalArgumentException("issueInstant cannot be null"); if (root != null) { unsign(); SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'"); formatter.setTimeZone(TimeZone.getTimeZone("GMT")); ((Element)root).getAttributeNodeNS(null, "IssueInstant").setNodeValue(formatter.format(issueInstant)); } this.issueInstant = issueInstant; } /** * Gets the Recipient attribute of the SAML response * * @return The Recipient value */ public String getRecipient() { return recipient; } /** * Sets the Recipient attribute * * @param recipient The Recipient value */ public void setRecipient(String recipient) { this.recipient = recipient; if (root != null) { ((Element)root).removeAttributeNS(null, "Recipient"); if (!XML.isEmpty(recipient)) ((Element)root).setAttributeNS(null, "Recipient", recipient); } } /** * Gets the SAML assertions contained in the response, if any * * @return The assertions in the response */ public Iterator getAssertions() { return assertions.iterator(); } /** * Sets the SAML assertions to include in the response * * @param assertions The assertions to include * @exception SAMLException Raised if the assertions are invalid */ public void setAssertions(Collection assertions) throws SAMLException { while (this.assertions.size() > 0) removeAssertion(0); if (assertions != null) { for (Iterator i = assertions.iterator(); i.hasNext(); ) addAssertion((SAMLAssertion)i.next()); } } /** * Adds an assertion to the response * * @param assertion The assertion to add * @exception SAMLException Raised if the assertion is invalid */ public void addAssertion(SAMLAssertion assertion) throws SAMLException { if (assertion != null) { if (root != null) { unsign(); Element last = XML.getLastChildElement(root, XML.SAML_NS, "Assertion"); if (last == null) root.insertBefore( assertion.toDOM(root.getOwnerDocument()), XML.getFirstChildElement(root, XML.SAMLP_NS, "Status").getNextSibling() ); else root.insertBefore(assertion.toDOM(root.getOwnerDocument()), last.getNextSibling()); } assertions.add(assertion); } else throw new IllegalArgumentException("assertion cannot be null"); } /** * Removes assertion by position (zero-based) * * @param index The position of the assertion to remove */ public void removeAssertion(int index) throws IndexOutOfBoundsException { assertions.remove(index); if (root != null) { unsign(); Element e = XML.getFirstChildElement(root, XML.SAML_NS, "Assertion"); while (e != null && index > 0) { e = XML.getNextSiblingElement(e, XML.SAML_NS, "Assertion"); index--; } if (e != null) root.removeChild(e); else throw new IndexOutOfBoundsException(); } } /** * @see org.opensaml.SAMLObject#toDOM(org.w3c.dom.Document,boolean) */ public Node toDOM(Document doc, boolean xmlns) throws SAMLException { if ((root = super.toDOM(doc, xmlns)) != null) { if (xmlns) { ((Element)root).setAttributeNS(XML.XMLNS_NS, "xmlns", XML.SAMLP_NS); ((Element)root).setAttributeNS(XML.XMLNS_NS, "xmlns:saml", XML.SAML_NS); ((Element)root).setAttributeNS(XML.XMLNS_NS, "xmlns:samlp", XML.SAMLP_NS); ((Element)root).setAttributeNS(XML.XMLNS_NS, "xmlns:xsi", XML.XSI_NS); ((Element)root).setAttributeNS(XML.XMLNS_NS, "xmlns:xsd", XML.XSD_NS); } return root; } SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'"); formatter.setTimeZone(TimeZone.getTimeZone("GMT")); // Generate a SAML Response. Element r = doc.createElementNS(XML.SAMLP_NS, "Response"); if (xmlns) r.setAttributeNS(XML.XMLNS_NS, "xmlns", XML.SAMLP_NS); r.setAttributeNS(XML.XMLNS_NS, "xmlns:saml", XML.SAML_NS); r.setAttributeNS(XML.XMLNS_NS, "xmlns:samlp", XML.SAMLP_NS); r.setAttributeNS(null, "MajorVersion", "1"); r.setAttributeNS(null, "MinorVersion", config.getBooleanProperty("org.opensaml.compatibility-mode") ? "0" : "1"); r.setAttributeNS(null, "ResponseID", responseId); r.setIdAttributeNS(null, "ResponseID", true); if (!XML.isEmpty(inResponseTo)) r.setAttributeNS(null, "InResponseTo", inResponseTo); r.setAttributeNS(null, "IssueInstant", formatter.format(issueInstant)); if (!XML.isEmpty(recipient)) r.setAttributeNS(null, "Recipient", recipient); // Fill in a status. if (e!=null) r.appendChild(e.toDOM(doc, false)); else { Element status = doc.createElementNS(XML.SAMLP_NS, "Status"); Element code = doc.createElementNS(XML.SAMLP_NS, "StatusCode"); code.setAttributeNS(null, "Value", "samlp:" + SAMLException.SUCCESS.getLocalName()); status.appendChild(code); r.appendChild(status); } // Embed the assertions. Iterator i = assertions.iterator(); while (i.hasNext()) r.appendChild(((SAMLAssertion)i.next()).toDOM(doc)); return root = r; } /** * Copies a SAML object such that no dependencies exist between the original * and the copy * * @return The new object * @see java.lang.Object#clone() */ public Object clone() throws CloneNotSupportedException { SAMLResponse dup=(SAMLResponse)super.clone(); // Clone the embedded objects. if (e != null) dup.e = (SAMLException)e.clone(); for (Iterator i = assertions.iterator(); i.hasNext(); ) dup.assertions.add(((SAMLAssertion)i.next()).clone()); return dup; }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -