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: ApplyDatasourceRealmAction.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: public class ApplyDatasourceRealmAction extends BaseMemoryRealmAction {
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: // Current server
054: WhereAreYou oWhere = (WhereAreYou) p_Request.getSession()
055: .getAttribute(WhereAreYou.SESSION_NAME);
056: String serverName = oWhere.getCurrentJonasServerName();
057:
058: // Form used
059: DatasourceRealmForm oForm = (DatasourceRealmForm) p_Form;
060:
061: // Populate MBean
062: try {
063: // Create new
064: if (oForm.getAction().equals("create") == true) {
065: oForm.setResource(oForm.getName());
066: // Add resource
067: ObjectName oObjectName = JonasObjectName
068: .securityService();
069: String[] asParam = { oForm.getName(),
070: oForm.getDsName(), oForm.getUserTable(),
071: oForm.getUserTableUsernameCol(),
072: oForm.getUserTablePasswordCol(),
073: oForm.getRoleTable(),
074: oForm.getRoleTableRolenameCol(),
075: oForm.getRoleTableUsernameCol(),
076: oForm.getAlgorithm() };
077: String[] asSignature = { "java.lang.String",
078: "java.lang.String", "java.lang.String",
079: "java.lang.String", "java.lang.String",
080: "java.lang.String", "java.lang.String",
081: "java.lang.String", "java.lang.String" };
082: JonasManagementRepr.invoke(oObjectName,
083: "addJResourceDS", asParam, asSignature,
084: serverName);
085: // refresh tree
086: refreshTree(p_Request);
087: // Force the node selected in tree
088: m_WhereAreYou.selectNameNode(
089: getTreeBranchName(DEPTH_SERVER)
090: + WhereAreYou.NODE_SEPARATOR
091: + "security"
092: + WhereAreYou.NODE_SEPARATOR
093: + "factory.datasource"
094: + WhereAreYou.NODE_SEPARATOR
095: + oForm.getName(), true);
096: // To see the form
097: oForm.setAction("apply");
098: } else {
099: // Modify existing
100: ObjectName oObjectName = JonasObjectName
101: .securityDatasourceFactory(oForm.getResource());
102: setStringAttribute(oObjectName, "DsName", oForm
103: .getDsName());
104: setStringAttribute(oObjectName, "RoleTable", oForm
105: .getRoleTable());
106: setStringAttribute(oObjectName, "RoleTableRolenameCol",
107: oForm.getRoleTableRolenameCol());
108: setStringAttribute(oObjectName, "RoleTableUsernameCol",
109: oForm.getRoleTableUsernameCol());
110: setStringAttribute(oObjectName, "UserTable", oForm
111: .getUserTable());
112: setStringAttribute(oObjectName, "UserTablePasswordCol",
113: oForm.getUserTablePasswordCol());
114: setStringAttribute(oObjectName, "UserTableUsernameCol",
115: oForm.getUserTableUsernameCol());
116: setStringAttribute(oObjectName, "Algorithm", oForm
117: .getAlgorithm());
118: }
119: // Save
120: if (oForm.isSave()) {
121: ObjectName onRealm = JonasObjectName
122: .securityDatasourceFactory(oForm.getResource());
123: JonasManagementRepr.invoke(onRealm, "saveConfig", null,
124: null, serverName);
125: }
126: } catch (Throwable t) {
127: addGlobalError(t);
128: saveErrors(p_Request, m_Errors);
129: return (p_Mapping.findForward("Global Error"));
130: }
131: // Forward to the jsp.
132: return (p_Mapping.findForward("Datasource Realm"));
133: }
134:
135: // --------------------------------------------------------- Protected Methods
136:
137: }
|