⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 samlauthenticationstatement.java

📁 开放源代码的基于SAML的单点登录系统
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
        return subjectIP;    }    /**     *  Sets the subject's IP address     *      * @param   subjectIP   The subject's IP address     */    public void setSubjectIP(String subjectIP) {        this.subjectIP = subjectIP;        if (root != null) {            Element loc = XML.getFirstChildElement(root, XML.SAML_NS, "SubjectLocality");            if (loc != null) {                loc.removeAttributeNS(null, "IPAddress");                if (!XML.isEmpty(subjectIP))                    loc.setAttributeNS(null, "IPAddress", subjectIP);                else if (!loc.hasAttributes())                    root.removeChild(loc);            }            else if (!XML.isEmpty(subjectIP)) {                loc = root.getOwnerDocument().createElementNS(XML.SAML_NS, "SubjectLocality");                loc.setAttributeNS(null, "IPAddress", subjectIP);                root.insertBefore(loc, subject.root.getNextSibling());            }        }    }    /**     *  Gets the subject's DNS address     *     * @return    The subject's DNS address     */    public String getSubjectDNS() {        return subjectDNS;    }    /**     *  Sets the subject's DNS address     *      * @param   subjectDNS  The subject's DNS address     */    public void setSubjectDNS(String subjectDNS) {        this.subjectDNS = subjectDNS;        if (root != null) {            Element loc = XML.getFirstChildElement(root, XML.SAML_NS, "SubjectLocality");            if (loc != null) {                loc.removeAttributeNS(null, "DNSAddress");                if (!XML.isEmpty(subjectDNS))                    loc.setAttributeNS(null, "DNSAddress", subjectDNS);                else if (!loc.hasAttributes())                    root.removeChild(loc);            }            else if (!XML.isEmpty(subjectDNS)) {                loc = root.getOwnerDocument().createElementNS(XML.SAML_NS, "SubjectLocality");                loc.setAttributeNS(null, "DNSAddress", subjectDNS);                root.insertBefore(loc, subject.root.getNextSibling());            }        }    }    /**     *  Gets the authentication method     *     * @return    The authentication method URI     */    public String getAuthMethod() {        return authMethod;    }    /**     *  Sets the authentication method     *      * @param   authMethod    The authentication method URI     */    public void setAuthMethod(String authMethod) {        if (XML.isEmpty(authMethod))            throw new IllegalArgumentException("authMethod cannot be null");        this.authMethod = authMethod;        if (root != null) {            ((Element)root).getAttributeNodeNS(null,"AuthenticationMethod").setNodeValue(authMethod);        }    }    /**     *  Gets the datetime of authentication     *     * @return    The date and time of authentication     */    public Date getAuthInstant() {        return authInstant;    }    /**     *  Sets the datetime of authentication     *     * @param   authInstant    The date and time of authentication     */    public void setAuthInstant(Date authInstant) {        if (authInstant == null)            throw new IllegalArgumentException("authInstant cannot be null");        if (root != null) {            SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'");            formatter.setTimeZone(TimeZone.getTimeZone("GMT"));            ((Element)root).getAttributeNodeNS(null, "AuthenticationInstant").setNodeValue(formatter.format(authInstant));        }        this.authInstant = authInstant;    }    /**     *  Gets SAML authority binding information     *     * @return    An iterator of bindings     */    public Iterator getBindings() {        return bindings.iterator();    }    /**     *  Sets SAML authority binding information     *      * @param bindings    The bindings to include     * @throws SAMLException    Raised if any of the bindings are invalid     */    public void setBindings(Collection bindings) throws SAMLException {        while (this.bindings.size() > 0) {            removeBinding(0);        }                if (bindings != null) {            for (Iterator i = bindings.iterator(); i.hasNext(); )                addBinding((SAMLAuthorityBinding)i.next());        }    }    /**     *  Adds SAML authority binding information     *      * @param binding    The binding to add     * @exception SAMLException     Raised if the binding is invalid     */    public void addBinding(SAMLAuthorityBinding binding) throws SAMLException {        if (binding != null) {            if (root != null) {                Node b = binding.toDOM(root.getOwnerDocument());                                //This is defensive code in case somebody extends this type and adds new elements.                Element last = XML.getLastChildElement(root, XML.SAML_NS, "AuthorityBinding");                if (last == null) {                    Element loc = XML.getFirstChildElement(root, XML.SAML_NS, "SubjectLocality");                    if (loc == null) {                        // Stick it after the Subject.                        root.insertBefore(b, subject.root.getNextSibling());                    }                    else {                        // Stick it after SubjectLocality.                        root.insertBefore(b, loc.getNextSibling());                    }                }                else {                    // Stick it after the last current binding.                    root.insertBefore(b, last.getNextSibling());                }            }            bindings.add(binding);        }        else            throw new IllegalArgumentException("binding cannot be null");    }        /**     *  Removes a binding by position (zero-based)     *      * @param   index   The position of the binding to remove     */    public void removeBinding(int index) {        bindings.remove(index);        if (root != null) {            Element e = XML.getFirstChildElement(root, XML.SAML_NS, "AuthorityBinding");            while (e != null && index > 0) {                e = XML.getNextSiblingElement(e);                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.SAML_NS);			return root;        }        // This is the meat. Build a new XML instance using our state and the specified Document.        Element statement = doc.createElementNS(XML.SAML_NS, "AuthenticationStatement");		if (xmlns)			statement.setAttributeNS(XML.XMLNS_NS, "xmlns", XML.SAML_NS);        SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'");        formatter.setTimeZone(TimeZone.getTimeZone("GMT"));        statement.setAttributeNS(null, "AuthenticationInstant", formatter.format(authInstant));        statement.setAttributeNS(null, "AuthenticationMethod", authMethod);        statement.appendChild(subject.toDOM(doc, false));        if (!XML.isEmpty(subjectIP) || !XML.isEmpty(subjectDNS)) {            Element locality = doc.createElementNS(XML.SAML_NS, "SubjectLocality");            if (!XML.isEmpty(subjectIP))                locality.setAttributeNS(null,"IPAddress", subjectIP);            if (!XML.isEmpty(subjectDNS))                locality.setAttributeNS(null,"DNSAddress", subjectDNS);            statement.appendChild(locality);        }        for (Iterator i=bindings.iterator(); i.hasNext(); )            statement.appendChild(((SAMLAuthorityBinding)i.next()).toDOM(doc, false));        return root = statement;    }    /**     * @see org.opensaml.SAMLObject#checkValidity()     */    public void checkValidity() throws SAMLException {        if (XML.isEmpty(authMethod) || authInstant == null)            throw new MalformedException(SAMLException.RESPONDER, "AuthenticationStatement is invalid, requires AuthenticationMethod and AuthenticationInstant");    }    /**     *  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 {        SAMLAuthenticationStatement dup=(SAMLAuthenticationStatement)super.clone();                // Clone the embedded objects.        for (Iterator i = bindings.iterator(); i.hasNext(); )            dup.bindings.add(((SAMLAuthorityBinding)i.next()).clone());                return dup;    }}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -