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: * Initial developer(s): Michel-Ange ANTON
022: * --------------------------------------------------------------------------
023: * $Id: ApplyRoleMemoryRealmAction.java 9680 2006-10-06 12:08:33Z danesa $
024: * --------------------------------------------------------------------------
025: */
026:
027: package org.objectweb.jonas.webapp.jonasadmin.security;
028:
029: import java.io.IOException;
030:
031: import javax.management.ObjectName;
032: import javax.servlet.ServletException;
033: import javax.servlet.http.HttpServletRequest;
034: import javax.servlet.http.HttpServletResponse;
035:
036: import org.apache.struts.action.ActionForm;
037: import org.apache.struts.action.ActionForward;
038: import org.apache.struts.action.ActionMapping;
039: import org.objectweb.jonas.jmx.JonasManagementRepr;
040: import org.objectweb.jonas.jmx.JonasObjectName;
041: import org.objectweb.jonas.webapp.jonasadmin.WhereAreYou;
042:
043: /**
044: *
045: */
046:
047: public class ApplyRoleMemoryRealmAction extends BaseMemoryRealmAction {
048:
049: // --------------------------------------------------------- Public Methods
050:
051: /**
052: */
053: public ActionForward executeAction(ActionMapping p_Mapping,
054: ActionForm p_Form, HttpServletRequest p_Request,
055: HttpServletResponse p_Response) throws IOException,
056: ServletException {
057:
058: WhereAreYou oWhere = (WhereAreYou) p_Request.getSession()
059: .getAttribute(WhereAreYou.SESSION_NAME);
060: String serverName = oWhere.getCurrentJonasServerName();
061:
062: // Realm Form used
063: MemoryRealmForm oRealmForm = getForm(p_Mapping, p_Request);
064:
065: // Form used
066: RoleMemoryRealmForm oForm = (RoleMemoryRealmForm) p_Form;
067:
068: // Populate MBean
069: try {
070: ObjectName onRole = null;
071: // Create a new role
072: if (oForm.getAction().equals("create") == true) {
073: ObjectName onRealm = JonasObjectName
074: .securityMemoryFactory(oRealmForm.getResource());
075: String[] asParam = { oForm.getRole() };
076: String[] asSignature = { "java.lang.String", };
077: JonasManagementRepr.invoke(onRealm, "addRole", asParam,
078: asSignature, serverName);
079: // Search created role
080: onRole = JonasObjectName.role(oRealmForm.getResource(),
081: oForm.getRole());
082: } else {
083: // Modify existing user
084: onRole = JonasObjectName.role(oRealmForm.getResource(),
085: oForm.getRole());
086: }
087: // Description
088: setStringAttribute(onRole, "Description", oForm
089: .getDescription());
090: } catch (Throwable t) {
091: addGlobalError(t);
092: saveErrors(p_Request, m_Errors);
093: return (p_Mapping.findForward("Global Error"));
094: }
095: // Forward to the jsp.
096: return (p_Mapping.findForward("ActionEditMemoryRealmRoles"));
097: }
098:
099: // --------------------------------------------------------- Protected Methods
100:
101: }
|