Author: prabath
Date: Tue Feb 12 00:19:29 2008
New Revision: 13621

Log:

comments

Modified:
   
trunk/solutions/identity/modules/user-ui/src/main/java/org/wso2/solutions/identity/user/ui/util/UserUtil.java

Modified: 
trunk/solutions/identity/modules/user-ui/src/main/java/org/wso2/solutions/identity/user/ui/util/UserUtil.java
==============================================================================
--- 
trunk/solutions/identity/modules/user-ui/src/main/java/org/wso2/solutions/identity/user/ui/util/UserUtil.java
       (original)
+++ 
trunk/solutions/identity/modules/user-ui/src/main/java/org/wso2/solutions/identity/user/ui/util/UserUtil.java
       Tue Feb 12 00:19:29 2008
@@ -7,7 +7,6 @@
 import javax.servlet.http.HttpServletRequest;
 
 import org.apache.struts2.StrutsStatics;
-import org.openid4java.server.ServerException;
 import org.wso2.solutions.identity.IdentityConstants;
 import org.wso2.solutions.identity.IdentityProviderException;
 import org.wso2.solutions.identity.UserStore;
@@ -16,6 +15,7 @@
 import org.wso2.solutions.identity.persistence.IPPersistenceManager;
 import org.wso2.solutions.identity.persistence.dataobject.ActionDO;
 import 
org.wso2.solutions.identity.persistence.dataobject.RegisteredInfoCardInfoDO;
+import org.wso2.solutions.identity.relyingparty.RelyingPartyException;
 import org.wso2.solutions.identity.relyingparty.TokenVerifierConstants;
 import org.wso2.solutions.identity.user.ui.UIConstants;
 
