1 26 27 package org.objectweb.jonas.webapp.jonasadmin.security; 28 29 import java.io.IOException ; 30 import java.util.ArrayList ; 31 32 import javax.management.ObjectName ; 33 import javax.servlet.ServletException ; 34 import javax.servlet.http.HttpServletRequest ; 35 import javax.servlet.http.HttpServletResponse ; 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 47 48 public class ApplyGroupMemoryRealmAction extends BaseMemoryRealmAction { 49 50 52 54 public ActionForward executeAction(ActionMapping p_Mapping, ActionForm p_Form 55 , HttpServletRequest p_Request, HttpServletResponse p_Response) 56 throws IOException , ServletException { 57 58 MemoryRealmForm oRealmForm = getForm(p_Mapping, p_Request); 60 61 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 alAddRoles = new ArrayList (oForm.getListRolesUsed()); 68 alAddRoles.removeAll(oForm.getListRolesGroup()); 69 ArrayList alRemoveRoles = new ArrayList (oForm.getListRolesNotused()); 70 alRemoveRoles.retainAll(oForm.getListRolesGroup()); 71 72 try { 74 ObjectName onGroup = null; 75 if (oForm.getAction().equals("create") == true) { 77 ObjectName onRealm = JonasObjectName.securityMemoryFactory(oRealmForm.getResource()); 78 String [] asParam = { 79 oForm.getGroup()}; 80 String [] asSignature = { 81 "java.lang.String"}; 82 JonasManagementRepr.invoke(onRealm, "addGroup", asParam, asSignature); 83 onGroup = JonasObjectName.group(oRealmForm.getResource(), oForm.getGroup()); 85 } 86 else { 87 onGroup = JonasObjectName.group(oRealmForm.getResource(), oForm.getGroup()); 89 } 90 setStringAttribute(onGroup, "Description", oForm.getDescription()); 92 93 if (alAddRoles.size() > 0) { 95 for (int i = 0; i < alAddRoles.size(); i++) { 96 String [] asParam = { 97 alAddRoles.get(i).toString()}; 98 String [] 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 [] asParam = { 106 alRemoveRoles.get(i).toString()}; 107 String [] asSignature = { 108 "java.lang.String"}; 109 JonasManagementRepr.invoke(onGroup, "removeRole", asParam, asSignature); 110 } 111 } 112 } 113 catch (Throwable t) { 114 addGlobalError(t); 115 saveErrors(p_Request, m_Errors); 116 return (p_Mapping.findForward("Global Error")); 117 } 118 return (p_Mapping.findForward("ActionEditMemoryRealmGroups")); 120 } 121 122 124 } 125 | Popular Tags |