Author: prabath
Date: Tue Mar 25 01:37:33 2008
New Revision: 15066

Log:

JIRA: IDENTITY-188

Modified:
   
trunk/solutions/identity/modules/identity-provider/src/main/java/org/wso2/solutions/identity/cards/CardIssuer.java

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
  Tue Mar 25 01:37:33 2008
@@ -20,6 +20,7 @@
 import org.wso2.solutions.identity.IdentityConstants;
 import org.wso2.solutions.identity.IdentityProviderConstants;
 import org.wso2.solutions.identity.IdentityProviderException;
+import org.wso2.solutions.identity.UserStore;
 import org.wso2.solutions.identity.admin.RegisteredInfoCardInfoAdmin;
 import org.wso2.solutions.identity.admin.ReportAdmin;
 import org.wso2.solutions.identity.cards.model.CardImage;
@@ -57,6 +58,9 @@
 import java.util.Calendar;
 import java.util.Date;
 import java.util.GregorianCalendar;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
 import java.util.TimeZone;
 
 /**
@@ -129,8 +133,8 @@
                     new String[] { "x509v3Cert", cert }));
         }
 
-        //TODO : Store audit data
-        //TOOD : - cert, user
+        // TODO : Store audit data
+        // TOOD : - cert, user
 
         X509V3Credential x509Cred = new X509V3Credential();
         x509Cred.setBase64EncodedThumbprintValue(cert);
@@ -173,7 +177,7 @@
             id.setCertificate((X509Certificate) store.getCertificate(alias));
 
             InformationCard infoCard = getInfoCard(credential, id,
-                    requireAppliesTo);
+                    requireAppliesTo, primaryUserId);
 
             if (isCardLogDebug) {
                 cardIssuerLog.debug(messages.getMessage("cardElementGenerated",
@@ -194,7 +198,8 @@
 
             if (isOpenIdInfoCard) {
                 ReportAdmin.record(primaryUserId,
-                        ActionDO.ACTION_USER_DOWNLOAD_OPENID_CARD, "CardId=" + 
cardId);
+                        ActionDO.ACTION_USER_DOWNLOAD_OPENID_CARD, "CardId="
+                                + cardId);
             } else {
                 ReportAdmin.record(primaryUserId,
                         ActionDO.ACTION_USER_DOWNLOAD_CARD, "CardId=" + 
cardId);
@@ -212,8 +217,8 @@
     }
 
     private InformationCard getInfoCard(UserCredential credential, Identity id,
-            boolean requireAppliesTo) throws CardModelException,
-            IdentityProviderException {
+            boolean requireAppliesTo, String primaryUserId)
+            throws CardModelException, IdentityProviderException {
 
         InformationCard card = new InformationCard();
 
@@ -320,6 +325,7 @@
                 // the database.
                 // But, this claim needs to be included in the InfoCard.
                 if (supportedClaims[i].isSupported()
+                        && isValidClaim(primaryUserId, supportedClaims[i])
                         || supportedClaims[i].getUri().equals(
                                 IdentityConstants.CLAIM_OPENID)) {
                     SupportedClaimType claim = new SupportedClaimType(
@@ -332,7 +338,8 @@
             }
         } else {
             for (int i = 0; i < supportedClaims.length; i++) {
-                if (supportedClaims[i].isSupported()) {
+                if (supportedClaims[i].isSupported()
+                        && isValidClaim(primaryUserId, supportedClaims[i])) {
                     SupportedClaimType claim = new SupportedClaimType(
                             supportedClaims[i].getUri());
                     claim.setDisplayTag(supportedClaims[i].getDisplayTag());
@@ -390,6 +397,26 @@
                 + card.getInformationCardReference().getCardId());
     }
 
+    private boolean isValidClaim(String user, ClaimDO claim)
+            throws IdentityProviderException {
+        UserStore userStore = null;
+        Map<String, String> mapValues = null;
+
+        if (IdentityConstants.CLAIM_PPID.equals(claim.getUri()))
+            return true;
+
+        userStore = UserStore.getInstance();
+        mapValues = userStore.getClaimValues(user, null);
+
+        if (mapValues != null && !mapValues.isEmpty()) {
+            if (mapValues.get(claim.getAttrId()) != null) {
+                return true;
+            }
+        }
+
+        return false;
+    }
+
     public void setIsOpenIdInfoCard(boolean isOpenIdInfoCard) {
         this.isOpenIdInfoCard = isOpenIdInfoCard;
     }

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

Reply via email to