Author: prabath
Date: Mon Mar 10 23:57:15 2008
New Revision: 14677

Log:

added attribute mapping

Modified:
   
trunk/solutions/identity/modules/base/src/main/java/org/wso2/solutions/identity/IdentityConstants.java
   
trunk/solutions/identity/modules/identity-provider/src/main/java/org/wso2/solutions/identity/cards/CardIssuer.java
   
trunk/solutions/identity/modules/identity-provider/src/main/java/org/wso2/solutions/identity/openid/OpenIDUtil.java
   
trunk/solutions/identity/modules/identity-provider/src/main/java/org/wso2/solutions/identity/openid/infocard/OpenIDInfoCardProviderData.java
   
trunk/solutions/identity/modules/identity-provider/src/main/java/org/wso2/solutions/identity/sts/OpenIDTokenIssuer.java
   
trunk/solutions/identity/modules/token-verifier-core/src/main/java/org/wso2/solutions/identity/relyingparty/openid/extensions/OpenIDAttributeExchange.java

Modified: 
trunk/solutions/identity/modules/base/src/main/java/org/wso2/solutions/identity/IdentityConstants.java
==============================================================================
--- 
trunk/solutions/identity/modules/base/src/main/java/org/wso2/solutions/identity/IdentityConstants.java
      (original)
+++ 
trunk/solutions/identity/modules/base/src/main/java/org/wso2/solutions/identity/IdentityConstants.java
      Mon Mar 10 23:57:15 2008
@@ -186,6 +186,12 @@
                        public final static String LANGUAGE = "language";
                        public final static String TIMEZONE = "timezone";
 
+                       public final static String FULL_NAME_NS = 
"http://schema.openid.net/2007/05/claims/fullname";;
+                       public final static String DOB_NS = 
"http://schema.openid.net/2007/05/claims/dob";;
+                       public final static String GENDER_NS = 
"http://schema.openid.net/2007/05/claims/gender";;
+                       public final static String LANGUAGE_NS = 
"http://schema.openid.net/2007/05/claims/language";;
+                       public final static String TIMEZONE_NS = 
"http://schema.openid.net/2007/05/claims/timezone";;
+
                }
 
                public static class ExchangeAttributes extends 
SimpleRegAttributes {

Modified: 
trunk/solutions/identity/modules/identity-provider/src/main/java/org/wso2/solutions/identity/cards/CardIssuer.java
==============================================================================
--- 
trunk/solutions/identity/modules/identity-provider/src/main/java/org/wso2/solutions/identity/cards/CardIssuer.java
  (original)
+++ 
trunk/solutions/identity/modules/identity-provider/src/main/java/org/wso2/solutions/identity/cards/CardIssuer.java
  Mon Mar 10 23:57:15 2008
@@ -1,17 +1,12 @@
 /*
- * Copyright 2005-2007 WSO2, Inc. (http://wso2.com)
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
+ * Copyright 2005-2007 WSO2, Inc. (http://wso2.com) Licensed under the Apache
+ * License, Version 2.0 (the "License"); you may not use this file except in
+ * compliance with the License. You may obtain a copy of the License at
+ * http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law
+ * or agreed to in writing, software distributed under the License is
+ * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the specific language
+ * governing permissions and limitations under the License.
  */
 
 package org.wso2.solutions.identity.cards;
@@ -42,6 +37,7 @@
 import org.wso2.solutions.identity.cards.model.UserCredential;
 import org.wso2.solutions.identity.cards.model.UsernamePasswordCredential;
 import org.wso2.solutions.identity.i18n.Messages;
+import org.wso2.solutions.identity.openid.OpenIDUtil;
 import org.wso2.solutions.identity.persistence.IPPersistenceManager;
 import org.wso2.solutions.identity.persistence.dataobject.ActionDO;
 import org.wso2.solutions.identity.persistence.dataobject.ClaimDO;
@@ -108,7 +104,7 @@
             cardIssuerLog.debug(messages.getMessage("startCardIssue",
                     new String[] { "selfIssuedCard", ppid }));
         }
-        
+
         Element cardElement = null;
         SelfIssuedCredential selfCred = new SelfIssuedCredential(ppid);
         RegisteredInfoCardInfoAdmin registerAdmin = new 
