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: */package org.apache.geronimo.console.securitymanager;
017:
018: import java.io.IOException;
019: import java.util.Hashtable;
020:
021: import javax.portlet.ActionRequest;
022: import javax.portlet.ActionResponse;
023: import javax.portlet.PortletConfig;
024: import javax.portlet.PortletContext;
025: import javax.portlet.PortletException;
026: import javax.portlet.RenderRequest;
027: import javax.portlet.RenderResponse;
028: import javax.portlet.WindowState;
029:
030: import org.apache.geronimo.console.util.SERealmGroupHelper;
031: import org.apache.geronimo.console.util.SERealmUserHelper;
032:
033: public class SEGroupsPortlet extends AbstractSecurityManagerPortlet {
034:
035: protected void doView(RenderRequest renderRequest,
036: RenderResponse renderResponse) throws PortletException,
037: IOException {
038: if (WindowState.MINIMIZED
039: .equals(renderRequest.getWindowState())) {
040: return;
041: }
042:
043: String errorMessage = renderRequest
044: .getParameter("errorMessage");
045:
046: if (errorMessage != null) {
047: renderRequest.setAttribute("errorMessage", errorMessage);
048: errorView.include(renderRequest, renderResponse);
049: } else {
050: String currAction = renderRequest
051: .getParameter("currAction");
052: String message = renderRequest.getParameter("message");
053: renderRequest.setAttribute("message", message);
054:
055: try {
056: if ("new".equals(currAction)) {
057: renderRequest.setAttribute("users",
058: SERealmUserHelper.getUsers());
059: addMaximizedView.include(renderRequest,
060: renderResponse);
061: } else if ("edit".equals(currAction)) {
062: String group = renderRequest.getParameter("group");
063: renderRequest.setAttribute("group", group);
064: renderRequest.setAttribute("users",
065: SERealmUserHelper.getUsers());
066: addMaximizedView.include(renderRequest,
067: renderResponse);
068: } else {
069: String[] groups = SERealmGroupHelper.getGroups();
070: Hashtable groupsInfo = new Hashtable();
071: for (int i = 0; i < groups.length; i++) {
072: String currentGroup = groups[i];
073: groupsInfo.put(currentGroup, SERealmGroupHelper
074: .getUsers(currentGroup));
075: }
076: renderRequest
077: .setAttribute("groupsInfo", groupsInfo);
078:
079: if (WindowState.NORMAL.equals(renderRequest
080: .getWindowState())) {
081: normalView.include(renderRequest,
082: renderResponse);
083: } else {
084: maximizedView.include(renderRequest,
085: renderResponse);
086: }
087: }
088: } catch (Exception e) {
089: errorMessage = e.getMessage();
090: renderRequest
091: .setAttribute("errorMessage", errorMessage);
092: errorView.include(renderRequest, renderResponse);
093: }
094: }
095: }
096:
097: public void init(PortletConfig portletConfig)
098: throws PortletException {
099: super .init(portletConfig);
100: PortletContext pc = portletConfig.getPortletContext();
101: normalView = pc
102: .getRequestDispatcher("/WEB-INF/view/securityrealmmanager/se/groups/normal.jsp");
103: addNormalView = pc
104: .getRequestDispatcher("/WEB-INF/view/securityrealmmanager/se/groups/addnormal.jsp");
105: maximizedView = pc
106: .getRequestDispatcher("/WEB-INF/view/securityrealmmanager/se/groups/maximized.jsp");
107: addMaximizedView = pc
108: .getRequestDispatcher("/WEB-INF/view/securityrealmmanager/se/groups/addmaximized.jsp");
109: helpView = pc
110: .getRequestDispatcher("/WEB-INF/view/securityrealmmanager/se/groups/help.jsp");
111: errorView = pc
112: .getRequestDispatcher("/WEB-INF/view/securityrealmmanager/se/groups/error.jsp");
113: }
114:
115: public void processAction(ActionRequest actionRequest,
116: ActionResponse actionResponse) throws PortletException,
117: IOException {
118: String action = actionRequest.getParameter("action").trim();
119: String cancel = actionRequest.getParameter("cancel");
120: String currAction = "";
121: if (cancel != null) {
122: action = "";
123: }
124: String group = actionRequest.getParameter("group");
125: String[] users = actionRequest.getParameterValues("users");
126:
127: try {
128: if ("delete".equals(action)) {
129: SERealmGroupHelper.deleteGroup(group);
130: } else if ("update".equals(action)) {
131: SERealmGroupHelper.updateGroup(group, users);
132: } else if ("add".equals(action)) {
133: try {
134: SERealmGroupHelper.addGroup(group, users);
135: } catch (Exception e) {
136: actionResponse.setRenderParameter("message",
137: "ERROR: Error in SEGroupsPortlet while adding group "
138: + group + ". Cause:"
139: + e.getMessage());
140: }
141: } else if ("new".equals(action)) {
142: currAction = "new";
143: } else if ("edit".equals(action)) {
144: currAction = "edit";
145: }
146: actionResponse.setRenderParameter("currAction", currAction);
147: if (group != null) {
148: actionResponse.setRenderParameter("group", group);
149: }
150: } catch (Exception e) {
151: actionResponse.setRenderParameter("message",
152: "Error encountered in SEGroupsPortlet. Cause: "
153: + e.getMessage());
154: }
155: }
156: }
|