Author: dimuthul
Date: Mon Dec  3 06:35:11 2007
New Revision: 10440

Log:

Fixing Identity-133 bug


Modified:
   
trunk/solutions/identity/modules/identity-provider/src/main/java/org/wso2/solutions/identity/admin/RegisteredInfoCardInfoAdmin.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/persistence/IPPersistenceManager.java
   
trunk/solutions/identity/modules/identity-provider/src/main/java/org/wso2/solutions/identity/persistence/dao/RegisteredInfoCardInfoDAO.java
   
trunk/solutions/identity/modules/identity-provider/src/main/java/org/wso2/solutions/identity/sts/IdentityProviderData.java
   
trunk/solutions/identity/modules/user-ui/src/main/java/org/wso2/solutions/identity/user/ui/action/DownloadInfoCardAction.java
   
trunk/solutions/identity/modules/user-ui/src/main/java/org/wso2/solutions/identity/user/ui/action/RegisterInfoCardAction.java

Modified: 
trunk/solutions/identity/modules/identity-provider/src/main/java/org/wso2/solutions/identity/admin/RegisteredInfoCardInfoAdmin.java
==============================================================================
--- 
trunk/solutions/identity/modules/identity-provider/src/main/java/org/wso2/solutions/identity/admin/RegisteredInfoCardInfoAdmin.java
 (original)
+++ 
trunk/solutions/identity/modules/identity-provider/src/main/java/org/wso2/solutions/identity/admin/RegisteredInfoCardInfoAdmin.java
 Mon Dec  3 06:35:11 2007
@@ -74,4 +74,15 @@
         db.create(removedCard);
         db.delete(infoCard);
     }
+    
+    /**
+     * This method extracts the primary username if there is one.
+     * If there is no primary username ... null will be returned. 
+     */
+    public String extractPrimaryUserName(String ppid)  throws 
IdentityProviderException{
+        IPPersistenceManager db = IPPersistenceManager.getPersistanceManager();
+        return db.extractPrimaryUserName(ppid);
+    }
+    
+    
 }

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 Dec  3 06:35:11 2007
@@ -39,6 +39,7 @@
 import org.wso2.solutions.identity.IdentityProviderConstants;
 import org.wso2.solutions.identity.IdentityProviderException;
 import org.wso2.solutions.identity.admin.ParameterAdmin;
+import org.wso2.solutions.identity.admin.RegisteredInfoCardInfoAdmin;
 import org.wso2.solutions.identity.admin.ReportAdmin;
 import org.wso2.solutions.identity.cards.model.CardImage;
 import org.wso2.solutions.identity.cards.model.CardModelException;
@@ -74,8 +75,6 @@
 
     private static CardIssuerConfig issuerConfig = null;
 
-    private String userIdentifier = null;
-
     public CardIssuer() throws IdentityProviderException {
         issuerConfig = CardIssuerConfig.getInstance();
     }
@@ -84,23 +83,31 @@
             boolean requireAppliesTo) throws IdentityProviderException {
 
         UsernamePasswordCredential passCred = new UsernamePasswordCredential();
-        userIdentifier = username;
         passCred.setUsername(username);
         UserCredential cred = new UserCredential(passCred);
-        return issueCard(cred, requireAppliesTo);
+        return issueCard(cred, requireAppliesTo, username);
 
     }
 
