Author: channa
Date: Sat May  3 01:05:24 2008
New Revision: 16482

Log:

Completed OpenID support for self registration.


Added:
   trunk/mashup/java/modules/www/images/openid-logo.gif   (contents, props 
changed)
   trunk/mashup/java/modules/www/images/openid-logo.jpg   (contents, props 
changed)
Modified:
   trunk/mashup/java/modules/core/conf/UI.properties
   
trunk/mashup/java/modules/core/src/org/wso2/mashup/webapp/identity/IdentityRegistrationBean.java
   trunk/mashup/java/modules/www/allow_guests.jsp
   trunk/mashup/java/modules/www/register_self.jsp
   trunk/mashup/java/modules/www/register_self_identity.jsp
   trunk/mashup/java/modules/www/signin.jsp

Modified: trunk/mashup/java/modules/core/conf/UI.properties
==============================================================================
--- trunk/mashup/java/modules/core/conf/UI.properties   (original)
+++ trunk/mashup/java/modules/core/conf/UI.properties   Sat May  3 01:05:24 2008
@@ -5,5 +5,5 @@
 register.admin.message=Please take a moment to secure the WSO2 Mashup Server 
by providing a user name and password for the primary account. This primary 
account will have administrative privileges, with full control over all the 
resources and users. Additional users can be added by this account, or 
self-registration with email verification can be enabled.</p><p>Note that if no 
email address is provided, you will be unable to recover a lost password for 
this account.
 reset.password.title=Reset Password
 reset.password.message=Enter the user name and e-mail ID you registered with 
to reset your password.
-register.self.infocarderror=Infocard submission failed. Please register using 
another card or by entering data manually
-register.self.infocardreused=Infocard has already been registered. Please 
register using another card or by entering data manually
\ No newline at end of file
+register.self.identerror=Identity submission failed. Please register using 
another identifier or by entering data manually
+register.self.identreused=Identity has already been registered. Please 
register using another identifier or by entering data manually
\ No newline at end of file

Modified: 
trunk/mashup/java/modules/core/src/org/wso2/mashup/webapp/identity/IdentityRegistrationBean.java
==============================================================================
--- 
trunk/mashup/java/modules/core/src/org/wso2/mashup/webapp/identity/IdentityRegistrationBean.java
    (original)
+++ 
trunk/mashup/java/modules/core/src/org/wso2/mashup/webapp/identity/IdentityRegistrationBean.java
    Sat May  3 01:05:24 2008
@@ -41,6 +41,7 @@
     public static final String OPENID_TYPE = "openid_type";
 
     // Constants for storing values in the servlet context.
+    private static final String USER_NAME = "username";
     private static final String FULL_NAME = "fullname";
     private static final String EMAIL_ID = "emailid";
     private static final String IDENTIFIER = "identifier";
@@ -105,15 +106,32 @@
         // Get values from context
         HttpSession session = request.getSession();
         identifier = (String) session.getAttribute(IDENTIFIER);
-        fullName = (String) session.getAttribute(FULL_NAME);
-        emailId = (String) session.getAttribute(EMAIL_ID);
+        fullName = "".equals(session.getAttribute(FULL_NAME)) ? fullName :
+                (String)session.getAttribute(FULL_NAME) ;
+        emailId = "".equals(session.getAttribute(EMAIL_ID)) ? emailId :
+                (String)session.getAttribute(EMAIL_ID) ;
         identifierType = (String) session.getAttribute(AUTHTYPE);
 
+        // Only OpenID provides a claim that can be used as the user name.
+        if (identifierType.equals(OPENID_TYPE) && 
!"".equals(session.getAttribute(USER_NAME))) {
+            userName = (String) session.getAttribute(USER_NAME);
+        }
+
         if (userName.equals("")) {
             errors.put("userName", "User name cannot be empty.");
             valid = false;
         }
 
+        if (fullName.equals("")) {
+            errors.put("fullName", "Full name cannot be empty.");              
  
+            valid = false;
+        }
+
+        if (emailId.equals("")) {
+            errors.put("emailId", "E-mail ID cannot be empty.");
+            valid = false;
+        }
+
         // Expensive operation, so do only once all other data has been 
