1 25 26 package org.objectweb.jonas.webapp.jonasadmin.security; 27 28 import java.io.IOException ; 29 import java.util.ArrayList ; 30 import java.util.Collections ; 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.CatalinaObjectName; 41 import org.objectweb.jonas.webapp.jonasadmin.JonasAdminJmx; 42 import org.objectweb.jonas.webapp.jonasadmin.WhereAreYou; 43 44 47 48 public class ListRealmsAction extends BaseMemoryRealmAction { 49 50 52 public ActionForward executeAction(ActionMapping p_Mapping, ActionForm p_Form 53 , HttpServletRequest p_Request, HttpServletResponse p_Response) 54 throws IOException , ServletException { 55 56 String sTypeRealm = p_Request.getParameter("realm"); 58 if (sTypeRealm == null) { 59 sTypeRealm = (String ) m_Session.getAttribute("typeRealm"); 60 } 61 else { 62 m_Session.setAttribute("typeRealm", sTypeRealm); 63 } 64 if (sTypeRealm == null) { 66 sTypeRealm = "all"; 67 m_Session.setAttribute("typeRealm", sTypeRealm); 68 } 69 70 try { 72 String sSecurityRealmUsed = null; 73 if (m_WhereAreYou.isCatalinaServer() == true) { 75 try { 76 ObjectName oObjectName = CatalinaObjectName.catalinaRealm(m_WhereAreYou. 78 getCurrentCatalinaServiceName()); 79 sSecurityRealmUsed = getStringAttribute(oObjectName, "resourceName"); 81 } 82 catch (Exception e) { 83 } 86 } 87 88 ArrayList alRealms = new ArrayList (); 89 if (sTypeRealm.equals("all") == true) { 91 addRealmItem(alRealms, "memory", sSecurityRealmUsed); 93 addRealmItem(alRealms, "datasource", sSecurityRealmUsed); 94 addRealmItem(alRealms, "ldap", sSecurityRealmUsed); 95 m_WhereAreYou.selectNameNode(getTreeBranchName(DEPTH_SERVER) 97 + WhereAreYou.NODE_SEPARATOR + "security", true); 98 } 99 else if (sTypeRealm.equals("memory") == true) { 101 addRealmItem(alRealms, "memory", sSecurityRealmUsed); 102 m_WhereAreYou.selectNameNode(getTreeBranchName(DEPTH_SERVER) 104 + WhereAreYou.NODE_SEPARATOR + "security" + WhereAreYou.NODE_SEPARATOR 105 + "factory.memory", true); 106 } 107 else if (sTypeRealm.equals("datasource") == true) { 109 addRealmItem(alRealms, "datasource", sSecurityRealmUsed); 110 m_WhereAreYou.selectNameNode(getTreeBranchName(DEPTH_SERVER) 112 + WhereAreYou.NODE_SEPARATOR + "security" + WhereAreYou.NODE_SEPARATOR 113 + "factory.datasource", true); 114 } 115 else if (sTypeRealm.equals("ldap") == true) { 117 addRealmItem(alRealms, "ldap", sSecurityRealmUsed); 118 m_WhereAreYou.selectNameNode(getTreeBranchName(DEPTH_SERVER) 120 + WhereAreYou.NODE_SEPARATOR + "security" + WhereAreYou.NODE_SEPARATOR 121 + "factory.ldap", true); 122 } 123 else { 125 String sMess = m_Resources.getMessage("error.security.factory.realms.type.unknown" 126 , sTypeRealm); 127 throw new Exception (sMess); 128 } 129 Collections.sort(alRealms, new RealmItemByNameComparator()); 131 m_Session.setAttribute("listRealms", alRealms); 133 134 } 135 catch (Throwable t) { 136 addGlobalError(t); 137 saveErrors(p_Request, m_Errors); 138 return (p_Mapping.findForward("Global Error")); 139 } 140 return (p_Mapping.findForward("Realms")); 142 } 143 144 154 protected void addRealmItem(ArrayList p_Realms, String p_Type, String p_SecurityRealmUsed) 155 throws Exception { 156 157 ArrayList al = null; 158 159 if (p_Type.equals("memory") == true) { 161 al = JonasAdminJmx.getSecurityMemoryFactories(); 162 } 163 else if (p_Type.equals("datasource") == true) { 165 al = JonasAdminJmx.getSecurityDatasourceFactories(); 166 } 167 else if (p_Type.equals("ldap") == true) { 169 al = JonasAdminJmx.getSecurityLdapFactories(); 170 } 171 if (al != null) { 173 for (int i = 0; i < al.size(); i++) { 174 if (p_SecurityRealmUsed != null) { 175 p_Realms.add(new RealmItem(al.get(i).toString(), p_Type 176 , p_SecurityRealmUsed.equals(al.get(i).toString()))); 177 } 178 else { 179 p_Realms.add(new RealmItem(al.get(i).toString(), p_Type)); 180 } 181 } 182 } 183 } 184 } 185 | Popular Tags |