00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
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 ApplyUserMemoryRealmAction extends BaseMemoryRealmAction {
00049
00050
00051
00054 public ActionForward executeAction(ActionMapping p_Mapping, ActionForm p_Form
00055 , HttpServletRequest p_Request, HttpServletResponse p_Response)
00056 throws IOException, ServletException {
00057
00058
00059 MemoryRealmForm oRealmForm = getForm(p_Mapping, p_Request);
00060
00061
00062 UserMemoryRealmForm oForm = (UserMemoryRealmForm) p_Form;
00063
00064 oForm.setListRolesUsed(Jlists.getArrayList(oForm.getRolesUsed(), Jlists.SEPARATOR));
00065 oForm.setListRolesNotused(Jlists.getArrayList(oForm.getRolesNotused(), Jlists.SEPARATOR));
00066 oForm.setListGroupsUsed(Jlists.getArrayList(oForm.getGroupsUsed(), Jlists.SEPARATOR));
00067 oForm.setListGroupsNotused(Jlists.getArrayList(oForm.getGroupsNotused(), Jlists.SEPARATOR));
00068
00069 ArrayList alAddRoles = new ArrayList(oForm.getListRolesUsed());
00070 alAddRoles.removeAll(oForm.getListRolesUser());
00071 ArrayList alRemoveRoles = new ArrayList(oForm.getListRolesNotused());
00072 alRemoveRoles.retainAll(oForm.getListRolesUser());
00073 ArrayList alAddGroups = new ArrayList(oForm.getListGroupsUsed());
00074 alAddGroups.removeAll(oForm.getListGroupsUser());
00075 ArrayList alRemoveGroups = new ArrayList(oForm.getListGroupsNotused());
00076 alRemoveGroups.retainAll(oForm.getListGroupsUser());
00077
00078
00079 try {
00080 ObjectName onUser = null;
00081
00082 if (oForm.getAction().equals("create") == true) {
00083 String sEncrypted = encryptPassword(oForm.getPassword(), "MD5");
00084 ObjectName onRealm = JonasObjectName.securityMemoryFactory(oRealmForm.getResource());
00085 String[] asParam = {
00086 oForm.getUser(), sEncrypted};
00087 String[] asSignature = {
00088 "java.lang.String", "java.lang.String"};
00089 JonasManagementRepr.invoke(onRealm, "addUser", asParam, asSignature);
00090
00091 onUser = JonasObjectName.user(oRealmForm.getResource(), oForm.getUser());
00092 }
00093 else {
00094
00095 onUser = JonasObjectName.user(oRealmForm.getResource(), oForm.getUser());
00096
00097 if (oForm.getPassword().length() > 0) {
00098
00099 setStringAttribute(onUser, "Password", encryptPassword(oForm.getPassword()
00100 , "MD5"));
00101 }
00102 }
00103
00104 if (alAddRoles.size() > 0) {
00105 for (int i = 0; i < alAddRoles.size(); i++) {
00106 String[] asParam = {
00107 alAddRoles.get(i).toString()};
00108 String[] asSignature = {
00109 "java.lang.String"};
00110 JonasManagementRepr.invoke(onUser, "addRole", asParam, asSignature);
00111 }
00112 }
00113 if (alRemoveRoles.size() > 0) {
00114 for (int i = 0; i < alRemoveRoles.size(); i++) {
00115 String[] asParam = {
00116 alRemoveRoles.get(i).toString()};
00117 String[] asSignature = {
00118 "java.lang.String"};
00119 JonasManagementRepr.invoke(onUser, "removeRole", asParam, asSignature);
00120 }
00121 }
00122
00123 if (alAddGroups.size() > 0) {
00124 for (int i = 0; i < alAddGroups.size(); i++) {
00125 String[] asParam = {
00126 alAddGroups.get(i).toString()};
00127 String[] asSignature = {
00128 "java.lang.String"};
00129 JonasManagementRepr.invoke(onUser, "addGroup", asParam, asSignature);
00130 }
00131 }
00132 if (alRemoveGroups.size() > 0) {
00133 for (int i = 0; i < alRemoveGroups.size(); i++) {
00134 String[] asParam = {
00135 alRemoveGroups.get(i).toString()};
00136 String[] asSignature = {
00137 "java.lang.String"};
00138 JonasManagementRepr.invoke(onUser, "removeGroup", asParam, asSignature);
00139 }
00140 }
00141
00142 }
00143 catch (Throwable t) {
00144 addGlobalError(t);
00145 saveErrors(p_Request, m_Errors);
00146 return (p_Mapping.findForward("Global Error"));
00147 }
00148
00149 return (p_Mapping.findForward("ActionEditMemoryRealmUsers"));
00150 }
00151
00152
00153
00154 }