ApplyGroupMemoryRealmAction.java

00001 /*
00002  * JOnAS: Java(TM) Open Application Server
00003  * Copyright (C) 1999 Bull S.A.
00004  * Contact: jonas-team@objectweb.org
00005  *
00006  * This library is free software; you can redistribute it and/or
00007  * modify it under the terms of the GNU Lesser General Public
00008  * License as published by the Free Software Foundation; either
00009  * version 2.1 of the License, or any later version.
00010  *
00011  * This library is distributed in the hope that it will be useful,
00012  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00013  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00014  * Lesser General Public License for more details.
00015  *
00016  * You should have received a copy of the GNU Lesser General Public
00017  * License along with this library; if not, write to the Free Software
00018  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307
00019  * USA
00020  *
00021  * Initial developer(s): Michel-Ange ANTON
00022  * --------------------------------------------------------------------------
00023  * $Id: ApplyGroupMemoryRealmAction.java,v 1.3 2004/03/19 14:31:48 sauthieg Exp $
00024  * --------------------------------------------------------------------------
00025  */
00026 
00027 package org.objectweb.jonas.webapp.jonasadmin.security;
00028 
00029 import java.io.IOException;
00030 import java.util.ArrayList;
00031 
00032 import javax.management.ObjectName;
00033 import javax.servlet.ServletException;
00034 import javax.servlet.http.HttpServletRequest;
00035 import javax.servlet.http.HttpServletResponse;
00036 
00037 import org.apache.struts.action.ActionForm;
00038 import org.apache.struts.action.ActionForward;
00039 import org.apache.struts.action.ActionMapping;
00040 import org.objectweb.jonas.jmx.JonasManagementRepr;
00041 import org.objectweb.jonas.jmx.JonasObjectName;
00042 import org.objectweb.jonas.webapp.jonasadmin.Jlists;
00043 
00048 public class ApplyGroupMemoryRealmAction extends BaseMemoryRealmAction {
00049 
00050 // --------------------------------------------------------- Public Methods
00051 
00054     public ActionForward executeAction(ActionMapping p_Mapping, ActionForm p_Form
00055         , HttpServletRequest p_Request, HttpServletResponse p_Response)
00056         throws IOException, ServletException {
00057 
00058         // Realm Form used
00059         MemoryRealmForm oRealmForm = getForm(p_Mapping, p_Request);
00060 
00061         // Form used
00062         GroupMemoryRealmForm oForm = (GroupMemoryRealmForm) p_Form;
00063 
00064         oForm.setListRolesUsed(Jlists.getArrayList(oForm.getRolesUsed(), Jlists.SEPARATOR));
00065         oForm.setListRolesNotused(Jlists.getArrayList(oForm.getRolesNotused(), Jlists.SEPARATOR));
00066 
00067         ArrayList alAddRoles = new ArrayList(oForm.getListRolesUsed());
00068         alAddRoles.removeAll(oForm.getListRolesGroup());
00069         ArrayList alRemoveRoles = new ArrayList(oForm.getListRolesNotused());
00070         alRemoveRoles.retainAll(oForm.getListRolesGroup());
00071 
00072         // Populate MBean
00073         try {
00074             ObjectName onGroup = null;
00075             // Create a new Group
00076             if (oForm.getAction().equals("create") == true) {
00077                 ObjectName onRealm = JonasObjectName.securityMemoryFactory(oRealmForm.getResource());
00078                 String[] asParam = {
00079                     oForm.getGroup()};
00080                 String[] asSignature = {
00081                     "java.lang.String"};
00082                 JonasManagementRepr.invoke(onRealm, "addGroup", asParam, asSignature);
00083                 // Search created Group
00084                 onGroup = JonasObjectName.group(oRealmForm.getResource(), oForm.getGroup());
00085             }
00086             else {
00087                 // Modify existing Group
00088                 onGroup = JonasObjectName.group(oRealmForm.getResource(), oForm.getGroup());
00089             }
00090             // Description
00091             setStringAttribute(onGroup, "Description", oForm.getDescription());
00092 
00093             // Roles
00094             if (alAddRoles.size() > 0) {
00095                 for (int i = 0; i < alAddRoles.size(); i++) {
00096                     String[] asParam = {
00097                         alAddRoles.get(i).toString()};
00098                     String[] asSignature = {
00099                         "java.lang.String"};
00100                     JonasManagementRepr.invoke(onGroup, "addRole", asParam, asSignature);
00101                 }
00102             }
00103             if (alRemoveRoles.size() > 0) {
00104                 for (int i = 0; i < alRemoveRoles.size(); i++) {
00105                     String[] asParam = {
00106                         alRemoveRoles.get(i).toString()};
00107                     String[] asSignature = {
00108                         "java.lang.String"};
00109                     JonasManagementRepr.invoke(onGroup, "removeRole", asParam, asSignature);
00110                 }
00111             }
00112         }
00113         catch (Throwable t) {
00114             addGlobalError(t);
00115             saveErrors(p_Request, m_Errors);
00116             return (p_Mapping.findForward("Global Error"));
00117         }
00118         // Forward to the jsp.
00119         return (p_Mapping.findForward("ActionEditMemoryRealmGroups"));
00120     }
00121 
00122 // --------------------------------------------------------- Protected Methods
00123 
00124 }

Generated on Tue Feb 15 15:05:30 2005 for JOnAS by  doxygen 1.3.9.1