Author: channa
Date: Fri Jan 18 01:17:39 2008
New Revision: 12468

Log:

Preventing deletion of user profiles required by server.

Added:
   
trunk/mashup/java/modules/core/src/org/wso2/mashup/webapp/userprofile/UserInfo.java
Modified:
   
trunk/mashup/java/modules/core/src/org/wso2/mashup/webapp/userprofile/ManageUsers.java
   trunk/mashup/java/modules/www/manage_users.jsp

Modified: 
trunk/mashup/java/modules/core/src/org/wso2/mashup/webapp/userprofile/ManageUsers.java
==============================================================================
--- 
trunk/mashup/java/modules/core/src/org/wso2/mashup/webapp/userprofile/ManageUsers.java
      (original)
+++ 
trunk/mashup/java/modules/core/src/org/wso2/mashup/webapp/userprofile/ManageUsers.java
      Fri Jan 18 01:17:39 2008
@@ -18,6 +18,8 @@
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 import org.wso2.mashup.MashupConstants;
+import org.wso2.mashup.webapp.utils.RegistryUtils;
+import org.wso2.registry.RegistryConstants;
 import org.wso2.registry.secure.SecureRegistry;
 import org.wso2.usermanager.Realm;
 import org.wso2.usermanager.UserManagerException;
@@ -51,13 +53,11 @@
             for (int userCount = 0; userCount < allUsers.length; userCount++) {
                 String fullName = (String) 
userStoreAdmin.getUserProperties(allUsers[userCount])
                         .get(MashupConstants.FULL_NAME);
-
                 // If the full name is available, use it, otherwise just show 
the user name.
-                if (fullName != null) {
-                    userMap.put(allUsers[userCount], fullName);
-                } else {
-                    userMap.put(allUsers[userCount], allUsers[userCount]);
-                }
+                fullName = fullName != null ? fullName : allUsers[userCount];
+                UserInfo userInfo = new UserInfo(fullName, 
isUserActive(registry,
+                               allUsers[userCount]), isUserDeletable(realm, 
allUsers[userCount]));
+                userMap.put(allUsers[userCount], userInfo);
             }
         } catch (UserManagerException e) {
             log.error("User manager error retrieving user list", e);
@@ -100,10 +100,13 @@
                 (SecureRegistry) 
request.getSession().getAttribute(MashupConstants.USER_REGISTRY);
         Realm realm = registry.getUserRealm();
         try {
-            UserStoreAdmin userStoreAdmin = realm.getUserStoreAdmin();
-            userStoreAdmin.deleteUser(userName);
-            deleteUserResources(registry, userName);
-            deletionSuccess = true;
+            // Check deletable - API level check for calls not validated via 
UI.
+            if (isUserDeletable(realm, userName)) {
+                UserStoreAdmin userStoreAdmin = realm.getUserStoreAdmin();
+                userStoreAdmin.deleteUser(userName);
+                deleteUserResources(registry, userName);
+                deletionSuccess = true;
+            }
         } catch (UserManagerException e) {
             log.error("Error deleting user", e);
         }
@@ -208,4 +211,24 @@
         }
         return success;
     }
+
+    /**
+     * Contains the logic which determines if a given user can be deleted.
+     * @param userName Name of user to be deleted.
+     * @return true if the user can be deleted without any adverse effects to 
the system.
+     */
+    private static boolean isUserDeletable(Realm realm, String userName) 
throws UserManagerException {
+        boolean canBeDeleted = true;
+
+        if (userName.equals(RegistryConstants.ANONYMOUS_USER) ||
+                userName.equals(RegistryConstants.SYSTEM_USER)) {
+            canBeDeleted = false;
+        }
+
+        if (RegistryUtils.isUserPrimary(realm, userName)) {
+            canBeDeleted = false;
+        }
+
+        return canBeDeleted;
+    }
 }

Added: 
trunk/mashup/java/modules/core/src/org/wso2/mashup/webapp/userprofile/UserInfo.java
==============================================================================
--- (empty file)
+++ 
trunk/mashup/java/modules/core/src/org/wso2/mashup/webapp/userprofile/UserInfo.java
 Fri Jan 18 01:17:39 2008
@@ -0,0 +1,43 @@
+/*
+ * Copyright (c) 2006, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.wso2.mashup.webapp.userprofile;
+
+/**
+ * Value object used to populate manage user page contents.
+ */
+public class UserInfo {
+    private boolean userActive;
+    private boolean userDeletable;
+    private String fullName;
+
+    public UserInfo(String userFullName, boolean userActive, boolean 
userDeleteable) {
+        this.userActive = userActive;
+        this.userDeletable = userDeleteable;
+        this.fullName = userFullName;
+    }
+
+    public boolean isUserActive() {
+        return userActive;
+    }
+
+    public boolean isUserDeletable() {
+        return userDeletable;
+    }
+
+    public String getFullName() {
+        return fullName;
+    }
+}

