Author: dimuthul
Date: Fri Dec 21 00:37:13 2007
New Revision: 11641

Log:

Adding the DisplayValue method to the base module.


Added:
   
trunk/solutions/identity/modules/base/src/main/java/org/wso2/solutions/identity/util/
   
trunk/solutions/identity/modules/base/src/main/java/org/wso2/solutions/identity/util/IdentityUtil.java
Modified:
   
trunk/solutions/identity/modules/identity-provider/src/main/java/org/wso2/solutions/identity/sts/IdentityProviderUtil.java
   
trunk/solutions/identity/modules/identity-provider/src/main/java/org/wso2/solutions/identity/sts/IdentityTokenIssuer.java
   
trunk/solutions/identity/modules/user-ui/src/main/java/org/wso2/solutions/identity/user/ui/action/InfoCardSubmitAction.java
   
trunk/solutions/identity/modules/user-ui/src/main/java/org/wso2/solutions/identity/user/ui/action/InfoCardUserRegistrationSubmitAction.java
   
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/RemoveRegisteredInfoCardAction.java

Added: 
trunk/solutions/identity/modules/base/src/main/java/org/wso2/solutions/identity/util/IdentityUtil.java
==============================================================================
--- (empty file)
+++ 
trunk/solutions/identity/modules/base/src/main/java/org/wso2/solutions/identity/util/IdentityUtil.java
      Fri Dec 21 00:37:13 2007
@@ -0,0 +1,38 @@
+package org.wso2.solutions.identity.util;
+
+import java.security.MessageDigest;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.xml.security.utils.Base64;
+
+public class IdentityUtil {
+
+    private static Log log = LogFactory.getLog(IdentityUtil.class);
+
+    private final static char[] ppidDisplayCharMap = new char[] { 'Q', 'L',
+            '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E',
+            'F', 'G', 'H', 'J', 'K', 'M', 'N', 'P', 'R', 'S', 'T', 'U', 'V',
+            'W', 'X', 'Y', 'Z' };
+
+    public static String getPPIDDisplayValue(String value) throws Exception {
+        log.info("Generating display value of PPID : " + value);
+        byte[] rawPpid = Base64.decode(value);
+        MessageDigest sha1 = MessageDigest.getInstance("SHA1");
+        sha1.update(rawPpid);
+        byte[] hashId = sha1.digest();
+        char[] returnChars = new char[10];
+        for (int i = 0; i < 10; i++) {
+            int rawValue = (hashId[i] + 128) % 32;
+            returnChars[i] = ppidDisplayCharMap[rawValue];
+        }
+        StringBuffer sb = new StringBuffer();
+        sb.append(returnChars, 0, 3);
+        sb.append("-");
+        sb.append(returnChars, 3, 4);
+        sb.append("-");
+        sb.append(returnChars, 6, 3);
+        return sb.toString();
+
+    }
+}

Modified: 
trunk/solutions/identity/modules/identity-provider/src/main/java/org/wso2/solutions/identity/sts/IdentityProviderUtil.java
==============================================================================
--- 
trunk/solutions/identity/modules/identity-provider/src/main/java/org/wso2/solutions/identity/sts/IdentityProviderUtil.java
  (original)
+++ 
trunk/solutions/identity/modules/identity-provider/src/main/java/org/wso2/solutions/identity/sts/IdentityProviderUtil.java
  Fri Dec 21 00:37:13 2007
@@ -15,30 +15,24 @@
  */
 package org.wso2.solutions.identity.sts;
 
+import java.net.URI;
+import java.net.URISyntaxException;
+
+import javax.xml.namespace.QName;
+
 import org.apache.axiom.om.OMElement;
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 import org.apache.rahas.RahasData;
-import org.apache.xml.security.utils.Base64;
 import org.wso2.solutions.identity.IdentityConstants;
 import org.wso2.solutions.identity.IdentityProviderConstants;
 import org.wso2.solutions.identity.IdentityProviderException;
 
