KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > jonas > webapp > jonasadmin > security > ApplyGroupMemoryRealmAction


1 /*
2  * JOnAS: Java(TM) Open Application Server
3  * Copyright (C) 1999 Bull S.A.
4  * Contact: jonas-team@objectweb.org
5  *
6  * This library is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public
8  * License as published by the Free Software Foundation; either
9  * version 2.1 of the License, or any later version.
10  *
11  * This library is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with this library; if not, write to the Free Software
18  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
19  * USA
20  *
21  * Initial developer(s): Michel-Ange ANTON
22  * --------------------------------------------------------------------------
23  * $Id: ApplyGroupMemoryRealmAction.java,v 1.3 2004/03/19 14:31:48 sauthieg Exp $
24  * --------------------------------------------------------------------------
25  */

26
27 package org.objectweb.jonas.webapp.jonasadmin.security;
28
29 import java.io.IOException JavaDoc;
30 import java.util.ArrayList JavaDoc;
31
32 import javax.management.ObjectName JavaDoc;
33 import javax.servlet.ServletException JavaDoc;
34 import javax.servlet.http.HttpServletRequest JavaDoc;
35 import javax.servlet.http.HttpServletResponse JavaDoc;
36
37 import org.apache.struts.action.ActionForm;
38 import org.apache.struts.action.ActionForward;
39 import org.apache.struts.action.ActionMapping;
40 import org.objectweb.jonas.jmx.JonasManagementRepr;
41 import org.objectweb.jonas.jmx.JonasObjectName;
42 import org.objectweb.jonas.webapp.jonasadmin.Jlists;
43
44 /**
45  *
46  */

47
48 public class ApplyGroupMemoryRealmAction extends BaseMemoryRealmAction {
49
50 // --------------------------------------------------------- Public Methods
51

52     /**
53      */

54     public ActionForward executeAction(ActionMapping p_Mapping, ActionForm p_Form
55         , HttpServletRequest JavaDoc p_Request, HttpServletResponse JavaDoc p_Response)
56         throws IOException JavaDoc, ServletException JavaDoc {
57
58         // Realm Form used
59
MemoryRealmForm oRealmForm = getForm(p_Mapping, p_Request);
60
61         // Form used
62
GroupMemoryRealmForm oForm = (GroupMemoryRealmForm) p_Form;
63
64         oForm.setListRolesUsed(Jlists.getArrayList(oForm.getRolesUsed(), Jlists.SEPARATOR));
65         oForm.setListRolesNotused(Jlists.getArrayList(oForm.getRolesNotused(), Jlists.SEPARATOR));
66
67         ArrayList JavaDoc alAddRoles = new ArrayList JavaDoc(oForm.getListRolesUsed());
68         alAddRoles.removeAll(oForm.getListRolesGroup());
69         ArrayList JavaDoc alRemoveRoles = new ArrayList JavaDoc(oForm.getListRolesNotused());
70         alRemoveRoles.retainAll(oForm.getListRolesGroup());
71
72         // Populate MBean
73
try {
74             ObjectName JavaDoc onGroup = null;
75             // Create a new Group
76
if (oForm.getAction().equals("create") == true) {
77                 ObjectName JavaDoc onRealm = JonasObjectName.securityMemoryFactory(oRealmForm.getResource());
78                 String JavaDoc[] asParam = {
79                     oForm.getGroup()};
80                 String JavaDoc[] asSignature = {
81                     "java.lang.String"};
82                 JonasManagementRepr.invoke(onRealm, "addGroup", asParam, asSignature);
83                 // Search created Group
84
onGroup = JonasObjectName.group(oRealmForm.getResource(), oForm.getGroup());
85             }
86             else {
87                 // Modify existing Group
88
onGroup = JonasObjectName.group(oRealmForm.getResource(), oForm.getGroup());
89             }
90             // Description
91
setStringAttribute(onGroup, "Description", oForm.getDescription());
92
93             // Roles
94
if (alAddRoles.size() > 0) {
95                 for (int i = 0; i < alAddRoles.size(); i++) {
96                     String JavaDoc[] asParam = {
97                         alAddRoles.get(i).toString()};
98                     String JavaDoc[] asSignature = {
99                         "java.lang.String"};
100                     JonasManagementRepr.invoke(onGroup, "addRole", asParam, asSignature);
101                 }
102             }
103             if (alRemoveRoles.size() > 0) {
104                 for (int i = 0; i < alRemoveRoles.size(); i++) {
105                     String JavaDoc[] asParam = {
106                         alRemoveRoles.get(i).toString()};
107                     String JavaDoc[] asSignature = {
108                         "java.lang.String"};
109                     JonasManagementRepr.invoke(onGroup, "removeRole", asParam, asSignature);
110                 }
111             }
112         }
113         catch (Throwable JavaDoc t) {
114             addGlobalError(t);
115             saveErrors(p_Request, m_Errors);
116             return (p_Mapping.findForward("Global Error"));
117         }
118         // Forward to the jsp.
119
return (p_Mapping.findForward("ActionEditMemoryRealmGroups"));
120     }
121
122 // --------------------------------------------------------- Protected Methods
123

124 }
125
Popular Tags