1 16 17 18 package org.apache.webapp.admin.realm; 19 20 import java.io.IOException ; 21 import java.util.ArrayList ; 22 import java.util.Iterator ; 23 import java.util.Locale ; 24 import java.util.Set ; 25 import java.util.TreeSet ; 26 import javax.management.MBeanServer ; 27 import javax.management.ObjectName ; 28 import javax.management.ObjectInstance ; 29 import javax.management.modelmbean.ModelMBean ; 30 import javax.servlet.ServletException ; 31 import javax.servlet.http.HttpSession ; 32 import javax.servlet.http.HttpServletRequest ; 33 import javax.servlet.http.HttpServletResponse ; 34 import org.apache.struts.action.Action; 35 import org.apache.struts.action.ActionForm; 36 import org.apache.struts.action.ActionForward; 37 import org.apache.struts.action.ActionMapping; 38 import org.apache.struts.util.MessageResources; 39 40 import org.apache.webapp.admin.ApplicationServlet; 41 import org.apache.webapp.admin.TomcatTreeBuilder; 42 import org.apache.webapp.admin.TreeControl; 43 import org.apache.webapp.admin.TreeControlNode; 44 45 46 53 54 public class DeleteRealmsAction extends Action { 55 56 57 60 private String removeRealmTypes[] = 61 { "java.lang.String", }; 63 64 65 68 private MBeanServer mBServer = null; 69 70 72 73 88 public ActionForward execute(ActionMapping mapping, 89 ActionForm form, 90 HttpServletRequest request, 91 HttpServletResponse response) 92 throws IOException , ServletException { 93 94 95 HttpSession session = request.getSession(); 97 Locale locale = getLocale(request); 98 MessageResources resources = getResources(request); 99 100 try { 102 mBServer = ((ApplicationServlet) getServlet()).getServer(); 103 } catch (Throwable t) { 104 throw new ServletException 105 ("Cannot acquire MBeanServer reference", t); 106 } 107 108 String realms[] = ((RealmsForm) form).getRealms(); 110 String values[] = new String [1]; 111 String operation = "removeRealm"; 112 try { 113 114 TreeControl control = (TreeControl) 116 session.getAttribute("treeControlTest"); 117 118 for (int i = 0; i < realms.length; i++) { 120 values[0] = realms[i]; 121 if (control != null) { 122 control.selectNode(null); 123 TreeControlNode node = control.findNode(realms[i]); 124 String domain = node.getDomain(); 125 ObjectName fname = 126 TomcatTreeBuilder.getMBeanFactory(); 127 mBServer.invoke(fname, operation, 128 values, removeRealmTypes); 129 if (node != null) { 130 node.remove(); 131 } else { 132 getServlet().log("Missing TreeControlNode for " + 133 realms[i]); 134 } 135 } else { 136 getServlet().log("Missing TreeControl attribute"); 137 } 138 } 139 140 } catch (Exception e) { 141 142 getServlet().log 143 (resources.getMessage(locale, "users.error.invoke", 144 operation), e); 145 response.sendError 146 (HttpServletResponse.SC_INTERNAL_SERVER_ERROR, 147 resources.getMessage(locale, "users.error.invoke", 148 operation)); 149 return (null); 150 151 } 152 153 return (mapping.findForward("Save Successful")); 155 156 } 157 158 } 159 | Popular Tags |