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: ApplyMemoryRealmAction.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 ApplyMemoryRealmAction 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 = (MemoryRealmForm) p_Form;
061:
062: // Populate MBean
063: try {
064: // Create new
065: if (oForm.getAction().equals("create") == true) {
066: oForm.setResource(oForm.getName());
067: // Add resource
068: ObjectName oObjectName = JonasObjectName
069: .securityService();
070: String[] asParam = { oForm.getName() };
071: String[] asSignature = { "java.lang.String" };
072: JonasManagementRepr.invoke(oObjectName,
073: "addJResourceMemory", asParam, asSignature,
074: serverName);
075: // refresh tree
076: refreshTree(p_Request);
077: // Force the node selected in tree
078: m_WhereAreYou.selectNameNode(
079: getTreeBranchName(DEPTH_SERVER)
080: + WhereAreYou.NODE_SEPARATOR
081: + "security"
082: + WhereAreYou.NODE_SEPARATOR
083: + "factory.memory"
084: + WhereAreYou.NODE_SEPARATOR
085: + oForm.getName(), true);
086: // To modify the form
087: oForm.setAction("apply");
088: }
089: // Save
090: if (oForm.isSave()) {
091: ObjectName onRealm = JonasObjectName
092: .securityMemoryFactory(oForm.getResource());
093: JonasManagementRepr.invoke(onRealm, "saveConfig", null,
094: null, serverName);
095: }
096: } catch (Throwable t) {
097: addGlobalError(t);
098: saveErrors(p_Request, m_Errors);
099: return (p_Mapping.findForward("Global Error"));
100: }
101: // Forward to the jsp.
102: return (p_Mapping.findForward("Memory Realm"));
103: }
104:
105: // --------------------------------------------------------- Protected Methods
106:
107: }
|