Author: prabath
Date: Sun Jan 27 22:19:28 2008
New Revision: 13025

Log:

login to OpenID provider with registered self-issued InfoCards 

Modified:
   
trunk/solutions/identity/modules/identity-provider/src/main/java/org/wso2/solutions/identity/openid/OpenIDProvider.java

Modified: 
trunk/solutions/identity/modules/identity-provider/src/main/java/org/wso2/solutions/identity/openid/OpenIDProvider.java
==============================================================================
--- 
trunk/solutions/identity/modules/identity-provider/src/main/java/org/wso2/solutions/identity/openid/OpenIDProvider.java
     (original)
+++ 
trunk/solutions/identity/modules/identity-provider/src/main/java/org/wso2/solutions/identity/openid/OpenIDProvider.java
     Sun Jan 27 22:19:28 2008
@@ -25,10 +25,16 @@
 import org.wso2.solutions.identity.IdentityConstants;
 import org.wso2.solutions.identity.IdentityProviderConstants;
 import org.wso2.solutions.identity.IdentityProviderException;
+import org.wso2.solutions.identity.admin.RegisteredInfoCardInfoAdmin;
+import 
org.wso2.solutions.identity.persistence.dataobject.RegisteredInfoCardInfoDO;
 import org.wso2.utils.ServerConfiguration;
 
 public class OpenIDProvider {
 
+    public final static String STATE_SUCCESS = "success";
+    public final static String SERVLET_ATTR_STATE = 
"org.wso2.solutions.identity.rp.State";
+    public final static String ISSUER_INFO = "issuerInfo";
+
     // Instantiate a ServerManager object.
     public static ServerManager manager = new OpenIDServerManager();
     private String authPage;
@@ -119,11 +125,16 @@
                                 
.getParameter(IdentityProviderConstants.OpenId.PASSWORD));
 
                 if (!authenticatedAndApproved) {
-                    // Not authenticated, redirect to the authentication page.
-                    session.setAttribute(
-                            IdentityProviderConstants.OpenId.PARAM_LIST,
-                            request);
-                    return authPage;
+                    if (!verifyInfoCardLogin(httpReq)) {
+                        // Not authenticated, redirect to the authentication
+                        // page.
+                        session.setAttribute(
+                                IdentityProviderConstants.OpenId.PARAM_LIST,
+                                request);
+                        return authPage;
+                    } else {
+                        authenticatedAndApproved = true;
+                    }
                 }
 
                 // Process an authentication request.
@@ -381,4 +392,35 @@
         }
         return null;
     }
+
+    /**
+     * 
+     * @param request
+     * @return
+     */
+    private boolean verifyInfoCardLogin(HttpServletRequest request) {
+        String state = (String) request.getAttribute(SERVLET_ATTR_STATE);
+
+        if (state == null || !STATE_SUCCESS.equals(state))
+            return false;
+
+        String ppid = (String) request
+                .getAttribute(IdentityConstants.CLAIM_PPID);
+        String issuerInfo = (String) request.getAttribute(ISSUER_INFO);
+
+        RegisteredInfoCardInfoAdmin admin = new RegisteredInfoCardInfoAdmin();
+        RegisteredInfoCardInfoDO info;
+        try {
+            info = admin.getInfo(ppid);
+        } catch (IdentityProviderException e) {
+            return false;
+        }
+
+        if (info != null && info.getIssuerInfo().equals(issuerInfo)) {
+            return true;
+        } else {
+            return false;
+        }
+    }
+
 }
\ No newline at end of file

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

Reply via email to