1 11 12 13 package com.sun.jmx.snmp.IPAcl; 14 15 16 17 import java.io.Serializable ; 20 import java.net.InetAddress ; 21 import java.net.UnknownHostException ; 22 import java.util.Hashtable ; 23 import java.util.Vector ; 24 import java.security.acl.NotOwnerException ; 25 26 import com.sun.jmx.trace.Trace; 29 30 36 abstract class Host extends SimpleNode implements Serializable { 37 38 public Host(int id) { 39 super(id); 40 } 41 42 public Host(Parser p, int id) { 43 super(p, id); 44 } 45 46 protected abstract PrincipalImpl createAssociatedPrincipal() 47 throws UnknownHostException ; 48 49 protected abstract String getHname(); 50 51 public void buildAclEntries(PrincipalImpl owner, AclImpl acl) { 52 PrincipalImpl p=null; 55 try { 56 p = createAssociatedPrincipal(); 57 } catch(UnknownHostException e) { 58 if (isDebugOn()) { 59 debug("buildAclEntries", "Cannot create ACL entry for " + e.getMessage()); 60 } 61 throw new IllegalArgumentException ("Cannot create ACL entry for " + e.getMessage()); 62 } 63 64 AclEntryImpl entry= null; 67 try { 68 entry = new AclEntryImpl(p); 69 registerPermission(entry); 72 acl.addEntry(owner, entry); 73 } catch(UnknownHostException e) { 74 if (isDebugOn()) { 75 debug("buildAclEntries", "Cannot create ACL entry for " + e.getMessage()); 76 } 77 return; 78 } catch(NotOwnerException a) { 79 if (isDebugOn()) { 80 debug("buildAclEntries", "Not owner of ACL " + a.getMessage()); 81 } 82 return; 83 } 84 } 85 86 private void registerPermission(AclEntryImpl entry) { 87 JDMHost host= (JDMHost) jjtGetParent(); 88 JDMManagers manager= (JDMManagers) host.jjtGetParent(); 89 JDMAclItem acl= (JDMAclItem) manager.jjtGetParent(); 90 JDMAccess access= (JDMAccess) acl.getAccess(); 91 access.putPermission(entry); 92 JDMCommunities comm= (JDMCommunities) acl.getCommunities(); 93 comm.buildCommunities(entry); 94 } 95 96 public void buildTrapEntries(Hashtable dest) { 97 98 JDMHostTrap host= (JDMHostTrap) jjtGetParent(); 99 JDMTrapInterestedHost hosts= (JDMTrapInterestedHost) host.jjtGetParent(); 100 JDMTrapItem trap = (JDMTrapItem) hosts.jjtGetParent(); 101 JDMTrapCommunity community = (JDMTrapCommunity) trap.getCommunity(); 102 String comm = community.getCommunity(); 103 104 InetAddress add = null; 105 try { 106 add = java.net.InetAddress.getByName(getHname()); 107 } catch(UnknownHostException e) { 108 if (isDebugOn()) { 109 debug("buildTrapEntries", "Cannot create TRAP entry for " + e.getMessage()); 110 } 111 return; 112 } 113 114 Vector list = null; 115 if (dest.containsKey(add)){ 116 list = (Vector ) dest.get(add); 117 if (!list.contains(comm)){ 118 list.addElement(comm); 119 } 120 } else { 121 list = new Vector (); 122 list.addElement(comm); 123 dest.put(add,list); 124 } 125 } 126 127 public void buildInformEntries(Hashtable dest) { 128 129 JDMHostInform host= (JDMHostInform) jjtGetParent(); 130 JDMInformInterestedHost hosts= (JDMInformInterestedHost) host.jjtGetParent(); 131 JDMInformItem inform = (JDMInformItem) hosts.jjtGetParent(); 132 JDMInformCommunity community = (JDMInformCommunity) inform.getCommunity(); 133 String comm = community.getCommunity(); 134 135 InetAddress add = null; 136 try { 137 add = java.net.InetAddress.getByName(getHname()); 138 } catch(UnknownHostException e) { 139 if (isDebugOn()) { 140 debug("buildInformEntries", "Cannot create INFORM entry for " + e.getMessage()); 141 } 142 return; 143 } 144 145 Vector list = null; 146 if (dest.containsKey(add)){ 147 list = (Vector ) dest.get(add); 148 if (!list.contains(comm)){ 149 list.addElement(comm); 150 } 151 } else { 152 list = new Vector (); 153 list.addElement(comm); 154 dest.put(add,list); 155 } 156 } 157 158 161 boolean isTraceOn() { 162 return Trace.isSelected(Trace.LEVEL_TRACE, Trace.INFO_SNMP); 163 } 164 165 void trace(String clz, String func, String info) { 166 Trace.send(Trace.LEVEL_TRACE, Trace.INFO_SNMP, clz, func, info); 167 } 168 169 void trace(String func, String info) { 170 trace(dbgTag, func, info); 171 } 172 173 boolean isDebugOn() { 174 return Trace.isSelected(Trace.LEVEL_DEBUG, Trace.INFO_SNMP); 175 } 176 177 void debug(String clz, String func, String info) { 178 Trace.send(Trace.LEVEL_DEBUG, Trace.INFO_SNMP, clz, func, info); 179 } 180 181 void debug(String func, String info) { 182 debug(dbgTag, func, info); 183 } 184 185 String dbgTag = "Host"; 186 } 187 | Popular Tags |