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

📄 saml1tokenholder.java

📁 开源的OpenId的一个java实现
💻 JAVA
字号:
package org.wso2.solutions.identity.relyingparty.saml.tokens;import java.util.Iterator;import java.util.List;import java.util.Map;import org.apache.commons.logging.Log;import org.apache.commons.logging.LogFactory;import org.opensaml.saml1.core.Assertion;import org.opensaml.saml1.core.Attribute;import org.opensaml.saml1.core.AttributeStatement;import org.opensaml.xml.Configuration;import org.opensaml.xml.io.Unmarshaller;import org.opensaml.xml.io.UnmarshallerFactory;import org.opensaml.xml.io.UnmarshallingException;import org.opensaml.xml.schema.XSAny;import org.opensaml.xml.schema.XSString;import org.opensaml.xml.signature.Signature;import org.w3c.dom.Element;public class SAML1TokenHolder implements TokenHolder {    private Assertion assertion = null;    private boolean isMultipleValues = false;    private static Log log = LogFactory.getLog(SAML1TokenHolder.class);    /**     * Creates the SAML object from the element This method must be called first     *      * @param elem     * @throws UnmarshallingException     *             If the token creation fails     */    public void createToken(Element elem) throws UnmarshallingException {        UnmarshallerFactory unmarshallerFactory = Configuration                .getUnmarshallerFactory();        Unmarshaller unmarshaller = unmarshallerFactory.getUnmarshaller(elem);        assertion = (Assertion) unmarshaller.unmarshall(elem);    }    /**     * @return the SAML signature.     */    public Signature getSAMLSignature() {        return assertion.getSignature();    }    /**     * Issuer of the SAML token     *      * @return     */    public String getIssuerName() {        return assertion.getIssuer();    }    /**     * Populates the attributes.     *      * @param attributeTable     */    public void populateAttributeTable(Map attributeTable) {        Iterator statements = assertion.getAttributeStatements().iterator();        while (statements.hasNext()) {            AttributeStatement stmt = (AttributeStatement) statements.next();            Iterator attrs = stmt.getAttributes().iterator();            while (attrs.hasNext()) {                Attribute attr = (Attribute) attrs.next();                String name = attr.getAttributeNamespace() + "/"                        + attr.getAttributeName();                List lst = attr.getAttributeValues();                Iterator ite = lst.iterator();                int count = 0;                StringBuffer buff = new StringBuffer();                while (ite.hasNext()) {                    Object obj = ite.next();                    if (obj instanceof XSString) {                        buff.append(((XSString) obj).getValue());                    } else if (obj instanceof XSAny) {                        XSAny any = (XSAny) obj;                        String value = any.getTextContent();                        buff.append(value);                    }                    buff.append(",");                    count++;                }                if (buff.length() > 1) {                    buff.deleteCharAt(buff.length() - 1);                }                String value = buff.toString();                if (count > 1) {                    isMultipleValues = true;                }                attributeTable.put(name, value);            }        }    }}

⌨️ 快捷键说明

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