RegisteredInfoCardInfoAdmin();
@@ -153,29 +149,30 @@
 
             Identity id = new Identity();
             id.setCertificate((X509Certificate) store.getCertificate(alias));
-            
+
             InformationCard infoCard = getInfoCard(credential, id,
                     requireAppliesTo);
-            
+
             if (isCardLogDebug) {
                 cardIssuerLog.debug(messages.getMessage("cardElementGenerated",
-                        new String[] 
{infoCard.getInformationCardReference().getCardId()}));
+                        new String[] { infoCard.getInformationCardReference()
+                                .getCardId() }));
             }
-            
+
             storeCard(infoCard, primaryUserId);
             Element elem = gen.signCard(infoCard);
 
             if (isCardLogDebug) {
-                
cardIssuerLog.debug(messages.getMessage("cardSignedSuccessfully",
-                        new String[] 
{infoCard.getInformationCardReference().getCardId()}));
+                cardIssuerLog.debug(messages.getMessage(
+                        "cardSignedSuccessfully", new String[] { infoCard
+                                .getInformationCardReference().getCardId() }));
             }
-            
+
             String cardId = infoCard.getInformationCardReference().getCardId();
 
             ReportAdmin.record(primaryUserId,
                     ActionDO.ACTION_USER_DOWNLOAD_CARD, "CardId=" + cardId);
 
-            
             return elem;
         } catch (CardModelException e) {
             throw new IdentityProviderException("cardModelError", e);
@@ -299,7 +296,8 @@
                         || supportedClaims[i].getUri().equals(
                                 IdentityConstants.CLAIM_OPENID)) {
                     SupportedClaimType claim = new SupportedClaimType(
-                            supportedClaims[i].getUri());
+                            OpenIDUtil.getMappedAxSchema(supportedClaims[i]
+                                    .getUri()));
                     claim.setDisplayTag(supportedClaims[i].getDisplayTag());
                     claim.setDescription(supportedClaims[i].getDescription());
                     claimTypeList.addSupportedClaimType(claim);

Modified: 
trunk/solutions/identity/modules/identity-provider/src/main/java/org/wso2/solutions/identity/openid/OpenIDUtil.java
==============================================================================
--- 
trunk/solutions/identity/modules/identity-provider/src/main/java/org/wso2/solutions/identity/openid/OpenIDUtil.java
 (original)
+++ 
trunk/solutions/identity/modules/identity-provider/src/main/java/org/wso2/solutions/identity/openid/OpenIDUtil.java
 Mon Mar 10 23:57:15 2008
@@ -6,6 +6,7 @@
 import java.net.URISyntaxException;
 import java.net.URL;
 import java.net.URLDecoder;
+import java.util.HashMap;
 import java.util.HashSet;
 import java.util.Iterator;
 import java.util.List;
@@ -26,6 +27,8 @@
 
     private static final Set<Character> UNRESERVED_CHARACTERS = new 
HashSet<Character>();
 