@@ -24,24 +24,34 @@
 public class UserUtil {
 
     /**
+     * Get the user name corresponding to a given OpenID
      * 
      * @param openID
-     * @return
-     * @throws ServerException
-     * @throws Exception
+     *                OpenID used to log in
+     * @return Corresponding user name
+     * @throws RelyingPartyException
      */
-    public static String getUserName(String openID) throws ServerException,
-            Exception {
+    public static String getUserName(String openID)
+            throws RelyingPartyException {
 
         UserStore userStore = null;
         List users = null;
 
-        userStore = UserStore.getInstance();
-        users = userStore.getAllUserNames();
+        try {
+            userStore = UserStore.getInstance();
+            users = userStore.getAllUserNames();
+        } catch (IdentityProviderException e) {
+            throw new RelyingPartyException(
+                    IdentityConstants.ErrorCodes.USERNAME_RETRIEVAL_FAILED);
+        }
 
         if (users == null)
-            // TODO: Define a custom exception or use a more appropriate one.
-            throw new Exception("No users found");
+            throw new RelyingPartyException(
+                    IdentityConstants.ErrorCodes.NO_USERS_FOUND);
+
+        if (openID == null || openID.trim().length() == 0)
+            throw new RelyingPartyException(
+                    IdentityConstants.ErrorCodes.NULL_OPEN_ID);
 
         Map mapValues = null;
         Iterator iterator = null;
@@ -51,10 +61,15 @@
         while (iterator.hasNext()) {
 
             String user = (String) iterator.next();
-            mapValues = userStore.getClaimValues(user, null);
 
-            if (mapValues != null && !mapValues.isEmpty()) {
+            try {
+                mapValues = userStore.getClaimValues(user, null);
+            } catch (IdentityProviderException e) {
+                throw new RelyingPartyException(
+                        IdentityConstants.ErrorCodes.CLAIM_RETRIEVAL_FAILED);
+            }
 
+            if (mapValues != null && !mapValues.isEmpty()) {
                 // User has defined claims!
                 String claimId = (String) mapValues
                         .get(IdentityConstants.CLAIM_OPENID);
@@ -68,19 +83,18 @@
                 }
             }
         }
-
-        // TODO: Define a custom exception or use a more appropriate one.
-        throw new Exception("No user found, correponding to the given OpenID");
+        throw new RelyingPartyException(
+                IdentityConstants.ErrorCodes.NO_USERS_FOUND);
     }
 
     /**
-     * Verify authentication.
+     * Verify user name/password authentication.
      * 
      * @param username
      *                User name
      * @param password
      *                Password
-     * @return
+     * @return true if user successfully authenticated
      */
     public static boolean doLogin(String username, String password) {
         try {
@@ -93,13 +107,14 @@
     }
 
     /**
+     * Verify user information card authentication.
      * 
-     * @param request
-     * @return
-     * @throws IdentityProviderException
+     * @param ActionContext
+     * @return true if user successfully authenticated
+     * @throws RelyingPartyException
      */
     public static boolean verifyInfoCardLogin(ActionContext context,
-            String openID) throws IdentityProviderException {
+            String openID) throws RelyingPartyException {
 
         HttpServletRequest request = (HttpServletRequest) context
                 .get(StrutsStatics.HTTP_REQUEST);
@@ -118,6 +133,7 @@
 
         RegisteredInfoCardInfoAdmin admin = new RegisteredInfoCardInfoAdmin();
         RegisteredInfoCardInfoDO info;
+
         try {
             info = admin.getInfo(ppid);
         } catch (IdentityProviderException e) {
@@ -144,18 +160,34 @@
         }
     }
 
-    public static String getOpenID(String ppid) throws ServerException,
-            Exception {
+    /**
+     * Get OpenID corresponding to a given PPID
+     * 
+     * @param ppid
+     *                PPID of the self-issued information card
+     * @return OpenID corresponding to the given PPID
+     * @throws RelyingPartyException
+     */
+    public static String getOpenID(String ppid) throws RelyingPartyException {
 
         UserStore userStore = null;
         List users = null;
 
-        userStore = UserStore.getInstance();
-        users = userStore.getAllUserNames();
+        try {
+            userStore = UserStore.getInstance();
+            users = userStore.getAllUserNames();
+        } catch (IdentityProviderException e) {
+            throw new RelyingPartyException(
+                    IdentityConstants.ErrorCodes.USERNAME_RETRIEVAL_FAILED);
+        }
 
         if (users == null)
-            // TODO: Define a custom exception or use a more appropriate one.
-            throw new Exception("No users found");
+            throw new RelyingPartyException(
+                    IdentityConstants.ErrorCodes.NO_USERS_FOUND);
+
+        if (ppid == null || ppid.trim().length() == 0)
+            throw new RelyingPartyException(
+                    IdentityConstants.ErrorCodes.INVALID_PPID);
 
         Map mapValues = null;
         Iterator iterator = null;
@@ -165,7 +197,12 @@
         while (iterator.hasNext()) {
 
             String user = (String) iterator.next();
-            mapValues = userStore.getClaimValues(user, null);
+            try {
+                mapValues = userStore.getClaimValues(user, null);
+            } catch (IdentityProviderException e) {
+                throw new RelyingPartyException(
+                        IdentityConstants.ErrorCodes.CLAIM_RETRIEVAL_FAILED);
+            }
 
             if (mapValues != null && !mapValues.isEmpty()) {
 
@@ -176,10 +213,15 @@
                         .get(IdentityConstants.CLAIM_PPID);
 
                 if (currentppid == null) {
-                    // this is a user signed up with user-name/password and 
later
-                    // registered an infocard.
-                    IPPersistenceManager db = IPPersistenceManager
-                            .getPersistanceManager();
+                    // This is a user signed up with user-name/password and
+                    // later registered an information card.
+                    IPPersistenceManager db;
+                    try {
+                        db = IPPersistenceManager.getPersistanceManager();
+                    } catch (IdentityProviderException e) {
+                        throw new RelyingPartyException(
+                                
IdentityConstants.ErrorCodes.DB_CONNECTION_FAILURE);
+                    }
                     RegisteredInfoCardInfoDO[] infocards = null;
                     infocards = db.getAllRegistedInfoCardInfoForUser(user);
 
@@ -193,9 +235,8 @@
                     return claimId;
             }
         }
-
-        // TODO: Define a custom exception or use a more appropriate one.
-        throw new Exception("No OpenID found for the given ppid");
+        throw new RelyingPartyException(
+                IdentityConstants.ErrorCodes.NO_OPENID_FOUND);
     }
 
 }

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

Reply via email to