Author: channa
Date: Wed Jan 16 02:11:03 2008
New Revision: 12340

Log:

Fixing admin provisioning, making full name non-mandatory, adding e-mail, using 
an attribute to differentiate auto created and explicitly created admin.

Modified:
   trunk/mashup/java/modules/core/src/org/wso2/mashup/MashupConstants.java
   
trunk/mashup/java/modules/core/src/org/wso2/mashup/webapp/identity/RegistrationBean.java
   
trunk/mashup/java/modules/core/src/org/wso2/mashup/webapp/utils/RegistryUtils.java
   trunk/mashup/java/modules/www/index.jsp
   trunk/mashup/java/modules/www/register_admin.jsp

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 Jan 16 02:11:03 2008
@@ -70,6 +70,7 @@
     public static final String LAST_NAME = "lastname";
     public static final String EMAIL_ID = "email";
     public static final String ENABLED = "enabled";
+    public static final String PRIMARY = "primary";
 
     public static final String INFOCARD_PPID = "ppid";
     public static final String INFOCARD_COUNT = "cardcount";
@@ -99,4 +100,6 @@
     public static final String INITIAL_SETUP_COMPLETE = 
"initial_setup_complete";
 
     public static final String FAULTY_MASHUP = "faulty_mashup";
+
+    public static final String LOCALHOST = "localhost";
 }

Modified: 
trunk/mashup/java/modules/core/src/org/wso2/mashup/webapp/identity/RegistrationBean.java
==============================================================================
--- 
trunk/mashup/java/modules/core/src/org/wso2/mashup/webapp/identity/RegistrationBean.java
    (original)
+++ 
trunk/mashup/java/modules/core/src/org/wso2/mashup/webapp/identity/RegistrationBean.java
    Wed Jan 16 02:11:03 2008
@@ -28,6 +28,7 @@
 import org.wso2.usermanager.Realm;
 import org.wso2.usermanager.UserManagerException;
 import org.wso2.usermanager.UserStoreAdmin;
+import org.wso2.usermanager.UserStoreReader;
 import org.wso2.usermanager.verification.email.EmailVerifier;
 import org.wso2.wsas.persistence.PersistenceManager;
 
@@ -154,16 +155,15 @@
             UserStoreAdmin userStoreAdmin = realm.getUserStoreAdmin();
             userStoreAdmin.addUser(userName, password);
 
