Author: prabath
Date: Mon Jan 21 01:50:41 2008
New Revision: 12581

Log:

OpenID integration

Added:
   
trunk/solutions/identity/modules/identity-provider/src/main/java/org/wso2/solutions/identity/openid/OpenIDProviderData.java

Added: 
trunk/solutions/identity/modules/identity-provider/src/main/java/org/wso2/solutions/identity/openid/OpenIDProviderData.java
==============================================================================
--- (empty file)
+++ 
trunk/solutions/identity/modules/identity-provider/src/main/java/org/wso2/solutions/identity/openid/OpenIDProviderData.java
 Mon Jan 21 01:50:41 2008
@@ -0,0 +1,204 @@
+package org.wso2.solutions.identity.openid;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+
+import org.openid4java.message.MessageException;
+import org.openid4java.message.ax.FetchResponse;
+import org.openid4java.message.sreg.SRegResponse;
+import org.wso2.solutions.identity.IdentityConstants;
+import org.wso2.solutions.identity.IdentityProviderException;
+import org.wso2.solutions.identity.UserStore;
+import org.wso2.solutions.identity.persistence.IPPersistenceManager;
+import org.wso2.solutions.identity.persistence.dataobject.ClaimDO;
+
+public class OpenIDProviderData {
+
+    /**
+     * 
+     * @param requiredClaims
+     * @param userId
+     * @return
+     * @throws IdentityProviderException
+     */
+    protected Map populateAttributeValues(List requiredClaims, String userId)
+            throws IdentityProviderException {
+
+        Map claims = null;
+        IPPersistenceManager persistenceManager = null;
+        ClaimDO[] supportedClaims = null;
+
+        claims = new HashMap();
+        persistenceManager = IPPersistenceManager.getPersistanceManager();
+        supportedClaims = persistenceManager.getAllSupportedClaims();
+
+        for (int i = 0; i < supportedClaims.length; i++) {
+            ClaimDO temp = supportedClaims[i];
+            if (temp.getOpenIDTag() != null)
+                claims.put(temp.getOpenIDTag(), temp);
+        }
+
+        return populateAttributeValues(requiredClaims, userId, claims);
+    }
+
+    /**
+     * 
+     * @param requiredClaims
+     * @param userId
+     * @return
+     * @throws IdentityProviderException
+     */
+    protected Map populateAttributeValues(Map requiredClaims, String userId)
+            throws IdentityProviderException {
+
+        Map claims = null;
+        IPPersistenceManager persistenceManager = null;
+        ClaimDO[] supportedClaims = null;
+
+        claims = new HashMap();
+        persistenceManager = IPPersistenceManager.getPersistanceManager();
+        supportedClaims = persistenceManager.getAllSupportedClaims();
+
+        for (int i = 0; i < supportedClaims.length; i++) {
+            ClaimDO temp = supportedClaims[i];
+            if (temp.getOpenIDTag() != null)
+                claims.put(temp.getUri(), temp);
+        }
+
+        return populateAttributeValues(requiredClaims.keySet(), userId, 
claims);
+    }
+
+    /**
+     * 
+     * @param requiredClaims
+     * @param userId
+     * @param claims
+     * @return
+     * @throws IdentityProviderException
+     */
+    protected Map populateAttributeValues(Collection requiredClaims,
+            String userId, Map claims) throws IdentityProviderException {
+
+        UserStore connector = null;
+        Map claimValues = null;
+        Iterator iterator = null;
+        List list = null;
+
+        connector = UserStore.getInstance();
+
+        // get the column names for the URIs
+        iterator = requiredClaims.iterator();
+        list = new ArrayList();
+
+        String tag = null;
+        ClaimDO claim = null;
+
+        while (iterator.hasNext()) {
+            tag = (String) iterator.next();
+            claim = (ClaimDO) claims.get(tag);
+            if (claim != null
+                    && !claim.getUri().equals(IdentityConstants.CLAIM_PPID)) {
+                if (claim.isSupported())
+                    list.add(claim.getAttrId());
+            }
+        }
+
+        Map mapValues = null;
+        OpenIDClaim openIDClaim = null;
+
+        mapValues = connector.getClaimValues(userId, list);
+        claimValues = new HashMap();
+
+        iterator = requiredClaims.iterator();
+
+        while (iterator.hasNext()) {
+            tag = (String) iterator.next();
+            claim = (ClaimDO) claims.get(tag);
+
+            if (claim != null && claim.isSupported()) {
+                openIDClaim = new OpenIDClaim();
+                openIDClaim.claimValue = (String) mapValues.get(claim
+                        .getAttrId());
+                openIDClaim.typeUri = claim.getUri();
+                openIDClaim.openIDTag = tag;
+                if (openIDClaim.claimValue != null)
+                    claimValues.put(openIDClaim.typeUri, openIDClaim);
+            }
+        }
+
+        return claimValues;
+    }
+
+    /**
+     * 
+     * @param response
+     * @param required
+     * @param claimValues
+     * @throws MessageException
+     */
+    protected void setSimpleAttributeRegistrationValues(SRegResponse response,
+            Map claimValues) throws MessageException {
+
+        // If we can't find the required values with us, we simply avoid 
sending
+        // them. An Identity Provider MAY return any subset of the following
+        // fields in response to the query.
+
+        Iterator iterator = null;
+        String key = null;
+        OpenIDClaim claim = null;
+
+        iterator = claimValues.keySet().iterator();
+
+        while (iterator.hasNext()) {
+            key = (String) iterator.next();
+            claim = (OpenIDClaim) claimValues.get(key);
+            response.addAttribute(claim.openIDTag, claim.claimValue);
+        }
+
+    }
+
+    /**
+     * 
+     * @param response
+     * @param required
+     * @param claimValues
+     * @throws MessageException
+     */
+    protected void setAttributeExchangeValues(FetchResponse response,
+            Map claimValues) throws MessageException {
+
+        // If we can't find the required values with us, we simply avoid 
sending
+        // them. An Identity Provider MAY return any subset of the following
+        // fields in response to the query.
+
+        Iterator iterator = null;
+        String key = null;
+        OpenIDClaim claim = null;
+
+        iterator = claimValues.keySet().iterator();
+
+        while (iterator.hasNext()) {
+            key = (String) iterator.next();
+            claim = (OpenIDClaim) claimValues.get(key);
+            response.addAttribute(claim.typeUri, claim.claimValue);
+        }
+    }
+
+    /**
+     * 
+     *
+     */
+    public class OpenIDClaim {
+
+        public String typeUri;
+
+        public String openIDTag;
+
+        public String claimValue;
+
+    }
+}

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

Reply via email to