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: * --------------------------------------------------------------------------
022: * $Id: EditMemoryRealmAction.java 9680 2006-10-06 12:08:33Z danesa $
023: * --------------------------------------------------------------------------
024: */
025:
026: package org.objectweb.jonas.webapp.jonasadmin.security;
027:
028: import java.io.IOException;
029:
030: import javax.management.ObjectName;
031: import javax.servlet.ServletException;
032: import javax.servlet.http.HttpServletRequest;
033: import javax.servlet.http.HttpServletResponse;
034:
035: import org.apache.struts.action.ActionForm;
036: import org.apache.struts.action.ActionForward;
037: import org.apache.struts.action.ActionMapping;
038: import org.objectweb.jonas.jmx.JonasManagementRepr;
039: import org.objectweb.jonas.jmx.JonasObjectName;
040: import org.objectweb.jonas.webapp.jonasadmin.WhereAreYou;
041:
042: /**
043: * @author Michel-Ange ANTON
044: */
045:
046: public class EditMemoryRealmAction extends BaseMemoryRealmAction {
047:
048: // --------------------------------------------------------- Public Methods
049:
050: public ActionForward executeAction(ActionMapping p_Mapping,
051: ActionForm p_Form, HttpServletRequest p_Request,
052: HttpServletResponse p_Response) throws IOException,
053: ServletException {
054:
055: WhereAreYou oWhere = (WhereAreYou) p_Request.getSession()
056: .getAttribute(WhereAreYou.SESSION_NAME);
057: String serverName = oWhere.getCurrentJonasServerName();
058:
059: // Form used
060: MemoryRealmForm oForm = getForm(p_Mapping, p_Request);
061: String sAction = p_Request.getParameter("action");
062: // Creating
063: if ((sAction != null) && (sAction.equals("create") == true)) {
064: oForm = new MemoryRealmForm();
065: oForm.reset(p_Mapping, p_Request);
066: m_Session.setAttribute("memoryRealmForm", oForm);
067: oForm.setAction("create");
068: }
069:
070: // Populate
071: try {
072: // Populate only if action is 'apply'
073: if (oForm.getAction().equals("apply") == true) {
074: ObjectName oObjectName = JonasObjectName
075: .securityMemoryFactory(oForm.getResource());
076: oForm.setName(getStringAttribute(oObjectName, "Name"));
077: oForm.setGroups((String[]) JonasManagementRepr.invoke(
078: oObjectName, "listGroups", null, null,
079: serverName));
080: oForm.setRoles((String[]) JonasManagementRepr.invoke(
081: oObjectName, "listRoles", null, null,
082: serverName));
083:
084: oForm.setResource(oForm.getName());
085: // Force the node selected in tree
086: m_WhereAreYou.selectNameNode(
087: getTreeBranchName(DEPTH_SERVER)
088: + WhereAreYou.NODE_SEPARATOR
089: + "security"
090: + WhereAreYou.NODE_SEPARATOR
091: + "factory.memory"
092: + WhereAreYou.NODE_SEPARATOR
093: + oForm.getName(), true);
094: }
095: } catch (Throwable t) {
096: addGlobalError(t);
097: saveErrors(p_Request, m_Errors);
098: return (p_Mapping.findForward("Global Error"));
099: }
100: // Forward to the jsp.
101: return (p_Mapping.findForward("Memory Realm"));
102: }
103:
104: // --------------------------------------------------------- Protected Methods
105:
106: }
|