001 /** 002 * Licensed to the Apache Software Foundation (ASF) under one or more 003 * contributor license agreements. See the NOTICE file distributed with 004 * this work for additional information regarding copyright ownership. 005 * The ASF licenses this file to You under the Apache License, Version 2.0 006 * (the "License"); you may not use this file except in compliance with 007 * the License. You may obtain a copy of the License at 008 * 009 * http://www.apache.org/licenses/LICENSE-2.0 010 * 011 * Unless required by applicable law or agreed to in writing, software 012 * distributed under the License is distributed on an "AS IS" BASIS, 013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 014 * See the License for the specific language governing permissions and 015 * limitations under the License. 016 */ 017 018 package org.apache.geronimo.console.securitymanager; 019 020 import java.io.IOException; 021 import java.util.Hashtable; 022 023 import javax.portlet.ActionRequest; 024 import javax.portlet.ActionResponse; 025 import javax.portlet.PortletConfig; 026 import javax.portlet.PortletContext; 027 import javax.portlet.PortletException; 028 import javax.portlet.RenderRequest; 029 import javax.portlet.RenderResponse; 030 import javax.portlet.WindowState; 031 032 import org.apache.geronimo.console.util.SERealmGroupHelper; 033 import org.apache.geronimo.console.util.SERealmUserHelper; 034 035 public class SEGroupsPortlet extends AbstractSecurityManagerPortlet { 036 037 protected void doView(RenderRequest renderRequest, 038 RenderResponse renderResponse) throws PortletException, IOException { 039 if (WindowState.MINIMIZED.equals(renderRequest.getWindowState())) { 040 return; 041 } 042 043 String errorMessage = renderRequest.getParameter("errorMessage"); 044 045 if (errorMessage != null) { 046 renderRequest.setAttribute("errorMessage", errorMessage); 047 errorView.include(renderRequest, renderResponse); 048 } else { 049 String currAction = renderRequest.getParameter("currAction"); 050 String message = renderRequest.getParameter("message"); 051 renderRequest.setAttribute("message", message); 052 053 try { 054 if ("new".equals(currAction)) { 055 renderRequest.setAttribute("users", SERealmUserHelper 056 .getUsers()); 057 addMaximizedView.include(renderRequest, renderResponse); 058 } else if ("edit".equals(currAction)) { 059 String group = renderRequest.getParameter("group"); 060 renderRequest.setAttribute("group", group); 061 renderRequest.setAttribute("users", SERealmUserHelper 062 .getUsers()); 063 addMaximizedView.include(renderRequest, renderResponse); 064 } else { 065 String[] groups = SERealmGroupHelper.getGroups(); 066 Hashtable groupsInfo = new Hashtable(); 067 for (int i = 0; i < groups.length; i++) { 068 String currentGroup = groups[i]; 069 groupsInfo.put(currentGroup, SERealmGroupHelper 070 .getUsers(currentGroup)); 071 } 072 renderRequest.setAttribute("groupsInfo", groupsInfo); 073 074 if (WindowState.NORMAL.equals(renderRequest 075 .getWindowState())) { 076 normalView.include(renderRequest, renderResponse); 077 } else { 078 maximizedView.include(renderRequest, renderResponse); 079 } 080 } 081 } catch (Exception e) { 082 errorMessage = e.getMessage(); 083 renderRequest.setAttribute("errorMessage", errorMessage); 084 errorView.include(renderRequest, renderResponse); 085 } 086 } 087 } 088 089 public void init(PortletConfig portletConfig) throws PortletException { 090 super.init(portletConfig); 091 PortletContext pc = portletConfig.getPortletContext(); 092 normalView = pc 093 .getRequestDispatcher("/WEB-INF/view/securityrealmmanager/se/groups/normal.jsp"); 094 addNormalView = pc 095 .getRequestDispatcher("/WEB-INF/view/securityrealmmanager/se/groups/addnormal.jsp"); 096 maximizedView = pc 097 .getRequestDispatcher("/WEB-INF/view/securityrealmmanager/se/groups/maximized.jsp"); 098 addMaximizedView = pc 099 .getRequestDispatcher("/WEB-INF/view/securityrealmmanager/se/groups/addmaximized.jsp"); 100 helpView = pc 101 .getRequestDispatcher("/WEB-INF/view/securityrealmmanager/se/groups/help.jsp"); 102 errorView = pc 103 .getRequestDispatcher("/WEB-INF/view/securityrealmmanager/se/groups/error.jsp"); 104 } 105 106 public void processAction(ActionRequest actionRequest, 107 ActionResponse actionResponse) throws PortletException, IOException { 108 String action = actionRequest.getParameter("action").trim(); 109 String cancel = actionRequest.getParameter("cancel"); 110 String currAction = ""; 111 if (cancel != null) { 112 action = ""; 113 } 114 String group = actionRequest.getParameter("group"); 115 String[] users = actionRequest.getParameterValues("users"); 116 117 try { 118 if ("delete".equals(action)) { 119 SERealmGroupHelper.deleteGroup(group); 120 } else if ("update".equals(action)) { 121 SERealmGroupHelper.updateGroup(group, users); 122 } else if ("add".equals(action)) { 123 try { 124 SERealmGroupHelper.addGroup(group, users); 125 } catch (Exception e) { 126 actionResponse.setRenderParameter("message", 127 "ERROR: Error in SEGroupsPortlet while adding group "+group+". Cause:"+e.getMessage()); 128 } 129 } else if ("new".equals(action)) { 130 currAction = "new"; 131 } else if ("edit".equals(action)) { 132 currAction = "edit"; 133 } 134 actionResponse.setRenderParameter("currAction", currAction); 135 if (group != null) { 136 actionResponse.setRenderParameter("group", group); 137 } 138 } catch (Exception e) { 139 actionResponse.setRenderParameter("message", 140 "Error encountered in SEGroupsPortlet. Cause: " 141 + e.getMessage()); 142 } 143 } 144 }