+    private static Map<String, String> axMapping = new HashMap<String, 
String>();
+
     static {
         for (char c = 'a'; c <= 'z'; c++)
             UNRESERVED_CHARACTERS.add(Character.valueOf(c));
@@ -40,6 +43,25 @@
         UNRESERVED_CHARACTERS.add(Character.valueOf('.'));
         UNRESERVED_CHARACTERS.add(Character.valueOf('_'));
         UNRESERVED_CHARACTERS.add(Character.valueOf('~'));
+
+        axMapping.put(IdentityConstants.CLAIM_EMAIL_ADDRESS,
+                IdentityConstants.OpenId.ExchangeAttributes.EMAIL_NS);
+        axMapping.put(IdentityConstants.CLAIM_POSTAL_CODE,
+                IdentityConstants.OpenId.ExchangeAttributes.POSTAL_CODE_NS);
+        axMapping.put(IdentityConstants.CLAIM_NICKNAME,
+                IdentityConstants.OpenId.ExchangeAttributes.NICK_NAME_NS);
+        axMapping.put(IdentityConstants.CLAIM_COUNTRY,
+                IdentityConstants.OpenId.ExchangeAttributes.COUNTRY_NS);
+        axMapping.put(IdentityConstants.OpenId.SimpleRegAttributes.FULL_NAME,
+                IdentityConstants.OpenId.ExchangeAttributes.FULL_NAME_NS);
+        axMapping.put(IdentityConstants.OpenId.SimpleRegAttributes.DOB_NS,
+                IdentityConstants.OpenId.ExchangeAttributes.DOB_NS);
+        axMapping.put(IdentityConstants.OpenId.SimpleRegAttributes.TIMEZONE_NS,
+                IdentityConstants.OpenId.ExchangeAttributes.TIMEZONE_NS);
+        axMapping.put(IdentityConstants.OpenId.SimpleRegAttributes.GENDER_NS,
+                IdentityConstants.OpenId.ExchangeAttributes.GENDER_NS);
+        axMapping.put(IdentityConstants.OpenId.SimpleRegAttributes.LANGUAGE_NS,
+                IdentityConstants.OpenId.ExchangeAttributes.LANGUAGE_NS);
     }
 
     /**
@@ -224,4 +246,18 @@
                     IdentityConstants.ErrorCodes.INVALID_OPENID_RETURNTO);
         }
     }
+    
+    /**
+     * This provides a mapping between http://schema.openid.net/ and
+     * http://axschema.org
+     * @param val schema name-space URL
+     * @return mapped value
+     */
+    public static String getMappedAxSchema(String val) {
+        if (axMapping.containsKey(val)) {
+            return axMapping.get(val);
+        }
+
+        return val;
+    }
 }
\ No newline at end of file

Modified: 
trunk/solutions/identity/modules/identity-provider/src/main/java/org/wso2/solutions/identity/openid/infocard/OpenIDInfoCardProviderData.java
==============================================================================
--- 
trunk/solutions/identity/modules/identity-provider/src/main/java/org/wso2/solutions/identity/openid/infocard/OpenIDInfoCardProviderData.java
        (original)
+++ 
trunk/solutions/identity/modules/identity-provider/src/main/java/org/wso2/solutions/identity/openid/infocard/OpenIDInfoCardProviderData.java
        Mon Mar 10 23:57:15 2008
@@ -1,6 +1,7 @@
 package org.wso2.solutions.identity.openid.infocard;
 
 import java.util.ArrayList;
+import java.util.HashMap;
 import java.util.Iterator;
 import java.util.List;
 import java.util.Map;