validated.
         if (valid) {
             if (ManageUsers.isExistingUser(request, userName)) {
@@ -127,10 +145,10 @@
     }
 
     /**
-     * Retrieve the user's claims from the infocard, to be used in 
registration.
+     * Retrieve the user's claims from the InfoCard, to be used in 
registration.
      *
      * @param request Servlet request object.
-     * @return True if infocard information has been retrieved successfully.
+     * @return True if InfoCard information has been retrieved successfully.
      */
     public boolean setInfoCardDetails(HttpServletRequest request) {
         boolean infocardOk = false;
@@ -156,29 +174,55 @@
     }
 
     /**
-     * Retrieve the user's claims from the infocard, to be used in 
registration.
+     * Retrieve the user's claims from the OpenID, to be used in registration.
      *
      * @param request Servlet request object.
-     * @return True if infocard information has been retrieved successfully.
+     * @return True if OpenID information has been retrieved successfully.
      */
     public boolean setOpenIdDetails(HttpServletRequest request) {
         boolean openIdOk = false;
+        String nickName;
         HttpSession session = request.getSession();
 
         // If infocard has been successfully used, proceed.
         String auth = (String) 
request.getAttribute(TokenVerifierConstants.SERVLET_ATTR_STATE);
 
-        // Get the details from the infocard and add to session for 
persistance.
+        // Get the available details from the OpenID and add to session for 
persistance.
         if (TokenVerifierConstants.STATE_SUCCESS.equals(auth)) {
-            identifier = (String) 
request.getAttribute(IdentityConstants.OpenId.OPENID_IDENTIFIER);
+            identifier = getValueFromRequest(request, 
IdentityConstants.OpenId.OPENID_IDENTIFIER);
             session.setAttribute(IDENTIFIER, identifier);
-            fullName = (String) 
request.getAttribute(IdentityConstants.OpenId.SimpleRegAttributes.FULL_NAME);
+            nickName = getValueFromRequest(request, 
IdentityConstants.OpenId.SimpleRegAttributes.NICK_NAME);
+
+            // If the nickname is unique, use it as the user name.
+            if (!"".equals(nickName) && !ManageUsers.isExistingUser(request, 
nickName)) {
+                userName = nickName;
+            } else {
+                userName = "";
+            }
+
+            session.setAttribute(USER_NAME, userName);
+            fullName = getValueFromRequest(request, 
IdentityConstants.OpenId.SimpleRegAttributes.FULL_NAME);
             session.setAttribute(FULL_NAME, fullName);
-            emailId = (String) 
request.getAttribute(IdentityConstants.OpenId.SimpleRegAttributes.EMAIL);
+            emailId = getValueFromRequest(request, 
IdentityConstants.OpenId.SimpleRegAttributes.EMAIL);
             session.setAttribute(EMAIL_ID, emailId);
+
             session.setAttribute(AUTHTYPE, OPENID_TYPE);
             openIdOk = true;
         }
         return openIdOk;
     }
+
+    /**
+     * Returns the value contained in the request for a given key.
+     * @param key
+     */
+    private String getValueFromRequest(HttpServletRequest request, String key) 
{
+        String returnValue = "";
+        Object value = request.getAttribute(key);
+
+        if (value != null) {
+            returnValue = (String) value;
+        }
+        return returnValue;
+    }
 }

Modified: trunk/mashup/java/modules/www/allow_guests.jsp
==============================================================================
--- trunk/mashup/java/modules/www/allow_guests.jsp      (original)
+++ trunk/mashup/java/modules/www/allow_guests.jsp      Sat May  3 01:05:24 2008
@@ -77,8 +77,8 @@
                                 &lt;param-value>relay.wso2.com&lt;/param-value>
                             &lt;/init-param>
                             &lt;init-param>
-                                
&lt;param-name>registration_validation_url&lt;/param-name>
-                                
&lt;param-value>https://wso2.com/validate.jsp&lt;/param-value>
+                                &lt;param-name>webapp_url&lt;/param-name>
+                                
&lt;param-value>https://wso2.com/&lt;/param-value>
                             &lt;/init-param>
                             &lt;init-param>
                                 
&lt;param-name>email_from_address&lt;/param-name>

Added: trunk/mashup/java/modules/www/images/openid-logo.gif
==============================================================================
Binary file. No diff available.

Added: trunk/mashup/java/modules/www/images/openid-logo.jpg
==============================================================================
Binary file. No diff available.