+            String adminName = "".equals(fullName.trim()) ? userName : 
fullName;
+            String adminEmail = "".equals(emailId.trim()) ? "none" : emailId;
+
             // Create the admin user profile.
             RegistryUtils.createUser(registry, realm, userName,
-                                     fullName, "none", "System Administrator");
-            // Assign system user the 'admin' role.
+                                     adminName, adminEmail, "System 
Administrator");
+            // Assign system user the 'admin' role and make primary.
             userStoreAdmin.addUserToRole(userName, 
RegistryConstants.ADMIN_ROLE);
-
-            // Delete redundant 'admin' user in registry, if it exists.
-            if (userStoreAdmin.isExistingUser(RegistryConstants.ADMIN_USER)) {
-                userStoreAdmin.deleteUser(RegistryConstants.ADMIN_USER);
-            }
+            makeUserPrimary(realm, userName);
             MashupUtils.setInitialSetupComplete(true);
         } catch (UserManagerException e) {
             log.error("Error creating admin user in user manager", e);
@@ -175,6 +175,27 @@
     }
 
     /**
+     * Gets the profile for a given user and makes him/her primary.
+     *
+     * @param realm  Registry realm.
+     * @param userName User to be made primary.
+     */
+    private void makeUserPrimary(Realm realm, String userName) throws 
UserManagerException {
+        try {
+            // Get the user's properties.
+            UserStoreAdmin userStoreAdmin = realm.getUserStoreAdmin();
+            Map userProps = userStoreAdmin.getUserProperties(userName);
+
+            // Set the 'primary' property.
+            userProps.put(MashupConstants.PRIMARY, String.valueOf(true));
+            userStoreAdmin.setUserProperties(userName, userProps);
+        } catch (UserManagerException e) {
+            log.error("Error getting user properties", e);
+            throw new UserManagerException("Could not make user primary", e);
+        }
+    }
+
+    /**
      * Return any added error messages.
      *
      * @param key Key to identify error.
@@ -282,10 +303,13 @@
             valid = false;
         }
 
-        if (fullName.equals("")) {
-            errors.put("fullName", "Full name cannot be empty.");
-            fullName = "";
-            valid = false;
+        // Full name is not mandatory for creating the admin profile.
+        if (!adminCreation) {
+            if (fullName.equals("")) {
+                errors.put("fullName", "Full name cannot be empty.");
+                fullName = "";
+                valid = false;
+            }
         }
 
         if (password.equals("")) {
@@ -306,7 +330,7 @@
             valid = false;
         }
 
-        // E-mail ID is not required for creating the admin profile.
+        // E-mail ID is not mandatory for creating the admin profile.
         if (!adminCreation) {
             if (emailId.equals("")) {
                 errors.put("emailId", "E-mail ID cannot be empty.");

Modified: 
trunk/mashup/java/modules/core/src/org/wso2/mashup/webapp/utils/RegistryUtils.java
==============================================================================
--- 
trunk/mashup/java/modules/core/src/org/wso2/mashup/webapp/utils/RegistryUtils.java
  (original)
+++ 
trunk/mashup/java/modules/core/src/org/wso2/mashup/webapp/utils/RegistryUtils.java
  Wed Jan 16 02:11:03 2008
@@ -34,6 +34,7 @@
 import org.wso2.usermanager.UserManagerConstants;
 import org.wso2.usermanager.UserManagerException;
 import org.wso2.usermanager.UserStoreAdmin;
+import org.wso2.usermanager.UserStoreReader;
 import org.wso2.utils.ServerConfiguration;
 import org.wso2.wsas.ServerManager;
 
@@ -556,4 +557,20 @@
         userProfile.setContent(user.serializeUserProfile().getBytes());
         registry.put(profilePath, userProfile);
     }
+
+    /**
+     * Gets the profile for a given user and returns if he ir she is the 
primary user.
+     *
+     * @param realm Registry realm.
+     * @param userName User name to be checked for status.
+     * @return true if user profile is enabled.
+     */
+    public static boolean isUserPrimary(Realm realm, String userName) throws 
UserManagerException {
+        // Get the user's properties.
+        UserStoreReader userStoreReader = realm.getUserStoreReader();
+        Map userProps = userStoreReader.getUserProperties(userName);
+
+        // Get 'primary' property.
+        return userProps.containsKey(MashupConstants.PRIMARY);
+    }
 }

Modified: trunk/mashup/java/modules/www/index.jsp
==============================================================================
--- trunk/mashup/java/modules/www/index.jsp     (original)
+++ trunk/mashup/java/modules/www/index.jsp     Wed Jan 16 02:11:03 2008
@@ -56,7 +56,8 @@
 <%@ page import="java.util.List" %>
 <%@ page import="java.util.Map" %>
 <%
-    if (!MashupUtils.isInitialSetupComplete()) {
+    if (!MashupUtils.isInitialSetupComplete() && 
MashupConstants.LOCALHOST.equalsIgnoreCase(
+            request.getLocalName())) {
         response.sendRedirect("register_admin.jsp?firstcall=true");
     }    
 

Modified: trunk/mashup/java/modules/www/register_admin.jsp
==============================================================================
--- trunk/mashup/java/modules/www/register_admin.jsp    (original)
+++ trunk/mashup/java/modules/www/register_admin.jsp    Wed Jan 16 02:11:03 2008
@@ -57,7 +57,7 @@
     <div id="content" style="height:400px; ">
     <div class="mashup_title">Welcome to the WSO2 Mashup Server!</div>
         <p>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 priveleges, with 
full control over all the resources
+            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.</p>
@@ -71,17 +71,15 @@
                                     <br><font 
color="#FF0000"><%=registrationHandler.getErrorMessage("userName")%></font>
                                 </td>
                             </tr>
-                            <!--
                             <tr>
-                                <td width="130"><label><strong>Email:<font 
color="#FF0000"></font></strong></label></td>
+                                <td 
width="130"><label><strong>Email:</strong></label></td>
                                 <td><input type="text" name="emailId"
                                            
value="<%=registrationHandler.getEmailId()%>"/>
                                     <br><font 
color="#FF0000"><%=registrationHandler.getErrorMessage("email")%></font>
                                 </td>
                             </tr>
-                            -->
                             <tr>
-                                <td width="130"><label><strong>Full Name:<font 
color="#FF0000"></font></strong></label></td>
+                                <td width="130"><label><strong>Full 
Name:</strong></label></td>
                                 <td><input type="text" name="fullName"
                                            
value="<%=registrationHandler.getFullName()%>"/>
                                     <br><font 
color="#FF0000"><%=registrationHandler.getErrorMessage("fullName")%></font>

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

Reply via email to