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: EditDatasourceRealmAction.java 4408 2004-03-19 14:31:54Z sauthieg $
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.JonasObjectName;
039: import org.objectweb.jonas.webapp.jonasadmin.JonasBaseAction;
040: import org.objectweb.jonas.webapp.jonasadmin.WhereAreYou;
041:
042: /**
043: * @author Michel-Ange ANTON
044: */
045: public class EditDatasourceRealmAction extends JonasBaseAction {
046:
047: // --------------------------------------------------------- Public Methods
048:
049: public ActionForward executeAction(ActionMapping p_Mapping,
050: ActionForm p_Form, HttpServletRequest p_Request,
051: HttpServletResponse p_Response) throws IOException,
052: ServletException {
053:
054: String sResource = p_Request.getParameter("resource");
055: String sAction = p_Request.getParameter("action");
056:
057: // Form used
058: DatasourceRealmForm oForm = null;
059: if (sResource != null) {
060: // Editing a new realm
061: oForm = new DatasourceRealmForm();
062: m_Session.setAttribute("datasourceRealmForm", oForm);
063: oForm.setResource(sResource);
064: oForm.setAction("apply");
065: } else {
066: // Creating
067: if ((sAction != null) && (sAction.equals("create") == true)) {
068: oForm = new DatasourceRealmForm();
069: m_Session.setAttribute("datasourceRealmForm", oForm);
070: oForm.setAction("create");
071: }
072: // Editing a realm in session (Show after apply or save)
073: else {
074: oForm = (DatasourceRealmForm) m_Session
075: .getAttribute("datasourceRealmForm");
076: oForm.reset(p_Mapping, p_Request);
077: }
078: }
079:
080: // Populate
081: try {
082: // Populate only if action is 'apply'
083: if (oForm.getAction().equals("apply") == true) {
084: ObjectName oObjectName = JonasObjectName
085: .securityDatasourceFactory(oForm.getResource());
086: oForm.setDsName(getStringAttribute(oObjectName,
087: "DsName"));
088: oForm.setName(getStringAttribute(oObjectName, "Name"));
089: oForm.setRoleTable(getStringAttribute(oObjectName,
090: "RoleTable"));
091: oForm.setRoleTableRolenameCol(getStringAttribute(
092: oObjectName, "RoleTableRolenameCol"));
093: oForm.setRoleTableUsernameCol(getStringAttribute(
094: oObjectName, "RoleTableUsernameCol"));
095: oForm.setUserTable(getStringAttribute(oObjectName,
096: "UserTable"));
097: oForm.setUserTablePasswordCol(getStringAttribute(
098: oObjectName, "UserTablePasswordCol"));
099: oForm.setUserTableUsernameCol(getStringAttribute(
100: oObjectName, "UserTableUsernameCol"));
101: oForm.setAlgorithm(getStringAttribute(oObjectName,
102: "Algorithm"));
103:
104: // Force the node selected in tree
105: m_WhereAreYou.selectNameNode(
106: getTreeBranchName(DEPTH_SERVER)
107: + WhereAreYou.NODE_SEPARATOR
108: + "security"
109: + WhereAreYou.NODE_SEPARATOR
110: + "factory.datasource"
111: + WhereAreYou.NODE_SEPARATOR
112: + oForm.getName(), true);
113: }
114: } catch (Throwable t) {
115: addGlobalError(t);
116: saveErrors(p_Request, m_Errors);
117: return (p_Mapping.findForward("Global Error"));
118: }
119: // Forward to the jsp.
120: return (p_Mapping.findForward("Datasource Realm"));
121: }
122:
123: // --------------------------------------------------------- Protected Methods
124:
125: }
|