1 8 9 package mx4j.examples.remote.interception; 10 11 import java.io.ObjectInputStream ; 12 import java.security.AccessController ; 13 import java.util.Set ; 14 import javax.management.Attribute ; 15 import javax.management.AttributeList ; 16 import javax.management.AttributeNotFoundException ; 17 import javax.management.InstanceAlreadyExistsException ; 18 import javax.management.InstanceNotFoundException ; 19 import javax.management.IntrospectionException ; 20 import javax.management.InvalidAttributeValueException ; 21 import javax.management.ListenerNotFoundException ; 22 import javax.management.MBeanException ; 23 import javax.management.MBeanInfo ; 24 import javax.management.MBeanRegistrationException ; 25 import javax.management.MBeanServer ; 26 import javax.management.NotCompliantMBeanException ; 27 import javax.management.NotificationFilter ; 28 import javax.management.NotificationListener ; 29 import javax.management.ObjectInstance ; 30 import javax.management.ObjectName ; 31 import javax.management.OperationsException ; 32 import javax.management.QueryExp ; 33 import javax.management.ReflectionException ; 34 import javax.management.loading.ClassLoaderRepository ; 35 import javax.management.remote.MBeanServerForwarder ; 36 import javax.security.auth.Subject ; 37 38 45 public class SubjectTrackingMBeanServer implements MBeanServerForwarder 46 { 47 private MBeanServer server; 48 49 public synchronized MBeanServer getMBeanServer() 50 { 51 return server; 52 } 53 54 public synchronized void setMBeanServer(MBeanServer server) throws IllegalArgumentException 55 { 56 if (server == null) throw new IllegalArgumentException ("Cannot forward to a null MBeanServer"); 57 this.server = server; 58 } 59 60 private void trackSubject() 61 { 62 Subject subject = Subject.getSubject(AccessController.getContext()); 63 System.out.println("Subject = " + subject); 64 } 65 66 public void addNotificationListener(ObjectName observed, NotificationListener listener, NotificationFilter filter, Object handback) 67 throws InstanceNotFoundException 68 { 69 trackSubject(); 70 getMBeanServer().addNotificationListener(observed, listener, filter, handback); 71 } 72 73 public void addNotificationListener(ObjectName observed, ObjectName listener, NotificationFilter filter, Object handback) 74 throws InstanceNotFoundException 75 { 76 trackSubject(); 77 getMBeanServer().addNotificationListener(observed, listener, filter, handback); 78 } 79 80 public void removeNotificationListener(ObjectName observed, ObjectName listener) 81 throws InstanceNotFoundException , ListenerNotFoundException 82 { 83 trackSubject(); 84 getMBeanServer().removeNotificationListener(observed, listener); 85 } 86 87 public void removeNotificationListener(ObjectName observed, NotificationListener listener) 88 throws InstanceNotFoundException , ListenerNotFoundException 89 { 90 trackSubject(); 91 getMBeanServer().removeNotificationListener(observed, listener); 92 } 93 94 public void removeNotificationListener(ObjectName observed, ObjectName listener, NotificationFilter filter, Object handback) 95 throws InstanceNotFoundException , ListenerNotFoundException 96 { 97 trackSubject(); 98 getMBeanServer().removeNotificationListener(observed, listener, filter, handback); 99 } 100 101 public void removeNotificationListener(ObjectName observed, NotificationListener listener, NotificationFilter filter, Object handback) 102 throws InstanceNotFoundException , ListenerNotFoundException 103 { 104 trackSubject(); 105 getMBeanServer().removeNotificationListener(observed, listener, filter, handback); 106 } 107 108 public MBeanInfo getMBeanInfo(ObjectName objectName) 109 throws InstanceNotFoundException , IntrospectionException , ReflectionException 110 { 111 trackSubject(); 112 return getMBeanServer().getMBeanInfo(objectName); 113 } 114 115 public boolean isInstanceOf(ObjectName objectName, String className) 116 throws InstanceNotFoundException 117 { 118 trackSubject(); 119 return getMBeanServer().isInstanceOf(objectName, className); 120 } 121 122 public String [] getDomains() 123 { 124 trackSubject(); 125 return getMBeanServer().getDomains(); 126 } 127 128 public String getDefaultDomain() 129 { 130 trackSubject(); 131 return getMBeanServer().getDefaultDomain(); 132 } 133 134 public ObjectInstance createMBean(String className, ObjectName objectName) 135 throws ReflectionException , InstanceAlreadyExistsException , MBeanRegistrationException , MBeanException , NotCompliantMBeanException 136 { 137 trackSubject(); 138 return getMBeanServer().createMBean(className, objectName); 139 } 140 141 public ObjectInstance createMBean(String className, ObjectName objectName, ObjectName loaderName) 142 throws ReflectionException , InstanceAlreadyExistsException , MBeanRegistrationException , MBeanException , NotCompliantMBeanException , InstanceNotFoundException 143 { 144 trackSubject(); 145 return getMBeanServer().createMBean(className, objectName, loaderName); 146 } 147 148 public ObjectInstance createMBean(String className, ObjectName objectName, Object [] args, String [] parameters) 149 throws ReflectionException , InstanceAlreadyExistsException , MBeanRegistrationException , MBeanException , NotCompliantMBeanException 150 { 151 trackSubject(); 152 return getMBeanServer().createMBean(className, objectName, args, parameters); 153 } 154 155 public ObjectInstance createMBean(String className, ObjectName objectName, ObjectName loaderName, Object [] args, String [] parameters) 156 throws ReflectionException , InstanceAlreadyExistsException , MBeanRegistrationException , MBeanException , NotCompliantMBeanException , InstanceNotFoundException 157 { 158 trackSubject(); 159 return getMBeanServer().createMBean(className, objectName, loaderName, args, parameters); 160 } 161 162 public void unregisterMBean(ObjectName objectName) 163 throws InstanceNotFoundException , MBeanRegistrationException 164 { 165 trackSubject(); 166 getMBeanServer().unregisterMBean(objectName); 167 } 168 169 public Object getAttribute(ObjectName objectName, String attribute) 170 throws MBeanException , AttributeNotFoundException , InstanceNotFoundException , ReflectionException 171 { 172 trackSubject(); 173 return getMBeanServer().getAttribute(objectName, attribute); 174 } 175 176 public void setAttribute(ObjectName objectName, Attribute attribute) 177 throws InstanceNotFoundException , AttributeNotFoundException , InvalidAttributeValueException , MBeanException , ReflectionException 178 { 179 trackSubject(); 180 getMBeanServer().setAttribute(objectName, attribute); 181 } 182 183 public AttributeList getAttributes(ObjectName objectName, String [] attributes) 184 throws InstanceNotFoundException , ReflectionException 185 { 186 trackSubject(); 187 return getMBeanServer().getAttributes(objectName, attributes); 188 } 189 190 public AttributeList setAttributes(ObjectName objectName, AttributeList attributes) 191 throws InstanceNotFoundException , ReflectionException 192 { 193 trackSubject(); 194 return getMBeanServer().setAttributes(objectName, attributes); 195 } 196 197 public Object invoke(ObjectName objectName, String methodName, Object [] args, String [] parameters) 198 throws InstanceNotFoundException , MBeanException , ReflectionException 199 { 200 trackSubject(); 201 return getMBeanServer().invoke(objectName, methodName, args, parameters); 202 } 203 204 public Integer getMBeanCount() 205 { 206 trackSubject(); 207 return getMBeanServer().getMBeanCount(); 208 } 209 210 public boolean isRegistered(ObjectName objectname) 211 { 212 trackSubject(); 213 return getMBeanServer().isRegistered(objectname); 214 } 215 216 public ObjectInstance getObjectInstance(ObjectName objectName) 217 throws InstanceNotFoundException 218 { 219 trackSubject(); 220 return getMBeanServer().getObjectInstance(objectName); 221 } 222 223 public Set queryMBeans(ObjectName patternName, QueryExp filter) 224 { 225 trackSubject(); 226 return getMBeanServer().queryMBeans(patternName, filter); 227 } 228 229 public Set queryNames(ObjectName patternName, QueryExp filter) 230 { 231 trackSubject(); 232 return getMBeanServer().queryNames(patternName, filter); 233 } 234 235 public Object instantiate(String className) 236 throws ReflectionException , MBeanException 237 { 238 trackSubject(); 239 return getMBeanServer().instantiate(className); 240 } 241 242 public Object instantiate(String className, ObjectName loaderName) 243 throws ReflectionException , MBeanException , InstanceNotFoundException 244 { 245 trackSubject(); 246 return getMBeanServer().instantiate(className, loaderName); 247 } 248 249 public Object instantiate(String className, Object [] args, String [] parameters) 250 throws ReflectionException , MBeanException 251 { 252 trackSubject(); 253 return getMBeanServer().instantiate(className, args, parameters); 254 } 255 256 public Object instantiate(String className, ObjectName loaderName, Object [] args, String [] parameters) 257 throws ReflectionException , MBeanException , InstanceNotFoundException 258 { 259 trackSubject(); 260 return getMBeanServer().instantiate(className, loaderName, args, parameters); 261 } 262 263 public ObjectInstance registerMBean(Object mbean, ObjectName objectName) 264 throws InstanceAlreadyExistsException , MBeanRegistrationException , NotCompliantMBeanException 265 { 266 trackSubject(); 267 return registerMBean(mbean, objectName); 268 } 269 270 public ObjectInputStream deserialize(String className, ObjectName loaderName, byte[] bytes) 271 throws InstanceNotFoundException , OperationsException , ReflectionException 272 { 273 trackSubject(); 274 return getMBeanServer().deserialize(className, loaderName, bytes); 275 } 276 277 public ObjectInputStream deserialize(String className, byte[] bytes) 278 throws OperationsException , ReflectionException 279 { 280 trackSubject(); 281 return getMBeanServer().deserialize(className, bytes); 282 } 283 284 public ObjectInputStream deserialize(ObjectName objectName, byte[] bytes) 285 throws InstanceNotFoundException , OperationsException 286 { 287 trackSubject(); 288 return getMBeanServer().deserialize(objectName, bytes); 289 } 290 291 public ClassLoader getClassLoaderFor(ObjectName mbeanName) 292 throws InstanceNotFoundException 293 { 294 trackSubject(); 295 return getMBeanServer().getClassLoaderFor(mbeanName); 296 } 297 298 public ClassLoader getClassLoader(ObjectName loaderName) 299 throws InstanceNotFoundException 300 { 301 trackSubject(); 302 return getMBeanServer().getClassLoader(loaderName); 303 } 304 305 public ClassLoaderRepository getClassLoaderRepository() 306 { 307 trackSubject(); 308 return getMBeanServer().getClassLoaderRepository(); 309 } 310 } 311 | Popular Tags |