Author: dimuthul
Date: Thu Feb  7 01:27:35 2008
New Revision: 13391

Log:

Adding the token validator SAML 2.0


Added:
   
trunk/solutions/identity/modules/token-verifier-core/src/main/java/org/wso2/solutions/identity/saml/relyingparty/tokens/SAML2TokenHolder.java

Added: 
trunk/solutions/identity/modules/token-verifier-core/src/main/java/org/wso2/solutions/identity/saml/relyingparty/tokens/SAML2TokenHolder.java
==============================================================================
--- (empty file)
+++ 
trunk/solutions/identity/modules/token-verifier-core/src/main/java/org/wso2/solutions/identity/saml/relyingparty/tokens/SAML2TokenHolder.java
       Thu Feb  7 01:27:35 2008
@@ -0,0 +1,106 @@
+package org.wso2.solutions.identity.saml.relyingparty.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.saml2.core.Assertion;
+import org.opensaml.saml2.core.Attribute;
+import org.opensaml.saml2.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 SAML2TokenHolder 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().getValue();
+    }
+
+    /**
+     * 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 attrNamesapce = attr.getNameFormat();
+                String attrName = attr.getName();
+                String name = attrNamesapce + "/" + attrName;
+
+                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);
+            }
+        }
+
+    }
+
+}

_______________________________________________
Identity-dev mailing list
[email protected]
http://wso2.org/cgi-bin/mailman/listinfo/identity-dev

Reply via email to