001: /*
002: * JOnAS: Java(TM) Open Application Server
003: * Copyright (C) 1999 Bull S.A.
004: * Contact: jonas-team@objectweb.org
005: *
006: * This library is free software; you can redistribute it and/or
007: * modify it under the terms of the GNU Lesser General Public
008: * License as published by the Free Software Foundation; either
009: * version 2.1 of the License, or any later version.
010: *
011: * This library is distributed in the hope that it will be useful,
012: * but WITHOUT ANY WARRANTY; without even the implied warranty of
013: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
014: * Lesser General Public License for more details.
015: *
016: * You should have received a copy of the GNU Lesser General Public
017: * License along with this library; if not, write to the Free Software
018: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
019: * USA
020: *
021: * Initial developer(s): Michel-Ange ANTON
022: * --------------------------------------------------------------------------
023: * $Id: ApplyConfirmMemoryRealmAction.java 9680 2006-10-06 12:08:33Z danesa $
024: * --------------------------------------------------------------------------
025: */
026:
027: package org.objectweb.jonas.webapp.jonasadmin.security;
028:
029: import java.io.IOException;
030:
031: import javax.management.ObjectName;
032: import javax.servlet.ServletException;
033: import javax.servlet.http.HttpServletRequest;
034: import javax.servlet.http.HttpServletResponse;
035:
036: import org.apache.struts.action.ActionForm;
037: import org.apache.struts.action.ActionForward;
038: import org.apache.struts.action.ActionMapping;
039: import org.objectweb.jonas.jmx.JonasManagementRepr;
040: import org.objectweb.jonas.jmx.JonasObjectName;
041: import org.objectweb.jonas.webapp.jonasadmin.WhereAreYou;
042:
043: /**
044: *
045: */
046:
047: public class ApplyConfirmMemoryRealmAction extends
048: BaseMemoryRealmAction {
049:
050: // --------------------------------------------------------- Public Methods
051:
052: /**
053: */
054: public ActionForward executeAction(ActionMapping p_Mapping,
055: ActionForm p_Form, HttpServletRequest p_Request,
056: HttpServletResponse p_Response) throws IOException,
057: ServletException {
058:
059: String sForward = null;
060:
061: WhereAreYou oWhere = (WhereAreYou) p_Request.getSession()
062: .getAttribute(WhereAreYou.SESSION_NAME);
063: String serverName = oWhere.getCurrentJonasServerName();
064:
065: // Realm Form used
066: MemoryRealmForm oRealmForm = getForm(p_Mapping, p_Request);
067: // Form used
068: ItemsMemoryRealmForm oForm = (ItemsMemoryRealmForm) m_Session
069: .getAttribute("itemsMemoryRealmForm");
070:
071: // Actions
072: try {
073: String[] asParam = new String[1];
074: String[] asSignature = { "java.lang.String" };
075: ObjectName onRealm = JonasObjectName
076: .securityMemoryFactory(oRealmForm.getResource());
077:
078: // User
079: if (oForm.getType().equals("user") == true) {
080: // Remove
081: if (oForm.getAction().equals("remove") == true) {
082: for (int i = 0; i < oForm.getSelectedItems().length; i++) {
083: asParam[0] = oForm.getSelectedItems()[i];
084: JonasManagementRepr.invoke(onRealm,
085: "removeUser", asParam, asSignature,
086: serverName);
087: }
088: }
089: sForward = "ActionEditMemoryRealmUsers";
090: }
091: // Role
092: else if (oForm.getType().equals("role") == true) {
093: // Remove
094: if (oForm.getAction().equals("remove") == true) {
095: for (int i = 0; i < oForm.getSelectedItems().length; i++) {
096: asParam[0] = oForm.getSelectedItems()[i];
097: JonasManagementRepr.invoke(onRealm,
098: "removeRole", asParam, asSignature,
099: serverName);
100: }
101: }
102: sForward = "ActionEditMemoryRealmRoles";
103: }
104: // Group
105: else if (oForm.getType().equals("group") == true) {
106: // Remove
107: if (oForm.getAction().equals("remove") == true) {
108: for (int i = 0; i < oForm.getSelectedItems().length; i++) {
109: asParam[0] = oForm.getSelectedItems()[i];
110: JonasManagementRepr.invoke(onRealm,
111: "removeGroup", asParam, asSignature,
112: serverName);
113: }
114: }
115: sForward = "ActionEditMemoryRealmGroups";
116: }
117: // Release select list of the session
118: m_Session.removeAttribute("itemsMemoryRealmForm");
119: } catch (Throwable t) {
120: addGlobalError(t);
121: saveErrors(p_Request, m_Errors);
122: return (p_Mapping.findForward("Global Error"));
123: }
124:
125: // Forward to the jsp.
126: return (p_Mapping.findForward(sForward));
127: }
128:
129: // --------------------------------------------------------- Protected Methods
130:
131: }
|