1 16 17 18 package org.apache.webapp.admin.realm; 19 20 import java.io.IOException ; 21 import java.util.Collections ; 22 import java.util.Iterator ; 23 import java.util.List ; 24 import java.util.Locale ; 25 import java.util.TreeSet ; 26 import java.util.Set ; 27 import java.util.ArrayList ; 28 import javax.servlet.ServletException ; 29 import javax.servlet.http.HttpServletRequest ; 30 import javax.servlet.http.HttpServletResponse ; 31 import javax.servlet.http.HttpSession ; 32 import org.apache.struts.action.Action; 33 import org.apache.struts.action.ActionErrors; 34 import org.apache.struts.action.ActionForm; 35 import org.apache.struts.action.ActionForward; 36 import org.apache.struts.action.ActionMapping; 37 38 import javax.management.MBeanServer ; 39 import javax.management.MBeanServerFactory ; 40 import javax.management.QueryExp ; 41 import javax.management.Query ; 42 import javax.management.ObjectInstance ; 43 import javax.management.ObjectName ; 44 import javax.management.JMException ; 45 import org.apache.struts.util.MessageResources; 46 47 import org.apache.webapp.admin.ApplicationServlet; 48 import org.apache.webapp.admin.TomcatTreeBuilder; 49 import org.apache.webapp.admin.valve.ValveUtil; 50 51 57 58 public class DeleteRealmAction extends Action { 59 60 61 64 private MBeanServer mBServer = null; 65 66 67 69 84 public ActionForward execute(ActionMapping mapping, 85 ActionForm form, 86 HttpServletRequest request, 87 HttpServletResponse response) 88 throws IOException , ServletException { 89 90 91 HttpSession session = request.getSession(); 93 Locale locale = getLocale(request); 94 MessageResources resources = getResources(request); 95 96 try { 98 mBServer = ((ApplicationServlet) getServlet()).getServer(); 99 } catch (Throwable t) { 100 throw new ServletException 101 ("Cannot acquire MBeanServer reference", t); 102 } 103 104 String pattern = null; 105 RealmsForm realmsForm = new RealmsForm(); 108 String select = request.getParameter("select"); 109 if (select != null) { 110 String realms[] = new String [1]; 111 realms[0] = select; 112 realmsForm.setRealms(realms); 113 pattern = select; 114 } 115 request.setAttribute("realmsForm", realmsForm); 116 117 ArrayList list = new ArrayList (); 119 String parent = request.getParameter("parent"); 120 121 if (parent != null) { 122 try { 123 pattern = ValveUtil.getObjectName( 124 parent,TomcatTreeBuilder.REALM_TYPE); 125 } catch (Exception e) { 126 getServlet().log 127 (resources.getMessage(locale, "users.error.select")); 128 response.sendError 129 (HttpServletResponse.SC_INTERNAL_SERVER_ERROR, 130 resources.getMessage(locale, "users.error.select")); 131 return (null); 132 } 133 } 134 135 try { 136 Iterator items = 137 mBServer.queryNames(new ObjectName (pattern), null).iterator(); 138 while (items.hasNext()) { 139 list.add(items.next().toString()); 140 } 141 } catch (Exception e) { 142 getServlet().log 143 (resources.getMessage(locale, "users.error.select")); 144 response.sendError 145 (HttpServletResponse.SC_INTERNAL_SERVER_ERROR, 146 resources.getMessage(locale, "users.error.select")); 147 return (null); 148 } 149 150 Collections.sort(list); 151 request.setAttribute("realmsList", list); 152 153 return (mapping.findForward("Realms")); 155 156 } 157 158 } 159 | Popular Tags |