Home » geronimo-2.2-source-release » org.apache.geronimo.console.securitymanager » [javadoc | source]

    1   /**
    2    *  Licensed to the Apache Software Foundation (ASF) under one or more
    3    *  contributor license agreements.  See the NOTICE file distributed with
    4    *  this work for additional information regarding copyright ownership.
    5    *  The ASF licenses this file to You under the Apache License, Version 2.0
    6    *  (the "License"); you may not use this file except in compliance with
    7    *  the License.  You may obtain a copy of the License at
    8    *
    9    *     http://www.apache.org/licenses/LICENSE-2.0
   10    *
   11    *  Unless required by applicable law or agreed to in writing, software
   12    *  distributed under the License is distributed on an "AS IS" BASIS,
   13    *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   14    *  See the License for the specific language governing permissions and
   15    *  limitations under the License.
   16    */
   17   
   18   package org.apache.geronimo.console.securitymanager;
   19   
   20   import java.io.IOException;
   21   import java.util.Collection;
   22   import java.util.Hashtable;
   23   
   24   import javax.portlet.ActionRequest;
   25   import javax.portlet.ActionResponse;
   26   import javax.portlet.PortletConfig;
   27   import javax.portlet.PortletContext;
   28   import javax.portlet.PortletException;
   29   import javax.portlet.RenderRequest;
   30   import javax.portlet.RenderResponse;
   31   import javax.portlet.WindowState;
   32   
   33   import org.apache.geronimo.console.util.SERealmGroupHelper;
   34   import org.apache.geronimo.console.util.SERealmUserHelper;
   35   
   36   /**
   37    * @version $Rev: 816623 $ $Date: 2009-09-18 06:14:04 -0700 (Fri, 18 Sep 2009) $
   38    */
   39   public class SEUsersPortlet extends AbstractSecurityManagerPortlet {
   40   
   41       protected void doView(RenderRequest renderRequest,
   42               RenderResponse renderResponse) throws PortletException, IOException {
   43           if (WindowState.MINIMIZED.equals(renderRequest.getWindowState())) {
   44               return;
   45           }
   46   
   47           String errorMessage = renderRequest.getParameter("errorMessage");
   48   
   49           if (errorMessage != null) {
   50               renderRequest.setAttribute("errorMessage", errorMessage);
   51               errorView.include(renderRequest, renderResponse);
   52           } else if (!SERealmGroupHelper.isDefaultLoginModuleAvaiable()) {
   53               renderRequest.setAttribute("errorMessage", getLocalizedString(renderRequest, "consolebase.errorMsg24"));
   54               errorView.include(renderRequest, renderResponse);
   55           } else {
   56               try {
   57                   String[] users = SERealmUserHelper.getUsers();
   58   
   59                   Hashtable userInfo = new Hashtable();
   60                   for (int i = 0; i < users.length; i++) {
   61                       String currentUser = users[i];
   62                       // We really shouldn't be attaching everyone's password as portlet data!!!
   63                       // And the current Portlet doesn't use it, so why send it....
   64                       // userInfo.put(currentUser, SERealmUserHelper.getPassword(currentUser.toString()));
   65                       userInfo.put(currentUser, currentUser.toString());
   66                   }
   67   
   68                   String currAction = renderRequest.getParameter("currAction");
   69                   renderRequest.setAttribute("message", renderRequest.getParameter("message"));
   70   
   71                   if ("new".equals(currAction)) {
   72                       String[] groups = SERealmGroupHelper.getGroups();
   73                       Hashtable groupsInfo = new Hashtable();
   74                       for (int i = 0; i < groups.length; i++) {
   75                           String currentGroup = groups[i];
   76                           groupsInfo.put(currentGroup, SERealmGroupHelper.getUsers(currentGroup));
   77                       }
   78                       renderRequest.setAttribute("groupsInfo", groupsInfo);
   79                       addMaximizedView.include(renderRequest, renderResponse);
   80                   } else if ("edit".equals(currAction)) {
   81                       String user = renderRequest.getParameter("user");
   82                       renderRequest.setAttribute("userID", user);
   83                       // We really shouldn't be sending the user's password as portlet data!!!
   84                       // And the current Portlet doesn't use it, so why send it....
   85                       //renderRequest.setAttribute("password", SERealmUserHelper.getPassword(user));
   86                       // Current Portlet doesn't use groupsInfo, so why send it 
   87                       //renderRequest.setAttribute("groupsInfo", groupsInfo);
   88                       addMaximizedView.include(renderRequest, renderResponse);
   89                   } else {
   90                       if (WindowState.NORMAL.equals(renderRequest.getWindowState())) {
   91                           renderRequest.setAttribute("userInfo", userInfo);
   92                           normalView.include(renderRequest, renderResponse);
   93                       } else {
   94                           renderRequest.setAttribute("userInfo", userInfo);
   95                           maximizedView.include(renderRequest, renderResponse);
   96                       }
   97                   }
   98               } catch (Exception e) {
   99                   errorMessage = e.getMessage();
  100                   renderRequest.setAttribute("errorMessage", errorMessage);
  101                   errorView.include(renderRequest, renderResponse);
  102               }
  103           }
  104       }
  105   
  106       public void init(PortletConfig portletConfig) throws PortletException {
  107           super.init(portletConfig);
  108           PortletContext pc = portletConfig.getPortletContext();
  109           normalView = pc
  110                   .getRequestDispatcher("/WEB-INF/view/securityrealmmanager/se/users/normal.jsp");
  111           addNormalView = pc
  112                   .getRequestDispatcher("/WEB-INF/view/securityrealmmanager/se/users/addnormal.jsp");
  113           maximizedView = pc
  114                   .getRequestDispatcher("/WEB-INF/view/securityrealmmanager/se/users/maximized.jsp");
  115           addMaximizedView = pc
  116                   .getRequestDispatcher("/WEB-INF/view/securityrealmmanager/se/users/addmaximized.jsp");
  117           helpView = pc
  118                   .getRequestDispatcher("/WEB-INF/view/securityrealmmanager/se/users/help.jsp");
  119           errorView = pc
  120                   .getRequestDispatcher("/WEB-INF/view/securityrealmmanager/se/users/error.jsp");
  121       }
  122   
  123       public void processAction(ActionRequest actionRequest,
  124               ActionResponse actionResponse) throws PortletException, IOException {
  125           String action = actionRequest.getParameter("action").trim();
  126           String cancel = actionRequest.getParameter("cancel");
  127           String currAction = "";
  128           if (cancel != null) {
  129               action = "";
  130           }
  131           String user = actionRequest.getParameter("userId");
  132           String password = actionRequest.getParameter("password");
  133           String group = actionRequest.getParameter("group");
  134   
  135           try {
  136               if ("delete".equals(action)) {
  137                   try {
  138                       String[] groups = SERealmGroupHelper.getGroups();
  139                       for (int i = 0; i < groups.length; i++) {
  140                           String currentGroup = groups[i];
  141                           if (SERealmGroupHelper.isGroupMember(currentGroup, user)) {
  142                               Collection list = SERealmGroupHelper.getUsers(currentGroup);
  143                               list.remove(user);
  144                               String[] groupUsers = (String[]) list.toArray(new String[0]);
  145                               SERealmGroupHelper.updateGroup(currentGroup, groupUsers);
  146                           }
  147                       }
  148                       SERealmUserHelper.deleteUser(user);
  149                   } catch (Exception e) {
  150                       addErrorMessage(actionRequest, getLocalizedString(actionRequest, "consolebase.errorMsg04"), e.getMessage());
  151                   }
  152               } else if ("update".equals(action)) {
  153                   if(password != null && !password.equals("")) {
  154                       // Update the password only when it is not blank.
  155                       SERealmUserHelper.updateUser(user, password);
  156                   }
  157               } else if ("add".equals(action)) {
  158                   try {
  159                       SERealmUserHelper.addUser(user, password);
  160                       if ((group != null) && (!group.equals(""))) {
  161                           Collection list = SERealmGroupHelper.getUsers(group);
  162                           list.add(user);
  163                           String[] groupUsers = (String[]) list.toArray(new String[0]);
  164                           SERealmGroupHelper.updateGroup(group, groupUsers);
  165                       }
  166                   } catch (Exception e) {
  167                       addErrorMessage(actionRequest, getLocalizedString(actionRequest, "consolebase.errorMsg05"), e.getMessage());
  168                   }
  169               } else if ("new".equals(action)) {
  170                   currAction = "new";
  171               } else if ("edit".equals(action)) {
  172                   currAction = "edit";
  173               }
  174               actionResponse.setRenderParameter("currAction", currAction);
  175               if (user != null) {
  176                   actionResponse.setRenderParameter("user", user);
  177               }
  178           } catch (Exception e) {
  179               addErrorMessage(actionRequest, getLocalizedString(actionRequest, "consolebase.errorMsg06"), e.getMessage());
  180           }
  181       }
  182   
  183   }

Home » geronimo-2.2-source-release » org.apache.geronimo.console.securitymanager » [javadoc | source]