-import javax.xml.namespace.QName;
-
-import java.net.URI;
-import java.net.URISyntaxException;
-import java.security.MessageDigest;
-
 public class IdentityProviderUtil {
 
     private static Log log = LogFactory.getLog(IdentityProviderUtil.class);
             
-    private final static char[] ppidDisplayCharMap = new char[] { 'Q', 'L',
-        '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E',
-        'F', 'G', 'H', 'J', 'K', 'M', 'N', 'P', 'R', 'S', 'T', 'U', 'V',
-        'W', 'X', 'Y', 'Z' };
-
+   
     public static OMElement createRequestedDisplayToken(OMElement parent,
             IdentityProviderData data) {
 
@@ -87,29 +81,7 @@
 
     }
     
-    public static String getPPIDDisplayValue(String value) throws 
IdentityProviderException {
-        try {
-            log.info("Generating display value of PPID : " + value);
-            byte[] rawPpid =  Base64.decode(value);
-            MessageDigest sha1 = MessageDigest.getInstance("SHA1");
-            sha1.update(rawPpid);
-            byte[] hashId = sha1.digest();
-            char[] returnChars = new char[10];
-            for (int i = 0; i < 10; i++) {
-                int rawValue = (hashId[i] + 128) % 32;
-                returnChars[i] = ppidDisplayCharMap[rawValue];
-            }
-            StringBuffer sb = new StringBuffer();
-            sb.append(returnChars, 0, 3);
-            sb.append("-");
-            sb.append(returnChars, 3, 4);
-            sb.append("-");
-            sb.append(returnChars, 6, 3);
-            return sb.toString();
-        } catch (Exception e) {
-            throw new 
IdentityProviderException("errorInGeneratingPPIDDisplayValue", new String[] 
{value}, e);
-        }
-    }
+   
 
     /**
      * Obtain the applies to host name from the WS-Trust request.

Modified: 
trunk/solutions/identity/modules/identity-provider/src/main/java/org/wso2/solutions/identity/sts/IdentityTokenIssuer.java
==============================================================================
--- 
trunk/solutions/identity/modules/identity-provider/src/main/java/org/wso2/solutions/identity/sts/IdentityTokenIssuer.java
   (original)
+++ 
trunk/solutions/identity/modules/identity-provider/src/main/java/org/wso2/solutions/identity/sts/IdentityTokenIssuer.java
   Fri Dec 21 00:37:13 2007
@@ -78,6 +78,7 @@
 import org.wso2.solutions.identity.persistence.dataobject.PPIDValueDO;
 import org.wso2.solutions.identity.persistence.dataobject.RelyingPartyDO;
 import org.wso2.solutions.identity.sts.IdentityProviderData.RequestedClaimData;
+import org.wso2.solutions.identity.util.IdentityUtil;
 import org.wso2.utils.ServerConfiguration;
 
 /**
@@ -467,19 +468,23 @@
         OMElement displayToken = IdentityProviderUtil.createDisplayToken(rdt,
                 ipData);
 
-        Iterator ite = requestedClaims.values().iterator();
-        while (ite.hasNext()) {
-            RequestedClaimData claim = (RequestedClaimData) ite.next();
-
-            if (claim.uri.equals(IdentityConstants.CLAIM_PPID)) {
-                //PPID display token
-                IdentityProviderUtil.createDisplayClaim(displayToken, ipData
-                        .getDisplayName(claim.uri), IdentityProviderUtil
-                        .getPPIDDisplayValue(claim.value), claim.uri);
-            } else {
-                IdentityProviderUtil.createDisplayClaim(displayToken, ipData
-                        .getDisplayName(claim.uri), claim.value, claim.uri);
+        try {
+            Iterator ite = requestedClaims.values().iterator();
+            while (ite.hasNext()) {
+                RequestedClaimData claim = (RequestedClaimData) ite.next();
+
+                if (claim.uri.equals(IdentityConstants.CLAIM_PPID)) {
+                    //PPID display token
+                    IdentityProviderUtil.createDisplayClaim(displayToken, 
ipData
+                            .getDisplayName(claim.uri), IdentityUtil
+                            .getPPIDDisplayValue(claim.value), claim.uri);
+                } else {
+                    IdentityProviderUtil.createDisplayClaim(displayToken, 
ipData
+                            .getDisplayName(claim.uri), claim.value, 
claim.uri);
+                }
             }
+        } catch (Exception e) {
+           throw new IdentityProviderException(e.getMessage(),e);
         }
 
         if (log.isDebugEnabled()) {

Modified: 
trunk/solutions/identity/modules/user-ui/src/main/java/org/wso2/solutions/identity/user/ui/action/InfoCardSubmitAction.java
==============================================================================
--- 
trunk/solutions/identity/modules/user-ui/src/main/java/org/wso2/solutions/identity/user/ui/action/InfoCardSubmitAction.java
 (original)
+++ 
trunk/solutions/identity/modules/user-ui/src/main/java/org/wso2/solutions/identity/user/ui/action/InfoCardSubmitAction.java
 Fri Dec 21 00:37:13 2007
@@ -16,6 +16,8 @@
 
 package org.wso2.solutions.identity.user.ui.action;
 
+import javax.servlet.http.HttpServletRequest;
+
 import org.apache.struts2.StrutsStatics;
 import org.wso2.solutions.identity.IdentityConstants;
 import org.wso2.solutions.identity.admin.RegisteredInfoCardInfoAdmin;
@@ -23,10 +25,8 @@
 import org.wso2.solutions.identity.persistence.dataobject.ActionDO;
 import 
org.wso2.solutions.identity.persistence.dataobject.RegisteredInfoCardInfoDO;
 import org.wso2.solutions.identity.relyingparty.TokenVerifierConstants;
-import org.wso2.solutions.identity.sts.IdentityProviderUtil;
 import org.wso2.solutions.identity.user.ui.UIConstants;
-
-import javax.servlet.http.HttpServletRequest;
+import org.wso2.solutions.identity.util.IdentityUtil;
 
 import com.opensymphony.xwork2.ActionContext;
 
@@ -61,7 +61,7 @@
             ReportAdmin.record(info.getUserId(),
                     ActionDO.ACTION_USER_LOG_IN_CARD, "PPID=" + ppid);
             this.addInfoMessage(getText("login_successful",
-                    new String[] { IdentityProviderUtil
+                    new String[] { IdentityUtil
                             .getPPIDDisplayValue(ppid) }));
         } else {
             this.addErrorMessage(getText("invalid_card_login"));

Modified: 
trunk/solutions/identity/modules/user-ui/src/main/java/org/wso2/solutions/identity/user/ui/action/InfoCardUserRegistrationSubmitAction.java
==============================================================================
--- 
trunk/solutions/identity/modules/user-ui/src/main/java/org/wso2/solutions/identity/user/ui/action/InfoCardUserRegistrationSubmitAction.java
 (original)
+++ 
trunk/solutions/identity/modules/user-ui/src/main/java/org/wso2/solutions/identity/user/ui/action/InfoCardUserRegistrationSubmitAction.java
 Fri Dec 21 00:37:13 2007
@@ -16,6 +16,10 @@
 
 package org.wso2.solutions.identity.user.ui.action;
 
+import java.util.HashMap;
+
+import javax.servlet.http.HttpServletRequest;
+
 import org.apache.axiom.om.util.UUIDGenerator;
 import org.apache.struts2.StrutsStatics;
 import org.wso2.solutions.identity.IdentityConstants;
@@ -24,11 +28,7 @@
 import org.wso2.solutions.identity.admin.RegisteredInfoCardInfoAdmin;
 import org.wso2.solutions.identity.persistence.dataobject.ClaimDO;
 import org.wso2.solutions.identity.relyingparty.TokenVerifierConstants;
-import org.wso2.solutions.identity.sts.IdentityProviderUtil;
-
-import javax.servlet.http.HttpServletRequest;
-
-import java.util.HashMap;
+import org.wso2.solutions.identity.util.IdentityUtil;
 
 import com.opensymphony.xwork2.ActionContext;
 
@@ -49,7 +49,7 @@
         RegisteredInfoCardInfoAdmin admin = new RegisteredInfoCardInfoAdmin();
         if(admin.isRegistedInformationCard(ppid)) {
             this.addErrorMessage(getText("card_alredy_registered",
-                    new String[] { IdentityProviderUtil
+                    new String[] { IdentityUtil
                             .getPPIDDisplayValue(ppid) }));
             return ERROR;
         }
@@ -57,7 +57,7 @@
         try {
             UserStore store = UserStore.getInstance();
             
-            String userName = IdentityProviderUtil.getPPIDDisplayValue(ppid);
+            String userName = IdentityUtil.getPPIDDisplayValue(ppid);
             store.getRealm().getUserStoreAdmin().addUser(userName, 
UUIDGenerator.getUUID());
 
             ClaimsAdmin ClaimsAdmin = new ClaimsAdmin();

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
       Fri Dec 21 00:37:13 2007
@@ -26,8 +26,8 @@
 import org.wso2.solutions.identity.admin.ReportAdmin;
 import org.wso2.solutions.identity.persistence.dataobject.ActionDO;
 import org.wso2.solutions.identity.relyingparty.TokenVerifierConstants;
-import org.wso2.solutions.identity.sts.IdentityProviderUtil;
 import org.wso2.solutions.identity.user.ui.UIConstants;
+import org.wso2.solutions.identity.util.IdentityUtil;
 
 import com.opensymphony.xwork2.ActionContext;
 
@@ -74,7 +74,7 @@
              * confused :P :-)
              */
             String msg = getText("register-card-already-exists",
-                    new String[] { IdentityProviderUtil
+                    new String[] { IdentityUtil
                     .getPPIDDisplayValue(ppid) });
             addErrorMessage(msg);
             ReportAdmin.record(user, ActionDO.ACTION_USER_FAILURE, msg);

Modified: 
trunk/solutions/identity/modules/user-ui/src/main/java/org/wso2/solutions/identity/user/ui/action/RemoveRegisteredInfoCardAction.java
==============================================================================
--- 
trunk/solutions/identity/modules/user-ui/src/main/java/org/wso2/solutions/identity/user/ui/action/RemoveRegisteredInfoCardAction.java
       (original)
+++ 
trunk/solutions/identity/modules/user-ui/src/main/java/org/wso2/solutions/identity/user/ui/action/RemoveRegisteredInfoCardAction.java
       Fri Dec 21 00:37:13 2007
@@ -16,11 +16,11 @@
 
 package org.wso2.solutions.identity.user.ui.action;
 
+import java.util.Map;
+
 import org.wso2.solutions.identity.admin.RegisteredInfoCardInfoAdmin;
-import org.wso2.solutions.identity.sts.IdentityProviderUtil;
 import org.wso2.solutions.identity.user.ui.UIConstants;
-
-import java.util.Map;
+import org.wso2.solutions.identity.util.IdentityUtil;
 
 import com.opensymphony.xwork2.ActionContext;
 
@@ -34,7 +34,7 @@
     public String execute() throws Exception {
         RegisteredInfoCardInfoAdmin admin = new RegisteredInfoCardInfoAdmin();
         //check whether a user is trying to remove the card that he/she 
registered with
-        String ppidDisplayValue = 
IdentityProviderUtil.getPPIDDisplayValue(ppid);
+        String ppidDisplayValue = IdentityUtil.getPPIDDisplayValue(ppid);
         
         ActionContext context = ActionContext.getContext();
         Map session = context.getSession();

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

Reply via email to