Modified: trunk/mashup/java/modules/www/register_self.jsp
==============================================================================
--- trunk/mashup/java/modules/www/register_self.jsp     (original)
+++ trunk/mashup/java/modules/www/register_self.jsp     Sat May  3 01:05:24 2008
@@ -219,9 +219,10 @@
     </td>
     <td align="center" valign="top" height="175">
         <form name="openidsignin" id="openidsignin" method="post" 
action="openidsubmit.jsp">
+            <img src="images/openid-logo.jpg" border="0"><br/>
             Enter Your OpenID Url for self registration:<input type="text" 
name="openIdUrl"/>
             <input type="hidden" name="calledfrom" value="registration"/>
-            <input type="submit" name="submit" value="Login"/>
+            <input type="submit" name="submit" value="Register"/>
         </form>
     </td>
 </tr>

Modified: trunk/mashup/java/modules/www/register_self_identity.jsp
==============================================================================
--- trunk/mashup/java/modules/www/register_self_identity.jsp    (original)
+++ trunk/mashup/java/modules/www/register_self_identity.jsp    Sat May  3 
01:05:24 2008
@@ -22,7 +22,7 @@
 <%
     ResourceBundle bundle = ResourceBundle.getBundle("UI");
     UserRegistry userRegistry = RegistryUtils.getRegistry(request);
-    
+
     String bounceback = request.getParameter("bounceback");
     String fromIdentityProvider = request.getParameter("FromIdentityProvider");
     String authMethod = 
request.getParameter(MashupConstants.AUTHENTICATION_METHOD);
@@ -32,27 +32,29 @@
         bounceback = URLDecoder.decode(bounceback, "UTF-8");
     }
 %>
-<jsp:useBean id="infoCardRegHandler" 
class="org.wso2.mashup.webapp.identity.IdentityRegistrationBean"
+<jsp:useBean id="identityRegHandler"
+             class="org.wso2.mashup.webapp.identity.IdentityRegistrationBean"
              scope="request">
-    <jsp:setProperty name="infoCardRegHandler" property="*"/>
+    <jsp:setProperty name="identityRegHandler" property="*"/>
 </jsp:useBean>
 <%
