Author: channa
Date: Wed Mar  5 01:35:57 2008
New Revision: 14518

Log:

Added global check for previously registered infocards in self registration and 
card association (MASHUP-695). Added footer to self reg message.

Modified:
   trunk/mashup/java/modules/core/conf/UI.properties
   trunk/mashup/java/modules/core/conf/web_root.xml
   trunk/mashup/java/modules/core/src/org/wso2/mashup/MashupConstants.java
   trunk/mashup/java/modules/core/src/org/wso2/mashup/transport/MainServlet.java
   
trunk/mashup/java/modules/core/src/org/wso2/mashup/webapp/identity/InfoCardHandler.java
   
trunk/mashup/java/modules/core/src/org/wso2/mashup/webapp/identity/InfoCardRegistrationBean.java
   trunk/mashup/java/modules/www/register_self_infocard.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   Wed Mar  5 01:35:57 2008
@@ -4,4 +4,6 @@
 register.admin.title=Welcome to the WSO2 Mashup Server!
 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.
\ No newline at end of file
+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

Modified: trunk/mashup/java/modules/core/conf/web_root.xml
==============================================================================
--- trunk/mashup/java/modules/core/conf/web_root.xml    (original)
+++ trunk/mashup/java/modules/core/conf/web_root.xml    Wed Mar  5 01:35:57 2008
@@ -105,6 +105,10 @@
             <param-name>email_body</param-name>
             <param-value>To complete your self-registation process, please 
click on the link below to verify your e-mail ID.</param-value>
         </init-param>
+        <init-param>
+            <param-name>email_footer</param-name>
+            <param-value>Thanks, The Mashup Server Team</param-value>
+        </init-param>
     </servlet>
 
     <servlet>

Modified: 
trunk/mashup/java/modules/core/src/org/wso2/mashup/MashupConstants.java
==============================================================================
--- trunk/mashup/java/modules/core/src/org/wso2/mashup/MashupConstants.java     
(original)
+++ trunk/mashup/java/modules/core/src/org/wso2/mashup/MashupConstants.java     
Wed Mar  5 01:35:57 2008
@@ -57,6 +57,7 @@
     public static final String EMAIL_FROM_ADDRESS = "email_from_address";
     public static final String EMAIL_SUBJECT = "email_subject";
     public static final String EMAIL_BODY = "email_body";
+    public static final String EMAIL_FOOTER = "email_footer";
 
     public static final String USER_REGISTRY = "user_registry";
     public static final String MASHUP_MEDIA_TYPE = "wso2_mashup";

Modified: 
trunk/mashup/java/modules/core/src/org/wso2/mashup/transport/MainServlet.java
==============================================================================
--- 
trunk/mashup/java/modules/core/src/org/wso2/mashup/transport/MainServlet.java   
    (original)
+++ 
trunk/mashup/java/modules/core/src/org/wso2/mashup/transport/MainServlet.java   
    Wed Mar  5 01:35:57 2008
@@ -23,7 +23,6 @@
 import org.wso2.registry.users.UserStoreException;
 import org.wso2.registry.users.verifier.EmailVerifier;
 import org.wso2.registry.users.verifier.EmailVerifierConfig;
-import org.wso2.usermanager.UserManagerException;
 
 import org.wso2.utils.ServerException;
 
@@ -68,10 +67,13 @@
         
verifierConfig.setRegistrationServiceEPR(servletConfig.getInitParameter(
                 MashupConstants.REG_VALIDATION_URL));
         verifierConfig.setFromAddress(fromEmail);
+        verifierConfig.setReplyTo(fromEmail);
         verifierConfig.setSubject(servletConfig.getInitParameter(
                 MashupConstants.EMAIL_SUBJECT));
         verifierConfig.setEmailBody(servletConfig.getInitParameter(
                 MashupConstants.EMAIL_BODY));
+        verifierConfig.setEmailFooter(servletConfig.getInitParameter(
+                MashupConstants.EMAIL_FOOTER));
 
         // Add the e-mail parameters to the servlet context.
         servletContext.setAttribute(MashupConstants.EMAIL_RELAY_HOST, 
relayHost);

Modified: 
trunk/mashup/java/modules/core/src/org/wso2/mashup/webapp/identity/InfoCardHandler.java
==============================================================================
--- 
trunk/mashup/java/modules/core/src/org/wso2/mashup/webapp/identity/InfoCardHandler.java
     (original)
+++ 
trunk/mashup/java/modules/core/src/org/wso2/mashup/webapp/identity/InfoCardHandler.java
     Wed Mar  5 01:35:57 2008
@@ -29,6 +29,7 @@
 import org.wso2.registry.users.UserRealm;
 import org.wso2.registry.users.UserStoreAdmin;
 import org.wso2.registry.users.UserStoreException;
+import org.wso2.registry.users.UserStoreReader;
 import org.wso2.solutions.identity.IdentityConstants;
 import org.wso2.solutions.identity.relyingparty.TokenVerifierConstants;
 import org.wso2.usermanager.Realm;
@@ -88,7 +89,7 @@
      *
      * @param request  Servlet request object, contains attributes provided by 
the info card.
      */
-    public static boolean associateCardWithUser(HttpServletRequest request) {
+    public static boolean associateCardWithUser(HttpServletRequest request) 
throws MashupFault {
         boolean cardAdded = false;
         try {
             // Get the available user properties.
@@ -105,7 +106,7 @@
                 String ppid = (String) 
request.getAttribute(IdentityConstants.CLAIM_PPID);
 
                 // Add only if this ppid has not been associated with a user.
-                if (!userProps.containsValue(ppid)) {
+                if (!InfoCardHandler.isInfoCardRegistered(request, ppid)) {
                     int regCardCount = 0;
 
                     // There will be a count if keys have been registered, so 
append.
@@ -150,4 +151,32 @@
         }
         return cardIds;
     }
+
+    /**
+     * Checks if a given ppid is registered for an existing user.
+     * @param request Servlet request instance.
+     * @param ppid PPID to be checked.
+     * @return true id the ppid has already been registered.
+     * @throws MashupFault if an error is encoutered getting user details.
+     */
+    public static boolean isInfoCardRegistered(HttpServletRequest request, 
String ppid) throws
+            MashupFault {
+        boolean isRegistered = false;
+        SecureRegistry registry = (SecureRegistry) 
request.getSession().getAttribute(
+                MashupConstants.USER_REGISTRY);
+        UserRealm realm = registry.getUserRealm();
+        try {
+            UserStoreReader storeReader = realm.getUserStoreReader();
+
+            // Null key checks across all users, so someone is registered if a 
name is returned.
+            String[] userNames = 
storeReader.getUserNamesWithPropertyValue(null, ppid);
+            if (userNames != null && userNames.length > 0) {
+                isRegistered = true;
+            }
+        } catch (UserStoreException e) {
+            log.error("Error retreiving user information", e);
+            throw new MashupFault("Error retreiving user information", e);
+        }
+        return isRegistered;
+    }
 }

Modified: 
trunk/mashup/java/modules/core/src/org/wso2/mashup/webapp/identity/InfoCardRegistrationBean.java
==============================================================================
--- 
trunk/mashup/java/modules/core/src/org/wso2/mashup/webapp/identity/InfoCardRegistrationBean.java
    (original)
+++ 
trunk/mashup/java/modules/core/src/org/wso2/mashup/webapp/identity/InfoCardRegistrationBean.java
    Wed Mar  5 01:35:57 2008
@@ -20,12 +20,10 @@
 import org.wso2.mashup.MashupConstants;
 import org.wso2.mashup.webapp.userprofile.ManageUsers;
 import org.wso2.registry.users.UserStoreException;
+import org.wso2.registry.users.verifier.EmailVerifier;
 import org.wso2.solutions.identity.IdentityConstants;
 import org.wso2.solutions.identity.relyingparty.TokenVerifierConstants;
 
-import org.wso2.usermanager.UserManagerException;
-import org.wso2.usermanager.verification.email.EmailVerifier;
-
 import javax.servlet.http.HttpServletRequest;
 import javax.servlet.http.HttpSession;
 import java.util.HashMap;
@@ -41,7 +39,7 @@
     // Constants for storing values in the servlet context.
     private final String FULL_NAME = "fullname";
     private final String EMAIL_ID = "emailid";
-    private final String PPID = "ppid";    
+    private final String PPID = "ppid";
 
     // Get registration values submitted using form.
     private String userName;
@@ -84,6 +82,10 @@
         return emailId;
     }
 
+    public String getPpid() {
+        return ppid;
+    }
+
     /**
      * Initialize bean values.
      */
@@ -114,7 +116,7 @@
         try {
             verifier.requestUserVerification(userName, emailId, password, 
userAttributes);
             success = true;
-        } catch (UserManagerException e) {
+        } catch (UserStoreException e) {
             log.error("Error perrforming self registration", e);
         }
 
@@ -134,6 +136,7 @@
 
     /**
      * Validates the information in mandatory fields.
+     *
      * @param request Servlet request object.
      * @return true if validation is successful.
      */
@@ -167,6 +170,7 @@
 
     /**
      * 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.
      */

Modified: trunk/mashup/java/modules/www/register_self_infocard.jsp
==============================================================================
--- trunk/mashup/java/modules/www/register_self_infocard.jsp    (original)
+++ trunk/mashup/java/modules/www/register_self_infocard.jsp    Wed Mar  5 
01:35:57 2008
@@ -20,6 +20,7 @@
 <%@ page import="org.wso2.registry.Registry" %>
 <%@ page import="java.net.URLDecoder" %>
 <%@ page import="java.util.ResourceBundle" %>
+<%@ page import="org.wso2.mashup.webapp.identity.InfoCardHandler" %>
 <%
     ResourceBundle bundle = ResourceBundle.getBundle("UI");
     Registry registry = RegistryUtils.getRegistry(request);
@@ -37,10 +38,17 @@
     <jsp:setProperty name="infoCardRegHandler" property="*"/>
 </jsp:useBean>
 <%
-        boolean infocardOk = false;
-        if ("Log in".equals(infoCardPresented)) {
-            infocardOk = infoCardRegHandler.setInfoCardDetails(request);
-        } else {
+   boolean infocardDetailsRetrieved = false;
+   boolean infocardAlreadyUsed = false;
+    if ("Log in".equals(infoCardPresented)) {
+        infocardDetailsRetrieved = 
infoCardRegHandler.setInfoCardDetails(request);
+
+        // If the details were successfully retrieved, check for duplication.
+        if (infocardDetailsRetrieved) {
+            infocardAlreadyUsed = InfoCardHandler.isInfoCardRegistered(request,
+                                                                       
infoCardRegHandler.getPpid());
+        }
+    } else {
         if (infoCardRegHandler.isInputValid(request)) {
             if (infoCardRegHandler.register()) {
                 response.sendRedirect(
@@ -50,7 +58,7 @@
                         "registration_result.jsp?success=false&bounceback=" + 
bounceback);
             }
         }
-        }
+    }
 %>
 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd";>
 <html>
@@ -69,10 +77,11 @@
        <div id="search"></div>
     <div id="content" style="height:400px; ">
         <% if (RegistrationBean.isSelfRegistrationEnabled()) {
-            if ("Log in".equals(infoCardPresented) && !infocardOk) { %>
+            if ("Log in".equals(infoCardPresented) && 
(!infocardDetailsRetrieved || infocardAlreadyUsed)) { %>
         <div class="mashup_title">Infocard Error</div>
-        <div>&nbsp; Infocard submission failed. Please register using another 
card or by entering
-            data manually <a 
href="register_self.jsp?firstcall=true&bounceback=<%=URLEncoder.encode(thisPage,"UTF-8")%>">here</a>.
+        <div>&nbsp;<%= infocardAlreadyUsed ? 
bundle.getString("register.self.infocardreused") :
+                bundle.getString("register.self.infocarderror") %>
+            <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>

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

Reply via email to