-    public Element issueCardForSelfIssuedCard(String username, String ppid,
+    public Element issueCardForSelfIssuedCard(String ppid,
             boolean requireAppliesTo) throws IdentityProviderException {
+        Element cardElement = null;
         SelfIssuedCredential selfCred = new SelfIssuedCredential(ppid);
-        userIdentifier = ppid;
+        RegisteredInfoCardInfoAdmin registerAdmin = new 
RegisteredInfoCardInfoAdmin();
+        String primaryUserName = registerAdmin.extractPrimaryUserName(ppid);
         UserCredential cred = new UserCredential(selfCred);
-        return issueCard(cred, requireAppliesTo);
+        
+        if(primaryUserName == null){
+            cardElement = issueCard(cred, requireAppliesTo, ppid);
+        }else{
+            cardElement = issueCard(cred, requireAppliesTo, primaryUserName);
+        }
+        
+        return cardElement;
     }
 
     private Element issueCard(UserCredential credential,
-            boolean requireAppliesTo) throws IdentityProviderException {
+            boolean requireAppliesTo, String primaryUserId) throws 
IdentityProviderException {
         ServerConfiguration serverConfig = ServerConfiguration.getInstance();
 
         try {
@@ -131,11 +138,12 @@
             InformationCard infoCard = getInfoCard(credential, id,
                     requireAppliesTo);
 
-            storeCard(infoCard, credential.getCredentialId());
+            storeCard(infoCard, primaryUserId);
             Element elem = gen.signCard(infoCard);
 
             String cardId = infoCard.getInformationCardReference().getCardId();
-            ReportAdmin.record(userIdentifier,
+           
+            ReportAdmin.record(primaryUserId,
                     ActionDO.ACTION_USER_DOWNLOAD_CARD, "CardId ::" + cardId);
 
             return elem;

Modified: 
trunk/solutions/identity/modules/identity-provider/src/main/java/org/wso2/solutions/identity/persistence/IPPersistenceManager.java
==============================================================================
--- 
trunk/solutions/identity/modules/identity-provider/src/main/java/org/wso2/solutions/identity/persistence/IPPersistenceManager.java
  (original)
+++ 
trunk/solutions/identity/modules/identity-provider/src/main/java/org/wso2/solutions/identity/persistence/IPPersistenceManager.java
  Mon Dec  3 06:35:11 2007
@@ -443,4 +443,9 @@
         IssuedTokenDAO dao = new IssuedTokenDAO(hbConfig);
         return dao.getTokenDetailsForCardAndUser(cardId, userId);
     }
+    
+    public String extractPrimaryUserName(String ppid){
+        RegisteredInfoCardInfoDAO dao = new 
RegisteredInfoCardInfoDAO(hbConfig);
+        return dao.extractPrimaryUserName(ppid);
+    }
 }

Modified: 
trunk/solutions/identity/modules/identity-provider/src/main/java/org/wso2/solutions/identity/persistence/dao/RegisteredInfoCardInfoDAO.java
==============================================================================
--- 
trunk/solutions/identity/modules/identity-provider/src/main/java/org/wso2/solutions/identity/persistence/dao/RegisteredInfoCardInfoDAO.java
 (original)
+++ 
trunk/solutions/identity/modules/identity-provider/src/main/java/org/wso2/solutions/identity/persistence/dao/RegisteredInfoCardInfoDAO.java
 Mon Dec  3 06:35:11 2007
@@ -51,8 +51,8 @@
             hbConfig.closeSession();
         }
     }
-
-    public RegisteredInfoCardInfoDO getInformationCardInfo(String ppid) {
+    
+     public RegisteredInfoCardInfoDO getInformationCardInfo(String ppid) {
         Session session = hbConfig.getCurrentSession();
         Transaction tx = session.beginTransaction();
         try {
@@ -70,5 +70,34 @@
             hbConfig.closeSession();
         }
     }
+    
+    /**
+     * This method extracts the primary username if there is one.
+     * If there is no primary username ... null will be returned. 
+     */
+    public String extractPrimaryUserName(String ppid){
+        String username = null;
+        Session session = hbConfig.getCurrentSession();
+        Transaction tx = session.beginTransaction();
+        try {
+            Criteria criteria = session
+                    .createCriteria(RegisteredInfoCardInfoDO.class);
+            criteria.add(Expression.eq("ppid", ppid));
+            RegisteredInfoCardInfoDO ido = 
(RegisteredInfoCardInfoDO)criteria.uniqueResult();
+            if(ido != null){
+                username = ido.getUserId();
+            }
+        } catch (Throwable e) {
+            tx.rollback();
+            String msg = messages
+                    .getMessage("errorQuerryingRegisteredInfoCardInfo");
+            log.error(msg, e);
+            throw new RuntimeException(msg, e);
+        } finally {
+            hbConfig.closeSession();
+        }
+        
+        return username;        
+    }
 
 }

Modified: 
trunk/solutions/identity/modules/identity-provider/src/main/java/org/wso2/solutions/identity/sts/IdentityProviderData.java
==============================================================================
--- 
trunk/solutions/identity/modules/identity-provider/src/main/java/org/wso2/solutions/identity/sts/IdentityProviderData.java
  (original)
+++ 
trunk/solutions/identity/modules/identity-provider/src/main/java/org/wso2/solutions/identity/sts/IdentityProviderData.java
  Mon Dec  3 06:35:11 2007
@@ -89,6 +89,7 @@
     
     private String userIdentifier = null;
     
+    private String primaryId = null;
     
     /**
      * Populate CardSpace specific meta-data.
@@ -416,7 +417,7 @@
                     // IdentityProviderException("signatureInfoMismatch",
                     // new String[] { ppidValue });
                     // }
-
+                    
                 } else {
                     throw new IdentityProviderException("alianPPID",
                             new String[] { ppidValue });

Modified: 
trunk/solutions/identity/modules/user-ui/src/main/java/org/wso2/solutions/identity/user/ui/action/DownloadInfoCardAction.java
==============================================================================
--- 
trunk/solutions/identity/modules/user-ui/src/main/java/org/wso2/solutions/identity/user/ui/action/DownloadInfoCardAction.java
       (original)
+++ 
trunk/solutions/identity/modules/user-ui/src/main/java/org/wso2/solutions/identity/user/ui/action/DownloadInfoCardAction.java
       Mon Dec  3 06:35:11 2007
@@ -59,9 +59,9 @@
         String details = null;
         
         if (selfIssuedPpid != null) {
-            card = cardIssuer.issueCardForSelfIssuedCard(userName, 
selfIssuedPpid, true);
+            card = cardIssuer.issueCardForSelfIssuedCard(selfIssuedPpid, true);
          } else if (sessionPpid != null) {
-            card = cardIssuer.issueCardForSelfIssuedCard(userName, 
sessionPpid, true);
+            card = cardIssuer.issueCardForSelfIssuedCard(sessionPpid, true);
         } else {
             card = cardIssuer.issueCardForUsername(userName, true);
         }

Modified: 
trunk/solutions/identity/modules/user-ui/src/main/java/org/wso2/solutions/identity/user/ui/action/RegisterInfoCardAction.java
==============================================================================
--- 
trunk/solutions/identity/modules/user-ui/src/main/java/org/wso2/solutions/identity/user/ui/action/RegisterInfoCardAction.java
       (original)
+++ 
trunk/solutions/identity/modules/user-ui/src/main/java/org/wso2/solutions/identity/user/ui/action/RegisterInfoCardAction.java
       Mon Dec  3 06:35:11 2007
@@ -16,6 +16,10 @@
 
 package org.wso2.solutions.identity.user.ui.action;
 
+import java.util.Map;
+
+import javax.servlet.http.HttpServletRequest;
+
 import org.apache.struts2.StrutsStatics;
 import org.wso2.solutions.identity.IdentityConstants;
 import org.wso2.solutions.identity.admin.RegisteredInfoCardInfoAdmin;
@@ -25,10 +29,6 @@
 import org.wso2.solutions.identity.sts.IdentityProviderUtil;
 import org.wso2.solutions.identity.user.ui.UIConstants;
 
-import javax.servlet.http.HttpServletRequest;
-
-import java.util.Map;
-
 import com.opensymphony.xwork2.ActionContext;
 
 public class RegisterInfoCardAction extends ManagedAction {
@@ -44,7 +44,7 @@
         String user = (String) session.get(UIConstants.USER);
         String ppid = (String) request
                 .getAttribute(IdentityConstants.CLAIM_PPID);
-        if(ppid == null) {
+      if(ppid == null) {
             addErrorMessage("Failure: submitting an information card");
             return ERROR;
         }
@@ -52,10 +52,17 @@
                 .getAttribute(TokenVerifierConstants.ISSUER_INFO);
 
         RegisteredInfoCardInfoAdmin admin = new RegisteredInfoCardInfoAdmin();
-
+        
         if(!admin.isRegistedInformationCard(ppid)) {
-            admin.registerNewInfoCardInformation(ppid, user, issuerInfo);
-            ReportAdmin.record(user, ActionDO.ACTION_USER_REGISTER, 
"PPID="+ppid);
+            //TODO: what are the chances of user picking a ppid as a username 
????
+            String primaryUserName = admin.extractPrimaryUserName(user);
+            if(primaryUserName == null){
+                admin.registerNewInfoCardInformation(ppid, user, issuerInfo);
+                ReportAdmin.record(user, ActionDO.ACTION_USER_REGISTER, 
"PPID="+ppid);
+            }else{
+                admin.registerNewInfoCardInformation(ppid, primaryUserName, 
issuerInfo);
+                ReportAdmin.record(primaryUserName, 
ActionDO.ACTION_USER_REGISTER, "PPID="+ppid);
+            }
         } else {
             /*
              * This ERROR state will take the user back to the main page.

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

Reply via email to