-   boolean authenticatedDetailsRetrieved = false;
-   boolean identityAlreadyUsed = false;
+    boolean authenticatedDetailsRetrieved = false;
+    boolean identityAlreadyUsed = false;
     if (MashupConstants.TRUE.equals(fromIdentityProvider)) {
         if (MashupConstants.INFOCARD.equals(authMethod)) {
-            authenticatedDetailsRetrieved = 
infoCardRegHandler.setInfoCardDetails(request);
+            authenticatedDetailsRetrieved = 
identityRegHandler.setInfoCardDetails(request);
         } else {
-            authenticatedDetailsRetrieved = 
infoCardRegHandler.setOpenIdDetails(request);
+            authenticatedDetailsRetrieved = 
identityRegHandler.setOpenIdDetails(request);
         }
         // If the details were successfully retrieved, check for duplication.
         if (authenticatedDetailsRetrieved) {
-            identityAlreadyUsed = 
org.wso2.mashup.webapp.identity.IdentityHandler.isIdentifierRegistered(request,
-                                                                       
infoCardRegHandler.getIdentifier());
+            identityAlreadyUsed =
+                    
org.wso2.mashup.webapp.identity.IdentityHandler.isIdentifierRegistered(request,
+                        identityRegHandler.getIdentifier());
         }
     } else {
-        if (infoCardRegHandler.isInputValid(request)) {
-            if (infoCardRegHandler.register(request)) {
+        if (identityRegHandler.isInputValid(request)) {
+            if (identityRegHandler.register(request)) {
                 response.sendRedirect(
                         "registration_result.jsp?success=true&bounceback=" + 
bounceback);
             } else {
@@ -65,7 +67,7 @@
 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd";>
 <html>
 <head>
-    <title><%= bundle.getString("main.title")%> - Infocard Self 
Registration</title>
+    <title><%= bundle.getString("main.title")%> - Identity based Self 
Registration</title>
     <!-- Required CSS -->
     <link href="css/styles.css" rel="stylesheet" type="text/css"/>
     <script language="javascript" src="js/common.js" 
type="text/javascript"></script>
@@ -76,57 +78,91 @@
 <div id="page">
     <% String thisPage = bounceback; %>
     <%@ include file="header.jsp" %>
-       <div id="search"></div>
+    <div id="search"></div>
     <div id="content" style="height:400px; ">
         <% if (RegistrationBean.isSelfRegistrationEnabled()) {
-            if (MashupConstants.TRUE.equals(fromIdentityProvider) && 
(!authenticatedDetailsRetrieved ||
-                    identityAlreadyUsed)) { %>
-        <div class="mashup_title">Infocard Error</div>
-        <div>&nbsp;<%= identityAlreadyUsed ? 
bundle.getString("register.self.infocardreused") :
-                bundle.getString("register.self.infocarderror") %>
+            if (MashupConstants.TRUE.equals(fromIdentityProvider) &&
+                    (!authenticatedDetailsRetrieved || identityAlreadyUsed)) { 
%>
+        <div class="mashup_title">Identity Error</div>
+        <div>&nbsp;<%= identityAlreadyUsed ? 
bundle.getString("register.self.identreused") :
+                bundle.getString("register.self.identerror") %>
             <a 
href="register_self.jsp?firstcall=true&bounceback=<%=URLEncoder.encode(thisPage,"UTF-8")%>">here</a>.
         </div>
         <% } else { %>
-    <div class="mashup_title">Your infocard details have been added and will 
be verified via e-mail</div>
-      <br />
-                    <form name="formRegisterSelf" method='post' 
action="register_self_identity.jsp">
-                        <input type="hidden" name="bounceback" 
value="<%=bounceback%>"/>
-                        <table width="100%" border="0" cellpadding="3" 
cellspacing="0" >
-                            <tr>
-                                <td width="130"><label><strong>Full 
Name:</strong></label></td>
-                                <td><%=infoCardRegHandler.getFullName()%></td>
-                            </tr>
-                            <tr>
-                                <td 
width="130"><label><strong>E-mail:</strong></label></td>
-                                <td><%=infoCardRegHandler.getEmailId()%></td>
-                            </tr>
-                            <tr>
-                                <td width="130"><label><strong>User Name:<font 
color="#FF0000">*</font></strong></label></td>
-                                <td><input type="text" name="userName"
-                                           
value="<%=infoCardRegHandler.getUserName()%>"/>
-                                    <br><font 
color="#FF0000"><%=infoCardRegHandler.getErrorMessage("userName")%></font>
-                                </td>
-                            </tr>
-                            <tr>
-                                <td>&nbsp;</td>
-                                <td><input type="submit" value="Register"/> 
<input type="button" value="Cancel" onclick="document.location = '<%= 
bounceback %>';"></td>
-                            </tr>
-                            <tr>
-                              <td>&nbsp;</td>
-                              <td align="center"></td>
-                            </tr>
-                        </table>
-                    </form>
+        <div class="mashup_title">Details provided by your identity provider 
have been added to a profile. 
+            Please complete any required information not supplied by your 
identity provider in the form below and submit.
+        </div>
+        <br/>
+
+        <form name="formRegisterSelf" method='post' 
action="register_self_identity.jsp">
+            <input type="hidden" name="bounceback" value="<%=bounceback%>"/>
+            <table width="100%" border="0" cellpadding="3" cellspacing="0">
+                <tr>
+                    <td width="130"><label><strong>Full 
Name:</strong></label></td>
+                    <td><%if ("".equals(identityRegHandler.getFullName())) { %>
+                        <input type="text" name="fullName"
+                               value="<%=identityRegHandler.getFullName()%>"/>
+                        <br><font 
color="#FF0000"><%=identityRegHandler.getErrorMessage("fullName")%>
+                    </font>
+                        <% } else { %>
+                        <%=identityRegHandler.getFullName()%>
+                        <% } %>
+                    </td>
+                </tr>
+                <tr>
+                    <td 
width="130"><label><strong>E-mail:</strong></label></td>
+                    <td><%if ("".equals(identityRegHandler.getEmailId())) { %>
+                        <input type="text" name="emailId"
+                               value="<%=identityRegHandler.getEmailId()%>"/>
+                        <br><font 
color="#FF0000"><%=identityRegHandler.getErrorMessage("emailId")%>
+                    </font>
+                        <% } else { %>
+                        <%=identityRegHandler.getEmailId()%>
+                        <% } %>
+                    </td>
+                </tr>
+                <tr>
+                    <td width="130"><label><strong>User Name:<font 
color="#FF0000">*</font></strong></label>
+                    </td>
+                    <td><%if ("".equals(identityRegHandler.getUserName())) { %>
+                        <input type="text" name="userName"
+                               value="<%=identityRegHandler.getUserName()%>"/>
+                        <br><font color="#FF0000"><%=identityRegHandler
+                            .getErrorMessage("userName")%>
+                    </font>
+                        <% } else { %>
+                        <%=identityRegHandler.getUserName()%>
+                        <% } %>
+                    </td>
+                </tr>
+                <tr>
+                    <td width="130"><label><strong>Identifier:<font 
color="#FF0000">*</font></strong></label>
+                    </td>
+                    <td><%=identityRegHandler.getIdentifier()%></td>
+                </tr>
+                <tr>
+                    <td>&nbsp;</td>
+                    <td><input type="submit" value="Register"/> <input 
type="button" value="Cancel"
+                            onclick="document.location = '<%= bounceback %>';">
+                    </td>
+                </tr>
+                <tr>
+                    <td>&nbsp;</td>
+                    <td align="center"></td>
+                </tr>
+            </table>
+        </form>
         <div>
             If you need to login using a password at some point of time, 
please use the
             <a 
href="reset_password.jsp?firstcall=true&bounceback=<%=URLEncoder.encode(bounceback,"UTF-8")%>">Retrieve
-            Forgotten Password</a> feature to have one generated and sent to 
your e-mail ID.
+                Forgotten Password</a> feature to have one generated and sent 
to your e-mail ID.
         </div>
         <br>
         <% }
         } else { %>
-            <div class="mashup_title">Self Registration Disabled</div>
-            <div>&nbsp; Self-registration disabled. Please contact 
administrator to register yourself.</div>
+        <div class="mashup_title">Self Registration Disabled</div>
+        <div>&nbsp; Self-registration disabled. Please contact administrator 
to register yourself.
+        </div>
         <% } %>
         <br>
     </div>

Modified: trunk/mashup/java/modules/www/signin.jsp
==============================================================================
--- trunk/mashup/java/modules/www/signin.jsp    (original)
+++ trunk/mashup/java/modules/www/signin.jsp    Sat May  3 01:05:24 2008
@@ -183,12 +183,8 @@
                 <tr>
                     <th width="50%">Sign-in to <%= 
bundle.getString("main.title")%>
                     </th>
-                    <th width="25%">Use InfoCard to enter <%= bundle
-                            .getString("main.title")%>
-                    </th>
-                    <th width="25%">Use OpenID to enter <%= bundle
-                            .getString("main.title")%>
-                    </th>
+                    <th width="25%">Use InfoCard to Sign-in</th>
+                    <th width="25%">Use OpenID to Sign-in</th>
                 </tr>
                 <tr>
                     <td height="175">
@@ -261,16 +257,16 @@
                         Sign In using your personal or managed InfoCard.
                         <br/>
                         <br/>
-                        <a href="http://wso2.org/projects/solutions/identity";
-                           target="_blank"><img 
src="images/powered_identity.gif"
-                                                border="0"></a>
                     </td>
                     <td height="175" valign="top">
                         <form name="openidsignin" id="openidsignin" 
method="post" action="openidsubmit.jsp">
+                            <img src="images/openid-logo.jpg" border="0"><br/>
                             Enter Your OpenID Url:<input type="text" 
name="openIdUrl"/>
                             <input type="hidden" name="calledfrom" 
value="signin"/>
                             <input type="submit" name="submit" value="Login" />
                         </form>
+                        <br/>
+                        <br/>
                     </td>
                 </tr>
                 <tr>
@@ -278,6 +274,11 @@
                         <a 
href="reset_password.jsp?firstcall=true&bounceback=<%=URLEncoder.encode(bounceback,"UTF-8")%>">Forgot
                             Password?</a>
                     </td>
+                    <td colspan="2">
+                        <a href="http://wso2.org/projects/solutions/identity"; 
target="_blank"><img src="images/powered_identity.gif"
+                                                border="0"></a>
+
+                    </td>
                 </tr>
             </table>
             <br/>

_______________________________________________
Mashup-dev mailing list
[email protected]
http://www.wso2.org/cgi-bin/mailman/listinfo/mashup-dev

Reply via email to