📄 samlexception.java
字号:
*/ public SAMLException(Collection codes, String msg, Exception e) { this(codes,msg); this.e = e; } /** * Creates a new SAMLException * * @param code A status code */ public SAMLException(QName code) { if (code != null) codes.add(code); } /** * Creates a new SAMLException * * @param code A status code * @param msg The detail message */ public SAMLException(QName code, String msg) { this(msg); if (code != null) codes.add(code); } /** * Creates a new SAMLException wrapping an existing exception <p> * * The existing exception will be embedded in the new one, and its message * will become the default message for the SAMLException.</p> * * @param code A status code * @param e The exception to be wrapped in a SAMLException */ public SAMLException(QName code, Exception e) { this(code, (String)null); this.e = e; } /** * Creates a new SAMLException from an existing exception. <p> * * The existing exception will be embedded in the new one, but the new * exception will have its own message.</p> * * @param code A status code * @param msg The detail message * @param e The exception to be wrapped in a SAMLException */ public SAMLException(QName code, String msg, Exception e) { this(code, msg); this.e = e; } /** * Handles initialization of exceptions from a DOM element * * @param e * @exception SAMLException Raised if an exception occurs while initializing the object */ public void fromDOM(Element e) throws SAMLException { if (e==null) throw new MalformedException("SAMLException.fromDOM() given an empty DOM"); root = e; if (config.getBooleanProperty("org.opensaml.strict-dom-checking") && !XML.isElementNamed(e,XML.SAMLP_NS,"Status")) throw new MalformedException(SAMLException.RESPONDER,"SAMLException.fromDOM() requires samlp:Status at root"); // Extract the status message. Element m = XML.getFirstChildElement(e, XML.SAMLP_NS, "StatusMessage"); if (m!=null && m.getFirstChild()!=null) msg=m.getFirstChild().getNodeValue(); NodeList nlist=e.getElementsByTagNameNS(XML.SAMLP_NS,"StatusCode"); for (int i=0; nlist!=null && i<nlist.getLength(); i++) { QName qptr=QName.getQNameAttribute((Element)nlist.item(i),null,"Value"); if (qptr!=null) codes.add(qptr); else throw new MalformedException(SAMLException.RESPONDER,"SAMLException.fromDOM() unable to evaluate QName Value"); } } /** * Serializes the XML representation of a SAML Status to a stream * * @param out Stream to use for output * @exception java.io.IOException Raised if an I/O problem is detected * @exception SAMLException Raised if the object is invalid */ public void toStream(OutputStream out) throws java.io.IOException, SAMLException { try { Canonicalizer c = Canonicalizer.getInstance(Canonicalizer.ALGO_ID_C14N_EXCL_OMIT_COMMENTS); out.write(c.canonicalizeSubtree(toDOM())); } catch (InvalidCanonicalizerException e) { throw new java.io.IOException(e.getMessage()); } catch (CanonicalizationException e) { throw new java.io.IOException(e.getMessage()); } } /** * Transforms the object into a DOM tree using an existing document context * * @param doc A Document object to use in manufacturing the tree * @param xmlns Include namespace(s) on root element? * @return Root element node of the DOM tree capturing the object * @exception SAMLException Raised if the object is incompletely defined */ public Node toDOM(Document doc, boolean xmlns) throws SAMLException { if (root != null) { // If the DOM tree is already generated, compare the Documents. if (root.getOwnerDocument() != doc) { root = doc.adoptNode(root); } } else { // Construct a Status element. Element s = doc.createElementNS(XML.SAMLP_NS, "Status"); s.setAttributeNS(XML.XMLNS_NS, "xmlns:samlp", XML.SAMLP_NS); if (codes == null || codes.isEmpty()) { Element sc = doc.createElementNS(XML.SAMLP_NS, "StatusCode"); sc.setAttributeNS(null, "Value", SAMLException.RESPONDER.getLocalName()); s.appendChild(sc); } else { Node base = s; Iterator i = codes.iterator(); while(i.hasNext()) { QName qcode = (QName)i.next(); Element sc = doc.createElementNS(XML.SAMLP_NS, "StatusCode"); String codens = qcode.getNamespaceURI(); if (!codens.equals(XML.SAMLP_NS)) { sc.setAttributeNS(XML.XMLNS_NS, "xmlns:code", codens); codens = "code:"; } else codens = "samlp:"; sc.setAttributeNS(null, "Value", codens + qcode.getLocalName()); base = base.appendChild(sc); } } if (!XML.isEmpty(getMessage())) { Element msg = doc.createElementNS(XML.SAMLP_NS, "StatusMessage"); msg.appendChild(doc.createTextNode(getMessage())); s.appendChild(msg); } if (!(this instanceof SAMLException)) { Element detail=doc.createElementNS(XML.SAMLP_NS, "StatusDetail"); detail.appendChild(doc.createElementNS(XML.OPENSAML_NS, "ExceptionClass")).appendChild(doc.createTextNode(this.getClass().getName())); } root = s; } if (xmlns) ((Element)root).setAttributeNS(XML.XMLNS_NS, "xmlns", XML.SAMLP_NS); return root; } /** * Transforms the object into a DOM tree without an existing document * context * * @param xmlns Include namespace(s) on root element? * @return Root element node of the DOM tree capturing the object * @exception SAMLException Raised if the exception is invalid */ public Node toDOM(boolean xmlns) throws SAMLException { if (root != null) return root; // No existing document object, so we have to create one. return toDOM(XML.parserPool.newDocument(), xmlns); } /** * Transforms the object into a DOM tree using an existing document context, * including namespace declarations * * @param doc A Document object to use in manufacturing the tree * @return Root element node of the DOM tree capturing the object * @exception SAMLException Raised if the exception is invalid */ public Node toDOM(Document doc) throws SAMLException { return toDOM(doc, true); } /** * Transforms the object into a DOM tree without an existing document context, * including namespace declarations * * @return Root element node of the DOM tree capturing the object * @exception SAMLException Raised if the exception is invalid */ public Node toDOM() throws SAMLException { return toDOM(true); } /** * Gets the status or fault code QNames * * @return An iterator of QNames */ public Iterator getCodes() { return codes.iterator(); } /** * Returns a detail message for this exception <p> * * If there is an embedded exception, and if the SAMLException has no * detail message of its own, this method will return the detail message * from the embedded exception.</p> * * @return The error message */ public String getMessage() { if (msg != null && e != null) return msg + " (wrapped: " + e.getMessage() + ')'; else if (e != null) return "(wrapped: " + e.getMessage() + ")"; else return msg; } /** * Returns the embedded exception, if any * * @return The embedded exception, or null if there is none */ public Exception getException() { return e; } /** * Overrides toString to pick up any embedded exception<p> * * One quirk is that this method does not produce a serialized XML * representation of the object. toString is oriented around the usual * expectations of Exception clients, while toStream implements the behavior * expected by SAMLObject clients. * * @return A string (but not XML) representation of this exception */ public String toString() { return (e != null) ? e.toString() : super.toString(); } /** * 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 { SAMLException dup=(SAMLException)super.clone(); dup.root = null; dup.codes = (ArrayList)codes.clone(); return dup; }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -