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: ApplyUserAction.java 9680 2006-10-06 12:08:33Z danesa $
023: * --------------------------------------------------------------------------
024: */package org.objectweb.jonas.webapp.jonasadmin.joramplatform;
025:
026: import java.io.IOException;
027: import java.util.Set;
028:
029: import javax.management.InstanceNotFoundException;
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.JoramObjectName;
040: import org.objectweb.jonas.webapp.jonasadmin.deploy.BaseDeployAction;
041:
042: /**
043: * @author Adriana Danes
044: * Creation of new destinations
045: */
046:
047: public class ApplyUserAction extends BaseDeployAction {
048:
049: // --------------------------------------------------------- Public Methods
050:
051: public ActionForward executeAction(ActionMapping p_Mapping,
052: ActionForm p_Form, HttpServletRequest p_Request,
053: HttpServletResponse p_Response) throws IOException,
054: ServletException {
055:
056: // Current JOnAS server
057: String jonasServerName = m_WhereAreYou
058: .getCurrentJonasServerName();
059:
060: // Form used
061: JoramUserForm oForm = (JoramUserForm) p_Form;
062: String idString = (String) m_Session.getAttribute("currentId");
063: String localIdString = (String) m_Session
064: .getAttribute("localId");
065: boolean isLocalServer;
066: if (localIdString.equals(idString)) {
067: isLocalServer = true;
068: } else {
069: isLocalServer = false;
070: }
071:
072: try {
073: ObjectName oObjectName;
074: Set adapterOns = JonasManagementRepr.queryNames(
075: JoramObjectName.joramAdapter(), jonasServerName);
076: if (adapterOns.isEmpty()) {
077: throw new InstanceNotFoundException();
078: }
079: ObjectName joramAdapterON = (ObjectName) adapterOns
080: .iterator().next();
081: if (JonasManagementRepr.isRegistered(joramAdapterON,
082: jonasServerName)) {
083: oObjectName = joramAdapterON;
084: } else {
085: oObjectName = JoramObjectName.joramAdmin();
086: }
087: if (isLocalServer) {
088: Object[] asParam = { oForm.getName(),
089: oForm.getPassword() };
090: String[] asSignature = { "java.lang.String",
091: "java.lang.String" };
092: JonasManagementRepr.invoke(oObjectName, "createUser",
093: asParam, asSignature, jonasServerName);
094: } else {
095: Integer idInteger = (new Integer(idString));
096: Object[] asParam = { oForm.getName(),
097: oForm.getPassword(), idInteger };
098: String[] asSignature = { "java.lang.String",
099: "java.lang.String", "int" };
100: JonasManagementRepr.invoke(oObjectName, "createUser",
101: asParam, asSignature, jonasServerName);
102: }
103: oForm.reset(p_Mapping, p_Request);
104: } catch (Throwable t) {
105: addGlobalError(t);
106: saveErrors(p_Request, m_Errors);
107: return (p_Mapping.findForward("Global Error"));
108: }
109:
110: // Forward to the jsp.
111: return (p_Mapping.findForward("Create Joram User"));
112: }
113: }
|