@@ -14,6 +15,45 @@
 
 public class OpenIDInfoCardProviderData extends IdentityProviderData {
 
+    private static Map<String, String> axMapping = new HashMap<String, 
String>();
+
+    static {
+        axMapping.put(IdentityConstants.OpenId.ExchangeAttributes.EMAIL_NS,
+                IdentityConstants.CLAIM_EMAIL_ADDRESS);
+        axMapping.put(
+                IdentityConstants.OpenId.ExchangeAttributes.POSTAL_CODE_NS,
+                IdentityConstants.CLAIM_POSTAL_CODE);
+        axMapping.put(IdentityConstants.OpenId.ExchangeAttributes.NICK_NAME_NS,
+                IdentityConstants.CLAIM_NICKNAME);
+        axMapping.put(IdentityConstants.OpenId.ExchangeAttributes.COUNTRY_NS,
+                IdentityConstants.CLAIM_COUNTRY);
+        axMapping.put(IdentityConstants.OpenId.ExchangeAttributes.FULL_NAME_NS,
+                IdentityConstants.OpenId.SimpleRegAttributes.FULL_NAME);
+        axMapping.put(IdentityConstants.OpenId.ExchangeAttributes.DOB_NS,
+                IdentityConstants.OpenId.SimpleRegAttributes.DOB_NS);
+        axMapping.put(IdentityConstants.OpenId.ExchangeAttributes.TIMEZONE_NS,
+                IdentityConstants.OpenId.SimpleRegAttributes.TIMEZONE_NS);
+        axMapping.put(IdentityConstants.OpenId.ExchangeAttributes.GENDER_NS,
+                IdentityConstants.OpenId.SimpleRegAttributes.GENDER_NS);
+        axMapping.put(IdentityConstants.OpenId.ExchangeAttributes.LANGUAGE_NS,
+                IdentityConstants.OpenId.SimpleRegAttributes.LANGUAGE_NS);
+
+    }
+
+    /**
+     * This provides a mapping between http://schema.openid.net/ and
+     * http://axschema.org
+     * @param val schema name-space URL
+     * @return mapped value
+     */
+    protected String getMappedAxSchema(String val) {
+        if (axMapping.containsKey(val)) {
+            return axMapping.get(val);
+        }
+
+        return val;
+    }
+
     /**
      * Populate CardSpace specific meta-data.
      * @param data WS-Trust information in the issue request.
@@ -53,7 +93,8 @@
         // the user store.
         while (iterator.hasNext()) {
             requestedClaimData = (OpenIDRequestedClaimData) iterator.next();
-            claim = (ClaimDO) claimObjs.get(requestedClaimData.uri);
+            claim = (ClaimDO) claimObjs
+                    .get(getMappedAxSchema(requestedClaimData.uri));
             if (claim != null
                     && !claim.getUri().equals(IdentityConstants.CLAIM_PPID)) {
                 list.add(claim.getAttrId());
@@ -71,7 +112,8 @@
         // be populated with the corresponding values.
         while (iterator.hasNext()) {
             requestedClaimData = (OpenIDRequestedClaimData) iterator.next();
-            claimDO = ((ClaimDO) this.claimObjs.get(requestedClaimData.uri));
+            claimDO = ((ClaimDO) this.claimObjs
+                    .get(getMappedAxSchema(requestedClaimData.uri)));
             attrId = claimDO.getAttrId();
             claimVal = (String) mapValues.get(attrId);
             requestedClaimData.value = claimVal;

Modified: 
trunk/solutions/identity/modules/identity-provider/src/main/java/org/wso2/solutions/identity/sts/OpenIDTokenIssuer.java
==============================================================================
--- 
trunk/solutions/identity/modules/identity-provider/src/main/java/org/wso2/solutions/identity/sts/OpenIDTokenIssuer.java
     (original)
+++ 
trunk/solutions/identity/modules/identity-provider/src/main/java/org/wso2/solutions/identity/sts/OpenIDTokenIssuer.java
     Mon Mar 10 23:57:15 2008
@@ -195,7 +195,7 @@
 
         params.set(new Parameter(
                 IdentityConstants.OpenId.ExchangeAttributes.EXT,
-                IdentityConstants.OpenId.ExchangeAttributes.NS_AX));
+                "http://openid.net/srv/ax/1.0-draft4";));
 
         params.set(new Parameter(
                 IdentityConstants.OpenId.ExchangeAttributes.MODE,

Modified: 
trunk/solutions/identity/modules/token-verifier-core/src/main/java/org/wso2/solutions/identity/relyingparty/openid/extensions/OpenIDAttributeExchange.java
==============================================================================
--- 
trunk/solutions/identity/modules/token-verifier-core/src/main/java/org/wso2/solutions/identity/relyingparty/openid/extensions/OpenIDAttributeExchange.java
  (original)
+++ 
trunk/solutions/identity/modules/token-verifier-core/src/main/java/org/wso2/solutions/identity/relyingparty/openid/extensions/OpenIDAttributeExchange.java
  Mon Mar 10 23:57:15 2008
@@ -1,6 +1,9 @@
 package org.wso2.solutions.identity.relyingparty.openid.extensions;
 
+import java.util.HashMap;
 import java.util.List;
+import java.util.Map;
+
 import javax.servlet.http.HttpServletRequest;
 
 import org.openid4java.message.AuthSuccess;
@@ -17,6 +20,51 @@
 
     private AuthSuccess authSuccess;
 
+    private static Map<String, String> axMapping = new HashMap<String, 
String>();
+
+    static {
+        axMapping.put(
+                IdentityConstants.OpenId.ExchangeAttributes.POSTAL_CODE_NS,
+                IdentityConstants.OpenId.ExchangeAttributes.POSTAL_CODE);
+        axMapping.put(IdentityConstants.OpenId.ExchangeAttributes.NICK_NAME_NS,
+                IdentityConstants.OpenId.ExchangeAttributes.NICK_NAME);
+        axMapping.put(IdentityConstants.OpenId.ExchangeAttributes.LANGUAGE_NS,
+                IdentityConstants.OpenId.ExchangeAttributes.LANGUAGE);
+        axMapping.put(IdentityConstants.OpenId.ExchangeAttributes.GENDER_NS,
+                IdentityConstants.OpenId.ExchangeAttributes.GENDER);
+        axMapping.put(IdentityConstants.OpenId.ExchangeAttributes.COUNTRY_NS,
+                IdentityConstants.OpenId.ExchangeAttributes.COUNTRY);
+        axMapping.put(IdentityConstants.OpenId.ExchangeAttributes.DOB_NS,
+                IdentityConstants.OpenId.ExchangeAttributes.DOB);
+        axMapping.put(IdentityConstants.OpenId.ExchangeAttributes.FULL_NAME_NS,
+                IdentityConstants.OpenId.ExchangeAttributes.FULL_NAME);
+        axMapping.put(IdentityConstants.OpenId.ExchangeAttributes.TIMEZONE_NS,
+                IdentityConstants.OpenId.ExchangeAttributes.TIMEZONE);
+        axMapping.put(IdentityConstants.OpenId.ExchangeAttributes.EMAIL_NS,
+                IdentityConstants.OpenId.ExchangeAttributes.EMAIL);
+        axMapping.put(
+                IdentityConstants.OpenId.ExchangeAttributes.POSTAL_CODE_NS2,
+                IdentityConstants.OpenId.ExchangeAttributes.POSTAL_CODE);
+        axMapping.put(
+                IdentityConstants.OpenId.ExchangeAttributes.NICK_NAME_NS2,
+                IdentityConstants.OpenId.ExchangeAttributes.NICK_NAME);
+        axMapping.put(IdentityConstants.OpenId.ExchangeAttributes.LANGUAGE_NS2,
+                IdentityConstants.OpenId.ExchangeAttributes.LANGUAGE);
+        axMapping.put(IdentityConstants.OpenId.ExchangeAttributes.GENDER_NS2,
+                IdentityConstants.OpenId.ExchangeAttributes.GENDER);
+        axMapping.put(IdentityConstants.OpenId.ExchangeAttributes.COUNTRY_NS2,
+                IdentityConstants.OpenId.ExchangeAttributes.COUNTRY);
+        axMapping.put(IdentityConstants.OpenId.ExchangeAttributes.DOB_NS2,
+                IdentityConstants.OpenId.ExchangeAttributes.DOB);
+        axMapping.put(
+                IdentityConstants.OpenId.ExchangeAttributes.FULL_NAME_NS2,
+                IdentityConstants.OpenId.ExchangeAttributes.FULL_NAME);
+        axMapping.put(IdentityConstants.OpenId.ExchangeAttributes.TIMEZONE_NS2,
+                IdentityConstants.OpenId.ExchangeAttributes.TIMEZONE);
+        axMapping.put(IdentityConstants.OpenId.ExchangeAttributes.EMAIL_NS2,
+                IdentityConstants.OpenId.ExchangeAttributes.EMAIL);
+    }
+
     /**
      * Default constructor
      */
@@ -73,6 +121,7 @@
         List aliases = null;
         List values = null;
         FetchResponse fetchReponse = null;
+        Map attributeTypes = null;
 
         try {
 
@@ -81,12 +130,12 @@
                 fetchReponse = (FetchResponse) authSuccess
                         .getExtension(FetchResponse.OPENID_NS_AX);
                 aliases = fetchReponse.getAttributeAliases();
+                attributeTypes = fetchReponse.getAttributeTypes();
 
                 for (Object alias : aliases) {
                     values = fetchReponse.getAttributeValues((String) alias);
-                    request
-                            .setAttribute((String) alias, (String) values
-                                    .get(0));
+                    
request.setAttribute(getAlias((String)attributeTypes.get(alias)),
+                            (String) values.get(0));
                 }
             }
         } catch (MessageException e) {
@@ -95,4 +144,18 @@
                     e);
         }
     }
+
+    /**
+     * This provides a mapping between http://schema.openid.net/ and
+     * http://axschema.org
+     * @param val schema name-space URL
+     * @return mapped value
+     */
+    protected String getAlias(String val) {
+        if (axMapping.containsKey(val)) {
+            return axMapping.get(val);
+        }
+
+        return val;
+    }
 }

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

Reply via email to