Modified: trunk/mashup/java/modules/www/manage_users.jsp
==============================================================================
--- trunk/mashup/java/modules/www/manage_users.jsp      (original)
+++ trunk/mashup/java/modules/www/manage_users.jsp      Fri Jan 18 01:17:39 2008
@@ -21,27 +21,27 @@
 <%@ page import="com.sun.syndication.feed.synd.SyndFeed" %>
 <%@ page import="com.sun.syndication.feed.synd.SyndFeedImpl" %>
 <%@ page import="com.sun.syndication.io.SyndFeedOutput" %>
-<%@ page import="org.wso2.mashup.MashupConstants" %>
+<%@ page import="org.apache.axis2.context.ConfigurationContext" %>
+<%@ page import="org.wso2.mashup.MashupFault" %>
 <%@ page import="org.wso2.mashup.utils.QueryResult" %>
 <%@ page import="org.wso2.mashup.utils.QueryResults" %>
 <%@ page import="org.wso2.mashup.webapp.identity.InfoCardHandler" %>
 <%@ page import="org.wso2.mashup.webapp.identity.RegistrationBean" %>
 <%@ page import="org.wso2.mashup.webapp.userprofile.ManageUsers" %>
-<%@ page import="org.wso2.mashup.webapp.userprofile.User" %>
+<%@ page import="org.wso2.mashup.webapp.userprofile.UserInfo" %>
 <%@ page import="org.wso2.mashup.webapp.userprofile.UserQuery" %>
 <%@ page import="org.wso2.mashup.webapp.utils.QueryParamUtils" %>
-<%@ page import="org.wso2.mashup.webapp.utils.RegistryUtils" %>
 <%@ page import="org.wso2.registry.Comment" %>
-<%@ page import="org.wso2.registry.Registry" %>
-<%@ page import="org.wso2.registry.RegistryConstants" %>
 <%@ page import="org.wso2.registry.RegistryException" %>
 <%@ page import="org.wso2.registry.Resource" %>
 <%@ page import="org.wso2.registry.Tag" %>
-<%@ page import="org.wso2.registry.jdbc.JDBCRegistry" %>
-<%@ page import="org.wso2.registry.secure.SecureRegistry" %>
-<%@ page import="org.wso2.usermanager.Realm" %>
 <%@ page import="org.wso2.usermanager.UserManagerException" %>
+<%@ page import="org.wso2.usermanager.UserStoreAdmin" %>
+<%@ page import="org.wso2.utils.ServerConfiguration" %>
+<%@ page import="org.wso2.wsas.ServerManager" %>
 <%@ page import="javax.servlet.ServletContext" %>
+<%@ page import="java.io.BufferedReader" %>
+<%@ page import="java.io.FileReader" %>
 <%@ page import="java.net.URL" %>
 <%@ page import="java.net.URLDecoder" %>
 <%@ page import="java.util.ArrayList" %>
@@ -90,13 +90,15 @@
           </tr>
           <%  for (Iterator userNames = users.keySet().iterator(); 
userNames.hasNext();) {
                    String userName =  (String) userNames.next();
-                            String fullName = (String) users.get(userName);
+                            UserInfo userInfo = (UserInfo) users.get(userName);
                         %>
           <tr class="results">
                  <td><img src="images/user.gif" align="absmiddle"></td>
-            <td><%= fullName %></td>
+            <td><%= userInfo.getFullName() %></td>
             <td align="center"><a 
href="add_user.jsp?username=<%=userName%>&editmode=true&firstcall=true&bounceback=<%=URLEncoder.encode(thisPage,"UTF-8")%>"><img
 src="images/edit.gif" alt="Edit user" title="Edit user" border="0"></a></td>
-            <td align="center"><a href="delete_user.jsp?username=<%= 
URLEncoder.encode(userName,"UTF-8") %>&fullname=<%= 
URLEncoder.encode(fullName,"UTF-8") 
%>&firstcall=true&bounceback=<%=URLEncoder.encode(thisPage,"UTF-8")%>"><img 
src="images/delete.gif" alt="Delete user" title="Delete user" 
border="0"></a></td>
+            <% if (userInfo.isUserDeletable()) { %>
+            <td align="center"><a href="delete_user.jsp?username=<%= 
URLEncoder.encode(userName,"UTF-8") %>&fullname=<%= 
URLEncoder.encode(userInfo.getFullName(),"UTF-8") 
%>&firstcall=true&bounceback=<%=URLEncoder.encode(thisPage,"UTF-8")%>"><img 
src="images/delete.gif" alt="Delete user" title="Delete user" 
border="0"></a></td>
+            <% } %>
           </tr>
           <% }%>
       </table>

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

Reply via email to