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.Hashtable;
   22   
   23   import javax.portlet.ActionRequest;
   24   import javax.portlet.ActionResponse;
   25   import javax.portlet.PortletConfig;
   26   import javax.portlet.PortletContext;
   27   import javax.portlet.PortletException;
   28   import javax.portlet.RenderRequest;
   29   import javax.portlet.RenderResponse;
   30   import javax.portlet.WindowState;
   31   
   32   import org.apache.geronimo.console.util.SERealmGroupHelper;
   33   import org.apache.geronimo.console.util.SERealmUserHelper;
   34   
   35   public class SEGroupsPortlet extends AbstractSecurityManagerPortlet {
   36   
   37       protected void doView(RenderRequest renderRequest,
   38               RenderResponse renderResponse) throws PortletException, IOException {
   39           if (WindowState.MINIMIZED.equals(renderRequest.getWindowState())) {
   40               return;
   41           }
   42   
   43           String errorMessage = renderRequest.getParameter("errorMessage");
   44   
   45           if (errorMessage != null) {
   46               renderRequest.setAttribute("errorMessage", errorMessage);
   47               errorView.include(renderRequest, renderResponse);
   48           } else if (!SERealmGroupHelper.isDefaultLoginModuleAvaiable()) {
   49               renderRequest.setAttribute("errorMessage", getLocalizedString(renderRequest, "consolebase.errorMsg24"));
   50               errorView.include(renderRequest, renderResponse);
   51           } else {
   52               String currAction = renderRequest.getParameter("currAction");
   53               String message = renderRequest.getParameter("message");
   54               renderRequest.setAttribute("message", message);
   55   
   56               try {
   57                   if ("new".equals(currAction)) {
   58                       renderRequest.setAttribute("users", SERealmUserHelper
   59                               .getUsers());
   60                       addMaximizedView.include(renderRequest, renderResponse);
   61                   } else if ("edit".equals(currAction)) {
   62                       String group = renderRequest.getParameter("group");
   63                       renderRequest.setAttribute("group", group);
   64                       renderRequest.setAttribute("users", SERealmUserHelper
   65                               .getUsers());
   66                       addMaximizedView.include(renderRequest, renderResponse);
   67                   } else {
   68                       String[] groups = SERealmGroupHelper.getGroups();
   69                       Hashtable groupsInfo = new Hashtable();
   70                       for (int i = 0; i < groups.length; i++) {
   71                           String currentGroup = groups[i];
   72                           groupsInfo.put(currentGroup, SERealmGroupHelper
   73                                   .getUsers(currentGroup));
   74                       }
   75                       renderRequest.setAttribute("groupsInfo", groupsInfo);
   76   
   77                       if (WindowState.NORMAL.equals(renderRequest
   78                               .getWindowState())) {
   79                           normalView.include(renderRequest, renderResponse);
   80                       } else {
   81                           maximizedView.include(renderRequest, renderResponse);
   82                       }
   83                   }
   84               } catch (Exception e) {
   85                   errorMessage = e.getMessage();
   86                   renderRequest.setAttribute("errorMessage", errorMessage);
   87                   errorView.include(renderRequest, renderResponse);
   88               }
   89           }
   90       }
   91   
   92       public void init(PortletConfig portletConfig) throws PortletException {
   93           super.init(portletConfig);
   94           PortletContext pc = portletConfig.getPortletContext();
   95           normalView = pc
   96                   .getRequestDispatcher("/WEB-INF/view/securityrealmmanager/se/groups/normal.jsp");
   97           addNormalView = pc
   98                   .getRequestDispatcher("/WEB-INF/view/securityrealmmanager/se/groups/addnormal.jsp");
   99           maximizedView = pc
  100                   .getRequestDispatcher("/WEB-INF/view/securityrealmmanager/se/groups/maximized.jsp");
  101           addMaximizedView = pc
  102                   .getRequestDispatcher("/WEB-INF/view/securityrealmmanager/se/groups/addmaximized.jsp");
  103           helpView = pc
  104                   .getRequestDispatcher("/WEB-INF/view/securityrealmmanager/se/groups/help.jsp");
  105           errorView = pc
  106                   .getRequestDispatcher("/WEB-INF/view/securityrealmmanager/se/groups/error.jsp");
  107       }
  108   
  109       public void processAction(ActionRequest actionRequest,
  110               ActionResponse actionResponse) throws PortletException, IOException {
  111           String action = actionRequest.getParameter("action").trim();
  112           String cancel = actionRequest.getParameter("cancel");
  113           String currAction = "";
  114           if (cancel != null) {
  115               action = "";
  116           }
  117           String group = actionRequest.getParameter("group");
  118           String[] users = actionRequest.getParameterValues("users");
  119   
  120           try {
  121               if ("delete".equals(action)) {
  122                   SERealmGroupHelper.deleteGroup(group);
  123               } else if ("update".equals(action)) {
  124                   SERealmGroupHelper.updateGroup(group, users);
  125               } else if ("add".equals(action)) {
  126                   try {
  127                       SERealmGroupHelper.addGroup(group, users);
  128                   } catch (Exception e) {
  129                       addErrorMessage(actionRequest, getLocalizedString(actionRequest, "consolebase.errorMsg07"), e.getMessage());
  130                   }
  131               } else if ("new".equals(action)) {
  132                   currAction = "new";
  133               } else if ("edit".equals(action)) {
  134                   currAction = "edit";
  135               }
  136               actionResponse.setRenderParameter("currAction", currAction);
  137               if (group != null) {
  138                   actionResponse.setRenderParameter("group", group);
  139               }
  140           } catch (Exception e) {
  141               addErrorMessage(actionRequest, getLocalizedString(actionRequest, "consolebase.errorMsg06"), e.getMessage());
  142           }
  143       }
  144   }

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