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 ApplyUserMemoryRealmAction 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 UserMemoryRealmForm oForm = (UserMemoryRealmForm) p_Form; 63 64 oForm.setListRolesUsed(Jlists.getArrayList(oForm.getRolesUsed(), Jlists.SEPARATOR)); 65 oForm.setListRolesNotused(Jlists.getArrayList(oForm.getRolesNotused(), Jlists.SEPARATOR)); 66 oForm.setListGroupsUsed(Jlists.getArrayList(oForm.getGroupsUsed(), Jlists.SEPARATOR)); 67 oForm.setListGroupsNotused(Jlists.getArrayList(oForm.getGroupsNotused(), Jlists.SEPARATOR)); 68 69 ArrayList alAddRoles = new ArrayList (oForm.getListRolesUsed()); 70 alAddRoles.removeAll(oForm.getListRolesUser()); 71 ArrayList alRemoveRoles = new ArrayList (oForm.getListRolesNotused()); 72 alRemoveRoles.retainAll(oForm.getListRolesUser()); 73 ArrayList alAddGroups = new ArrayList (oForm.getListGroupsUsed()); 74 alAddGroups.removeAll(oForm.getListGroupsUser()); 75 ArrayList alRemoveGroups = new ArrayList (oForm.getListGroupsNotused()); 76 alRemoveGroups.retainAll(oForm.getListGroupsUser()); 77 78 try { 80 ObjectName onUser = null; 81 if (oForm.getAction().equals("create") == true) { 83 String sEncrypted = encryptPassword(oForm.getPassword(), "MD5"); 84 ObjectName onRealm = JonasObjectName.securityMemoryFactory(oRealmForm.getResource()); 85 String [] asParam = { 86 oForm.getUser(), sEncrypted}; 87 String [] asSignature = { 88 "java.lang.String", "java.lang.String"}; 89 JonasManagementRepr.invoke(onRealm, "addUser", asParam, asSignature); 90 onUser = JonasObjectName.user(oRealmForm.getResource(), oForm.getUser()); 92 } 93 else { 94 onUser = JonasObjectName.user(oRealmForm.getResource(), oForm.getUser()); 96 if (oForm.getPassword().length() > 0) { 98 setStringAttribute(onUser, "Password", encryptPassword(oForm.getPassword() 100 , "MD5")); 101 } 102 } 103 if (alAddRoles.size() > 0) { 105 for (int i = 0; i < alAddRoles.size(); i++) { 106 String [] asParam = { 107 alAddRoles.get(i).toString()}; 108 String [] asSignature = { 109 "java.lang.String"}; 110 JonasManagementRepr.invoke(onUser, "addRole", asParam, asSignature); 111 } 112 } 113 if (alRemoveRoles.size() > 0) { 114 for (int i = 0; i < alRemoveRoles.size(); i++) { 115 String [] asParam = { 116 alRemoveRoles.get(i).toString()}; 117 String [] asSignature = { 118 "java.lang.String"}; 119 JonasManagementRepr.invoke(onUser, "removeRole", asParam, asSignature); 120 } 121 } 122 if (alAddGroups.size() > 0) { 124 for (int i = 0; i < alAddGroups.size(); i++) { 125 String [] asParam = { 126 alAddGroups.get(i).toString()}; 127 String [] asSignature = { 128 "java.lang.String"}; 129 JonasManagementRepr.invoke(onUser, "addGroup", asParam, asSignature); 130 } 131 } 132 if (alRemoveGroups.size() > 0) { 133 for (int i = 0; i < alRemoveGroups.size(); i++) { 134 String [] asParam = { 135 alRemoveGroups.get(i).toString()}; 136 String [] asSignature = { 137 "java.lang.String"}; 138 JonasManagementRepr.invoke(onUser, "removeGroup", asParam, asSignature); 139 } 140 } 141 142 } 143 catch (Throwable t) { 144 addGlobalError(t); 145 saveErrors(p_Request, m_Errors); 146 return (p_Mapping.findForward("Global Error")); 147 } 148 return (p_Mapping.findForward("ActionEditMemoryRealmUsers")); 150 } 151 152 154 } 155 | Popular Tags |