📄 samlauthorizationdecisionstatement.java
字号:
* * @param actions The actions to include * @exception SAMLException Raised if the actions are invalid */ public void setActions(Collection actions) throws SAMLException { while (this.actions.size() > 0) removeAction(0); if (actions != null) { for (Iterator i = actions.iterator(); i.hasNext(); ) addAction((SAMLAction)i.next()); } } /** * Adds an action to the statement * @param action The action to add * @exception SAMLException Raised if the action if invalid */ public void addAction(SAMLAction action) throws SAMLException { if (action != null) { if (root != null) { Element last = XML.getLastChildElement(root, XML.SAML_NS, "Action"); if (last == null) root.insertBefore(action.toDOM(root.getOwnerDocument()), subject.root.getNextSibling()); else root.insertBefore(action.toDOM(root.getOwnerDocument()), last.getNextSibling()); } actions.add(action); } else throw new IllegalArgumentException("action cannot be null"); } /** * Removes an action by position (zero-based) * * @param index The position of the action to remove */ public void removeAction(int index) { actions.remove(index); if (root != null) { Element e = XML.getFirstChildElement(root, XML.SAML_NS, "Action"); while (e != null && index > 0) { e = XML.getNextSiblingElement(e); index--; } if (e != null) root.removeChild(e); else throw new IndexOutOfBoundsException(); } if (actions.size() == 0) { NDC.push("removeAction"); log.warn("all actions have been removed, statement is in an illegal state"); NDC.pop(); } } /** * Gets the evidence inside the statement * * @return An iterator over the evidence */ public Iterator getEvidence() { return evidence.iterator(); } /** * Sets the evidence to include in the statement * * @param evidence The evidence to include * @exception SAMLException Raised if the evidence is invalid */ public void setEvidence(Collection evidence) throws SAMLException { while (this.evidence.size() > 0) removeEvidence(0); if (evidence != null) { for (Iterator i = evidence.iterator(); i.hasNext(); ) addEvidence(i.next()); } } /** * Adds an evidence element * * @param evidence a String or SAMLAssertion * @exception SAMLException Raised if an invalid kind of object is provided */ public void addEvidence(Object evidence) throws SAMLException { if (evidence != null && (evidence instanceof String || evidence instanceof SAMLAssertion)) { if (root != null) { Document doc = root.getOwnerDocument(); Element wrapper = XML.getFirstChildElement(root, XML.SAML_NS, "Evidence"); if (wrapper == null) { wrapper = doc.createElementNS(XML.SAML_NS, "Evidence"); if (actions.size() == 0) { root.insertBefore(wrapper, subject.root.getNextSibling()); } else { root.insertBefore(wrapper, ((SAMLAction)actions.get(actions.size()-1)).root.getNextSibling()); } } if (evidence instanceof String && !XML.isEmpty((String)evidence)) { Element ref = doc.createElementNS(XML.SAML_NS, "AssertionIDReference"); ref.appendChild(doc.createTextNode((String)evidence)); wrapper.appendChild(ref); } else if (evidence instanceof SAMLAssertion) { wrapper.appendChild(((SAMLAssertion)evidence).toDOM(doc)); } } this.evidence.add(evidence); } else throw new IllegalArgumentException("can only add Strings or SAMLAssertions"); } /** * Removes an evidence element by position (zero-based) * * @param index The position of the element to remove */ public void removeEvidence(int index) throws IndexOutOfBoundsException { evidence.remove(index); if (root != null) { Element wrapper = XML.getFirstChildElement(root, XML.SAML_NS, "Evidence"); Element e = XML.getFirstChildElement(wrapper); while (e != null && index > 0) { e = XML.getNextSiblingElement(e); index--; } if (e != null) wrapper.removeChild(e); else throw new IndexOutOfBoundsException(); if (evidence.size() == 0) root.removeChild(wrapper); } } /** * @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.SAML_NS); return root; } Element s = doc.createElementNS(XML.SAML_NS, "AuthorizationDecisionStatement"); if (xmlns) s.setAttributeNS(XML.XMLNS_NS, "xmlns", XML.SAML_NS); s.setAttributeNS(null, "Resource", resource); s.setAttributeNS(null, "Decision", decision); s.appendChild(subject.toDOM(doc, false)); Iterator i = actions.iterator(); while (i.hasNext()) s.appendChild(((SAMLAction)i.next()).toDOM(doc, false)); if (evidence.size()>0) { Element ev = doc.createElementNS(XML.SAML_NS, "Evidence"); i = evidence.iterator(); while (i.hasNext()) { Object o = i.next(); if (o instanceof SAMLAssertion) ev.appendChild(((SAMLAssertion)o).toDOM(doc, false)); else if (o instanceof String && !XML.isEmpty((String)o)) ev.appendChild(doc.createElementNS(XML.SAML_NS,"AssertionIDReference")).appendChild(doc.createTextNode((String)o)); } s.appendChild(ev); } return root = s; } /** * @see org.opensaml.SAMLObject#checkValidity() */ public void checkValidity() throws SAMLException { super.checkValidity(); if (XML.isEmpty(resource) || XML.isEmpty(decision) || actions.size() == 0) throw new MalformedException("AuthorizationDecisionStatement is invalid, must have Resource, Decision, and at least one Action"); } /** * 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 { SAMLAuthorizationDecisionStatement dup=(SAMLAuthorizationDecisionStatement)super.clone(); // Clone the embedded objects. for (Iterator i=actions.iterator(); i.hasNext(); ) dup.actions.add(((SAMLAction)i.next()).clone()); for (Iterator i=evidence.iterator(); i.hasNext(); ) { Object o = i.next(); if (o instanceof SAMLAssertion) dup.evidence.add(((SAMLAssertion)o).clone()); else if (o instanceof String) dup.evidence.add(o); } return dup; }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -