Author: prabath
Date: Mon Jan  7 03:22:34 2008
New Revision: 11950

Log:

OpenID integration

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/UserInfoServlet.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
     Mon Jan  7 03:22:34 2008
@@ -131,7 +131,7 @@
             if (!authenticatedAndApproved) {
                 // Not authenticated, redirect to the authentication page.
                 session.setAttribute(
-                        IdentityProviderConstants.OpenId.PARAM_LIST, request); 
            
+                        IdentityProviderConstants.OpenId.PARAM_LIST, request);
                 return authPage;
             }
 
@@ -229,61 +229,70 @@
     private void setAttributeAxchange(SRegResponse response, List required,
             Map<String, String> claimValues) throws MessageException {
 
-        // If we can't find the required values with us, we simply add a null 
value it.
-        // Caller should verify whether he has got non-null values to all 
required attributes.
+        // If we can't find the required values with us, we simply add a null
+        // value it.
+        // Caller should verify whether he has got non-null values to all
+        // required attributes.
         // If not, what to do is up to the caller.
 
-        if (required.contains(IdentityConstants.OpenId.Attributes.EMAIL)) {
-            response.addAttribute(IdentityConstants.OpenId.Attributes.EMAIL,
-                    claimValues.get(EMAIL));
+        // An Identity Provider MAY return any subset of the following fields 
in
+        // response to the query.
+
+        if 
(required.contains(IdentityConstants.OpenId.SimpleRegAttributes.EMAIL)) {
+            response.addAttribute(
+                    IdentityConstants.OpenId.SimpleRegAttributes.EMAIL, 
claimValues
+                            .get(EMAIL));
         }
 
-        if (required.contains(IdentityConstants.OpenId.Attributes.NICK_NAME)) {
+        if (required
+                
.contains(IdentityConstants.OpenId.SimpleRegAttributes.NICK_NAME)) {
             response.addAttribute(
-                    IdentityConstants.OpenId.Attributes.NICK_NAME, claimValues
-                            .get(NICK_NAME));
+                    IdentityConstants.OpenId.SimpleRegAttributes.NICK_NAME,
+                    claimValues.get(NICK_NAME));
         }
 
-        if (required.contains(IdentityConstants.OpenId.Attributes.FULL_NAME)) {
+        if (required
+                
.contains(IdentityConstants.OpenId.SimpleRegAttributes.FULL_NAME)) {
             response.addAttribute(
-                    IdentityConstants.OpenId.Attributes.FULL_NAME, claimValues
-                            .get(FULL_NAME));
+                    IdentityConstants.OpenId.SimpleRegAttributes.FULL_NAME,
+                    claimValues.get(FULL_NAME));
         }
 
-        if (required.contains(IdentityConstants.OpenId.Attributes.COUNTRY)) {
-            response.addAttribute(IdentityConstants.OpenId.Attributes.COUNTRY,
+        if 
(required.contains(IdentityConstants.OpenId.SimpleRegAttributes.COUNTRY)) {
+            response.addAttribute(
+                    IdentityConstants.OpenId.SimpleRegAttributes.COUNTRY,
                     claimValues.get(COUNTRY));
         }
 
-        if 
(required.contains(IdentityConstants.OpenId.Attributes.POSTAL_CODE)) {
+        if (required
+                
.contains(IdentityConstants.OpenId.SimpleRegAttributes.POSTAL_CODE)) {
             response.addAttribute(
-                    IdentityConstants.OpenId.Attributes.POSTAL_CODE,
+                    IdentityConstants.OpenId.SimpleRegAttributes.POSTAL_CODE,
                     claimValues.get(POSTAL_CODE));
         }
 
-        if (required.contains(IdentityConstants.OpenId.Attributes.DOB)) {
-            response.addAttribute(IdentityConstants.OpenId.Attributes.DOB,
+        if 
(required.contains(IdentityConstants.OpenId.SimpleRegAttributes.DOB)) {
+            
response.addAttribute(IdentityConstants.OpenId.SimpleRegAttributes.DOB,
                     claimValues.get(DOB));
         }
-        if (required.contains(IdentityConstants.OpenId.Attributes.GENDER)) {
-            response.addAttribute(IdentityConstants.OpenId.Attributes.GENDER,
-                    claimValues.get(GENDER));
+        if 
(required.contains(IdentityConstants.OpenId.SimpleRegAttributes.GENDER)) {
+            response.addAttribute(
+                    IdentityConstants.OpenId.SimpleRegAttributes.GENDER, 
claimValues
+                            .get(GENDER));
         }
 
-        if (required.contains(IdentityConstants.OpenId.Attributes.LANGUAGE)) {
-            response.addAttribute(IdentityConstants.OpenId.Attributes.LANGUAGE,
+        if 
(required.contains(IdentityConstants.OpenId.SimpleRegAttributes.LANGUAGE)) {
+            response.addAttribute(
+                    IdentityConstants.OpenId.SimpleRegAttributes.LANGUAGE,
                     claimValues.get(LANGUAGE));
         }
 
-        if (required.contains(IdentityConstants.OpenId.Attributes.TIMEZONE)) {
-            response.addAttribute(IdentityConstants.OpenId.Attributes.TIMEZONE,
+        if 
(required.contains(IdentityConstants.OpenId.SimpleRegAttributes.TIMEZONE)) {
+            response.addAttribute(
+                    IdentityConstants.OpenId.SimpleRegAttributes.TIMEZONE,
                     claimValues.get(TIMEZONE));
         }
 
-        if (required.contains(IdentityConstants.OpenId.Attributes.BLOG)) {
-            response.addAttribute(IdentityConstants.OpenId.Attributes.BLOG,
-                    claimValues.get(BLOG));
-        }
     }
 
     /**
@@ -296,78 +305,80 @@
     private void setAttributeAxchange(FetchResponse response, Map required,
             Map<String, String> claimValues) throws MessageException {
 
-        // If we can't find the required values with us, we simply add a null 
value it.
-        // Caller should verify whether he has got non-null values to all 
required attributes.
+        // If we can't find the required values with us, we simply add a null
+        // value it.
+        // Caller should verify whether he has got non-null values to all
+        // required attributes.
         // If not, what to do is up to the caller..
 
-        if (required.containsKey(IdentityConstants.OpenId.Attributes.EMAIL)) {
-            response.addAttribute(IdentityConstants.OpenId.Attributes.EMAIL,
-                    IdentityConstants.OpenId.Attributes.EMAIL_NS, claimValues
+        if 
(required.containsKey(IdentityConstants.OpenId.ExchangeAttributes.EMAIL)) {
+            
response.addAttribute(IdentityConstants.OpenId.ExchangeAttributes.EMAIL,
+                    IdentityConstants.OpenId.ExchangeAttributes.EMAIL_NS, 
claimValues
                             .get(EMAIL));
         }
 
-        if (required.containsKey(IdentityConstants.OpenId.Attributes.ADDRESS)) 
{
-            response.addAttribute(IdentityConstants.OpenId.Attributes.ADDRESS,
-                    IdentityConstants.OpenId.Attributes.ADDRESS_NS, claimValues
+        if 
(required.containsKey(IdentityConstants.OpenId.ExchangeAttributes.ADDRESS)) {
+            
response.addAttribute(IdentityConstants.OpenId.ExchangeAttributes.ADDRESS,
+                    IdentityConstants.OpenId.ExchangeAttributes.ADDRESS_NS, 
claimValues
                             .get(ADDRESS));
         }
 
-        if (required.containsKey(IdentityConstants.OpenId.Attributes.CITY)) {
-            response.addAttribute(IdentityConstants.OpenId.Attributes.CITY,
-                    IdentityConstants.OpenId.Attributes.CITY_NS, claimValues
+        if 
(required.containsKey(IdentityConstants.OpenId.ExchangeAttributes.CITY)) {
+            
response.addAttribute(IdentityConstants.OpenId.ExchangeAttributes.CITY,
+                    IdentityConstants.OpenId.ExchangeAttributes.CITY_NS, 
claimValues
                             .get(CITY));
         }
 
-        if (required.containsKey(IdentityConstants.OpenId.Attributes.COUNTRY)) 
{
-            response.addAttribute(IdentityConstants.OpenId.Attributes.COUNTRY,
-                    IdentityConstants.OpenId.Attributes.COUNTRY_NS, claimValues
+        if 
(required.containsKey(IdentityConstants.OpenId.ExchangeAttributes.COUNTRY)) {
+            
response.addAttribute(IdentityConstants.OpenId.ExchangeAttributes.COUNTRY,
+                    IdentityConstants.OpenId.ExchangeAttributes.COUNTRY_NS, 
claimValues
                             .get(COUNTRY));
         }
 
         if (required
-                .containsKey(IdentityConstants.OpenId.Attributes.FIRST_NAME)) {
+                
.containsKey(IdentityConstants.OpenId.ExchangeAttributes.FIRST_NAME)) {
             response.addAttribute(
-                    IdentityConstants.OpenId.Attributes.FIRST_NAME,
-                    IdentityConstants.OpenId.Attributes.FIRST_NAME_NS,
+                    IdentityConstants.OpenId.ExchangeAttributes.FIRST_NAME,
+                    IdentityConstants.OpenId.ExchangeAttributes.FIRST_NAME_NS,
                     claimValues.get(FIRST_NAME));
         }
 
-        if 
(required.containsKey(IdentityConstants.OpenId.Attributes.LAST_NAME)) {
+        if 
(required.containsKey(IdentityConstants.OpenId.ExchangeAttributes.LAST_NAME)) {
             response.addAttribute(
-                    IdentityConstants.OpenId.Attributes.LAST_NAME,
-                    IdentityConstants.OpenId.Attributes.LAST_NAME_NS,
+                    IdentityConstants.OpenId.ExchangeAttributes.LAST_NAME,
+                    IdentityConstants.OpenId.ExchangeAttributes.LAST_NAME_NS,
                     claimValues.get(LAST_NAME));
         }
 
-        if 
(required.containsKey(IdentityConstants.OpenId.Attributes.FULL_NAME)) {
+        if 
(required.containsKey(IdentityConstants.OpenId.ExchangeAttributes.FULL_NAME)) {
             response.addAttribute(
-                    IdentityConstants.OpenId.Attributes.FULL_NAME,
-                    IdentityConstants.OpenId.Attributes.FULL_NAME_NS,
+                    IdentityConstants.OpenId.ExchangeAttributes.FULL_NAME,
+                    IdentityConstants.OpenId.ExchangeAttributes.FULL_NAME_NS,
                     claimValues.get(FULL_NAME));
         }
 
-        if 
(required.containsKey(IdentityConstants.OpenId.Attributes.NICK_NAME)) {
+        if 
(required.containsKey(IdentityConstants.OpenId.ExchangeAttributes.NICK_NAME)) {
             response.addAttribute(
-                    IdentityConstants.OpenId.Attributes.NICK_NAME,
-                    IdentityConstants.OpenId.Attributes.NICK_NAME_NS,
+                    IdentityConstants.OpenId.ExchangeAttributes.NICK_NAME,
+                    IdentityConstants.OpenId.ExchangeAttributes.NICK_NAME_NS,
                     claimValues.get(NICK_NAME));
         }
 
-        if (required.containsKey(IdentityConstants.OpenId.Attributes.PHONE)) {
-            response.addAttribute(IdentityConstants.OpenId.Attributes.PHONE,
-                    IdentityConstants.OpenId.Attributes.PHONE_NS, claimValues
+        if 
(required.containsKey(IdentityConstants.OpenId.ExchangeAttributes.PHONE)) {
+            
response.addAttribute(IdentityConstants.OpenId.ExchangeAttributes.PHONE,
+                    IdentityConstants.OpenId.ExchangeAttributes.PHONE_NS, 
claimValues
                             .get(PHONE));
         }
 
-        if 
(required.containsKey(IdentityConstants.OpenId.Attributes.ZIP_CODE)) {
-            response.addAttribute(IdentityConstants.OpenId.Attributes.ZIP_CODE,
-                    IdentityConstants.OpenId.Attributes.ZIP_CODE_NS,
+        if 
(required.containsKey(IdentityConstants.OpenId.ExchangeAttributes.ZIP_CODE)) {
+            
response.addAttribute(IdentityConstants.OpenId.ExchangeAttributes.ZIP_CODE,
+                    IdentityConstants.OpenId.ExchangeAttributes.ZIP_CODE_NS,
                     claimValues.get(ZIP_CODE));
         }
 
-        if (required.containsKey(IdentityConstants.OpenId.Attributes.BLOG)) {
-            response.addAttribute(IdentityConstants.OpenId.Attributes.BLOG,
-                    IdentityConstants.OpenId.Attributes.BLOG, claimValues
+        if 
(required.containsKey(IdentityConstants.OpenId.ExchangeAttributes.BLOG)) {
+            
response.addAttribute(IdentityConstants.OpenId.ExchangeAttributes.BLOG,
+                    IdentityConstants.OpenId.ExchangeAttributes.BLOG, 
claimValues
                             .get(BLOG));
         }
 

Modified: 
trunk/solutions/identity/modules/identity-provider/src/main/java/org/wso2/solutions/identity/openid/UserInfoServlet.java
==============================================================================
--- 
trunk/solutions/identity/modules/identity-provider/src/main/java/org/wso2/solutions/identity/openid/UserInfoServlet.java
    (original)
+++ 
trunk/solutions/identity/modules/identity-provider/src/main/java/org/wso2/solutions/identity/openid/UserInfoServlet.java
    Mon Jan  7 03:22:34 2008
@@ -2,12 +2,17 @@
 
 import java.io.IOException;
 import java.io.PrintWriter;
+import java.util.Iterator;
+import java.util.List;
 
 import javax.servlet.ServletException;
 import javax.servlet.http.HttpServlet;
 import javax.servlet.http.HttpServletRequest;
 import javax.servlet.http.HttpServletResponse;
 
+import org.wso2.solutions.identity.IdentityProviderException;
+import org.wso2.solutions.identity.UserStore;
+
 public class UserInfoServlet extends HttpServlet {
 
     private static final long serialVersionUID = -2306630174647697559L;
@@ -18,29 +23,73 @@
     protected void service(HttpServletRequest req, HttpServletResponse resp)
             throws ServletException, IOException {
 
-        String serverUrl = "http://"; + req.getServerName() + ":"
-                + req.getServerPort() + "/server";
+        String serverUrl = null;
+        String caller = null;
         String back = "";
-        if ("html".equals(req.getParameter("format"))) {
+
+        serverUrl = "http://"; + req.getServerName() + ":" + req.getServerPort()
+                + "/server";
+
+        caller = req.getPathInfo();
+
+        if (!isUserExist(caller.substring(1))) {
             resp.setContentType("text/html");
-            back = "<html><head>\n" + "<link rel='openid.server' href='"
-                    + serverUrl + "'/>\n"
-                    + "</head><body>in html</body></html>";
+            back = "<html><head>\n"
+                    + "</head><body><h1>You are trying to do something fishy 
!!!</h1></body></html>";
         } else {
-            resp.setContentType("application/xrds+xml");
-            back = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
-                    + "<xrds:XRDS\n" + "  xmlns:xrds=\"xri://$xrds\"\n"
-                    + "  xmlns:openid=\"http://openid.net/xmlns/1.0\"\n";
-                    + "  xmlns=\"xri://$xrd*($v*2.0)\">\n" + "  <XRD>\n"
-                    + "    <Service priority=\"0\">\n"
-                    + "      <Type>http://openid.net/signon/1.0</Type>\n"
-                    + "      <URI>http://"; + req.getServerName() + ":"
-                    + req.getServerPort() + "/server</URI>\n"
-                    + "    </Service>\n" + "  </XRD>\n" + "</xrds:XRDS>";
+            if ("html".equals(req.getParameter("format"))) {
+                resp.setContentType("text/html");
+                back = "<html><head>\n" + "<link rel='openid.server' href='"
+                        + serverUrl + "'/>\n"
+                        + "</head><body>in html</body></html>";
+            } else {
+                resp.setContentType("application/xrds+xml");
+                back = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
+                        + "<xrds:XRDS\n" + "  xmlns:xrds=\"xri://$xrds\"\n"
+                        + "  xmlns:openid=\"http://openid.net/xmlns/1.0\"\n";
+                        + "  xmlns=\"xri://$xrd*($v*2.0)\">\n" + "  <XRD>\n"
+                        + "    <Service priority=\"0\">\n"
+                        + "      <Type>http://openid.net/signon/1.0</Type>\n"
+                        + "      <URI>http://"; + req.getServerName() + ":"
+                        + req.getServerPort() + "/server</URI>\n"
+                        + "    </Service>\n" + "  </XRD>\n" + "</xrds:XRDS>";
+            }
         }
 
         PrintWriter out = resp.getWriter();
         out.write(back);
     }
 
+    /**
+     * 
+     * @param userName
+     * @return
+     */
+    private boolean isUserExist(String userName) {
+
+        UserStore userStore = null;
+        List users = null;
+        Iterator iterator = null;
+
+        try {
+            userStore = UserStore.getInstance();
+            users = userStore.getAllUserNames();
+            iterator = users.iterator();
+
+            String user = null;
+
+            while (iterator.hasNext()) {
+
+                user = (String) iterator.next();
+
+                if (user.equals(userName))
+                    return true;
+            }
+        } catch (IdentityProviderException e) {
+            return false;
+        }
+
+        return false;
+    }
+
 }

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

Reply via email to