Source Code Cross Referenced for PortalServerLoggingInterceptor.java in  » Portal » Open-Portal » com » sun » portal » admin » server » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Portal » Open Portal » com.sun.portal.admin.server 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        package com.sun.portal.admin.server;
002:
003:        import java.util.*;
004:        import java.util.logging.Logger;
005:        import java.util.logging.Level;
006:        import java.io.InputStream;
007:        import java.io.IOException;
008:
009:        import com.sun.jdmk.interceptor.MBeanServerInterceptorWrapper;
010:        import com.sun.jdmk.interceptor.MBeanServerInterceptor;
011:        import com.sun.jdmk.ServiceName;
012:        import com.sun.jdmk.JdmkMBeanServer;
013:        import com.sun.jdmk.comm.CommunicatorServer;
014:        import com.sun.jdmk.comm.HtmlAdaptorServer;
015:        import com.sun.portal.log.common.PortalLogger;
016:        import com.sun.portal.admin.common.util.AdminUtil;
017:
018:        import javax.management.timer.Timer;
019:        import javax.management.*;
020:        import javax.management.Attribute;
021:
022:        import org.apache.bcel.classfile.*;
023:        import org.apache.bcel.generic.Type;
024:
025:        /**
026:         * This class is responsible for audit logging. This needs to be plugged-in as
027:         * one of the interceptors in MBeanServer.
028:         */
029:        public class PortalServerLoggingInterceptor implements 
030:                MBeanServerInterceptor {
031:            //Keys
032:            public static String OP_TYPE = "OperationType";
033:            public static String OP_NAME = "OperationName";
034:            public static String MBEAN_NAME = "MBeanName";
035:            public static String RETURN = "ReturnValue";
036:            public static String LISTENER = "Listener";
037:            public static String CLASS_NAME = "ClassName";
038:            public static String LOADER_NAME = "LoaderName";
039:            public static String MBEAN_OBJECT = "MBeanObject";
040:            public static String QUERY_EXP = "QueryExpression";
041:            public static String ATTRIBUTE_NAME = "AttributeName";
042:            public static String METHOD_NAME = "MethodName";
043:            //Operations
044:            public static String LISTEN = "LISTEN";
045:            public static String CREATE = "CREATE";
046:            public static String REGISTER = "REGISTER";
047:            public static String UNREGISTER = "UNREGISTER";
048:            public static String GET = "GET";
049:            public static String SET = "SET";
050:            public static String INVOKE = "INVOKE";
051:            public static String QUERY = "QUERY";
052:            public static String INFO = "INFO";
053:
054:            private static String maskedPassword = "******";
055:
056:            //DON'T use this logger for debug logging
057:            private static Logger auditLogger = PortalLogger
058:                    .getLogger("debug.com.sun.portal.audit");
059:            ///////////
060:
061:            private MBeanServerInterceptorWrapper interceptorWrapper = null;
062:            private MBeanServer server;
063:            private HashMap clazzCache = new HashMap();
064:
065:            public PortalServerLoggingInterceptor(
066:                    MBeanServerInterceptor mBeanServerInterceptor,
067:                    MBeanServerInterceptorWrapper.Controller controller) {
068:                interceptorWrapper = new MBeanServerInterceptorWrapper(
069:                        mBeanServerInterceptor, controller);
070:                server = PASModule.getMBeanServer();
071:            }
072:
073:            public void removeNotificationListener(ObjectName objectName,
074:                    ObjectName objectName1,
075:                    NotificationFilter notificationFilter, Object o)
076:                    throws InstanceNotFoundException, ListenerNotFoundException {
077:                this .interceptorWrapper.removeNotificationListener(objectName,
078:                        objectName1, notificationFilter, o);
079:                try {
080:                    if (auditLogger.isLoggable(Level.INFO)
081:                            && AdminUtil.JMX_DOMAIN.equals(objectName
082:                                    .getDomain())) {
083:                        Hashtable nameValues = new Hashtable();
084:                        nameValues.put(OP_TYPE, LISTEN);
085:                        nameValues.put(OP_NAME, "removeNotificationListener");
086:                        nameValues.put(MBEAN_NAME, objectName.toString());
087:                        nameValues.put(LISTENER, objectName1.toString());
088:                        auditLogger.log(Level.INFO, AuditLogMessage
089:                                .getMessage(nameValues));
090:                    }
091:                } catch (Exception e) {
092:                    //drop-through!
093:                }
094:            }
095:
096:            public void removeNotificationListener(ObjectName objectName,
097:                    NotificationListener notificationListener,
098:                    NotificationFilter notificationFilter, Object o)
099:                    throws InstanceNotFoundException, ListenerNotFoundException {
100:                this .interceptorWrapper.removeNotificationListener(objectName,
101:                        notificationListener, notificationFilter, o);
102:                try {
103:                    if (auditLogger.isLoggable(Level.INFO)
104:                            && AdminUtil.JMX_DOMAIN.equals(objectName
105:                                    .getDomain())) {
106:                        Hashtable nameValues = new Hashtable();
107:                        nameValues.put(OP_TYPE, LISTEN);
108:                        nameValues.put(OP_NAME, "removeNotificationListener");
109:                        nameValues.put(MBEAN_NAME, objectName.toString());
110:                        auditLogger.log(Level.INFO, AuditLogMessage
111:                                .getMessage(nameValues));
112:                    }
113:                } catch (Exception e) {
114:                    //drop-through!
115:                }
116:            }
117:
118:            public ClassLoader getClassLoaderFor(ObjectName objectName)
119:                    throws InstanceNotFoundException {
120:                ClassLoader cl = this .interceptorWrapper
121:                        .getClassLoaderFor(objectName);
122:                try {
123:                    if (auditLogger.isLoggable(Level.FINEST)
124:                            && AdminUtil.JMX_DOMAIN.equals(objectName
125:                                    .getDomain())) {
126:                        Hashtable nameValues = new Hashtable();
127:                        nameValues.put(OP_TYPE, INFO);
128:                        nameValues.put(OP_NAME, "getClassLoaderFor");
129:                        nameValues.put(MBEAN_NAME, objectName.toString());
130:                        auditLogger.log(Level.FINEST, AuditLogMessage
131:                                .getMessage(nameValues));
132:                    }
133:                } catch (Exception e) {
134:                    //drop-through!
135:                }
136:                return cl;
137:            }
138:
139:            public ClassLoader getClassLoader(ObjectName objectName)
140:                    throws InstanceNotFoundException {
141:                ClassLoader cl = this .interceptorWrapper
142:                        .getClassLoader(objectName);
143:                try {
144:                    if (auditLogger.isLoggable(Level.FINEST)) {
145:                        Hashtable nameValues = new Hashtable();
146:                        nameValues.put(OP_TYPE, INFO);
147:                        nameValues.put(OP_NAME, "getClassLoader");
148:                        nameValues.put(MBEAN_NAME, objectName.toString());
149:                        auditLogger.log(Level.FINEST, AuditLogMessage
150:                                .getMessage(nameValues));
151:                    }
152:                } catch (Exception e) {
153:                    //drop-through!
154:                }
155:                return cl;
156:            }
157:
158:            public String[] getDomains() {
159:                return this .interceptorWrapper.getDomains();
160:            }
161:
162:            public ObjectInstance createMBean(String s, ObjectName objectName,
163:                    Object[] objects, String[] strings)
164:                    throws ReflectionException, InstanceAlreadyExistsException,
165:                    MBeanRegistrationException, MBeanException,
166:                    NotCompliantMBeanException {
167:                ObjectInstance obj = this .interceptorWrapper.createMBean(s,
168:                        objectName, objects, strings);
169:                try {
170:                    if (auditLogger.isLoggable(Level.FINE)
171:                            && AdminUtil.JMX_DOMAIN.equals(objectName
172:                                    .getDomain())) {
173:                        Hashtable nameValues = new Hashtable();
174:                        nameValues.put(OP_TYPE, CREATE);
175:                        nameValues.put(OP_NAME, "createMBean");
176:                        nameValues.put(CLASS_NAME, s);
177:                        nameValues.put(MBEAN_NAME, objectName.toString());
178:                        if (objects != null && objects.length > 0) {
179:                            String[] argsNames = getMethodArguments(s, s
180:                                    .substring(s.lastIndexOf(".")), strings,
181:                                    PortalServerLoggingInterceptor.class
182:                                            .getClassLoader());
183:                            fillTable(nameValues, argsNames, objects);
184:                        }
185:                        auditLogger.log(Level.FINE, AuditLogMessage
186:                                .getMessage(nameValues));
187:                    }
188:                } catch (Exception e) {
189:                    //drop-through!
190:                }
191:                return obj;
192:            }
193:
194:            private void fillTable(Hashtable nameValues, String[] argsNames,
195:                    Object[] objects) {
196:                if (argsNames != null && objects != null) {
197:                    for (int i = 0; i < argsNames.length && i < objects.length; i++) {
198:
199:                        if (objects[i] instanceof  Hashtable) {
200:                            Hashtable tmpTable = (Hashtable) ((Hashtable) (objects[i]))
201:                                    .clone();
202:
203:                            // Mask password values
204:                            maskPasswordProperties(tmpTable);
205:                            nameValues.put(argsNames[i], tmpTable);
206:                        } else {
207:                            nameValues.put(argsNames[i], objects[i]);
208:                        }
209:                    }
210:                }
211:            }
212:
213:            public ObjectInstance createMBean(String s, ObjectName objectName,
214:                    ObjectName objectName1, Object[] objects, String[] strings)
215:                    throws ReflectionException, InstanceAlreadyExistsException,
216:                    MBeanRegistrationException, MBeanException,
217:                    NotCompliantMBeanException, InstanceNotFoundException {
218:                ObjectInstance obj = this .interceptorWrapper.createMBean(s,
219:                        objectName, objectName1, objects, strings);
220:                try {
221:                    if (auditLogger.isLoggable(Level.FINE)
222:                            && AdminUtil.JMX_DOMAIN.equals(objectName
223:                                    .getDomain())) {
224:                        Hashtable nameValues = new Hashtable();
225:                        nameValues.put(OP_TYPE, CREATE);
226:                        nameValues.put(OP_NAME, "createMBean");
227:                        nameValues.put(CLASS_NAME, s);
228:                        nameValues.put(MBEAN_NAME, objectName.toString());
229:                        nameValues.put(LOADER_NAME, objectName1.toString());
230:                        if (objects != null && objects.length > 0) {
231:                            String[] argsNames = getMethodArguments(s, s
232:                                    .substring(s.lastIndexOf(".")), strings,
233:                                    PortalServerLoggingInterceptor.class
234:                                            .getClassLoader());
235:                            fillTable(nameValues, argsNames, objects);
236:                        }
237:                        auditLogger.log(Level.FINE, AuditLogMessage
238:                                .getMessage(nameValues));
239:                    }
240:                } catch (Exception e) {
241:                    //drop-through!
242:                }
243:                return obj;
244:            }
245:
246:            public ObjectInstance registerMBean(Object o, ObjectName objectName)
247:                    throws InstanceAlreadyExistsException,
248:                    MBeanRegistrationException, NotCompliantMBeanException {
249:                ObjectInstance obj = this .interceptorWrapper.registerMBean(o,
250:                        objectName);
251:                try {
252:                    if (auditLogger.isLoggable(Level.FINE)
253:                            && AdminUtil.JMX_DOMAIN.equals(objectName
254:                                    .getDomain())) {
255:                        Hashtable nameValues = new Hashtable();
256:                        nameValues.put(OP_TYPE, REGISTER);
257:                        nameValues.put(OP_NAME, "registerMBean");
258:                        nameValues.put(MBEAN_NAME, objectName.toString());
259:                        nameValues.put(MBEAN_OBJECT, o);
260:                        auditLogger.log(Level.FINE, AuditLogMessage
261:                                .getMessage(nameValues));
262:                    }
263:                } catch (Exception e) {
264:                    //drop-through!
265:                }
266:                return obj;
267:            }
268:
269:            public void unregisterMBean(ObjectName objectName)
270:                    throws InstanceNotFoundException,
271:                    MBeanRegistrationException {
272:                this .interceptorWrapper.unregisterMBean(objectName);
273:                try {
274:                    if (auditLogger.isLoggable(Level.INFO)
275:                            && AdminUtil.JMX_DOMAIN.equals(objectName
276:                                    .getDomain())) {
277:                        Hashtable nameValues = new Hashtable();
278:                        nameValues.put(OP_TYPE, UNREGISTER);
279:                        nameValues.put(OP_NAME, "unregisterMBean");
280:                        nameValues.put(MBEAN_NAME, objectName.toString());
281:                        auditLogger.log(Level.INFO, AuditLogMessage
282:                                .getMessage(nameValues));
283:                    }
284:                } catch (Exception e) {
285:                    //drop-through!
286:                }
287:            }
288:
289:            public ObjectInstance getObjectInstance(ObjectName objectName)
290:                    throws InstanceNotFoundException {
291:                ObjectInstance obj = this .interceptorWrapper
292:                        .getObjectInstance(objectName);
293:                try {
294:                    if (auditLogger.isLoggable(Level.FINEST)
295:                            && AdminUtil.JMX_DOMAIN.equals(objectName
296:                                    .getDomain())) {
297:                        Hashtable nameValues = new Hashtable();
298:                        nameValues.put(OP_TYPE, INFO);
299:                        nameValues.put(OP_NAME, "getObjectInstance");
300:                        nameValues.put(MBEAN_NAME, objectName.toString());
301:                        auditLogger.log(Level.FINEST, AuditLogMessage
302:                                .getMessage(nameValues));
303:                    }
304:                } catch (Exception e) {
305:                    //drop-through!
306:                }
307:                return obj;
308:            }
309:
310:            public Set queryMBeans(ObjectName objectName, QueryExp queryExp) {
311:                Set set = this .interceptorWrapper.queryMBeans(objectName,
312:                        queryExp);
313:                try {
314:                    if (auditLogger.isLoggable(Level.FINER)
315:                            && AdminUtil.JMX_DOMAIN.equals(objectName
316:                                    .getDomain())) {
317:                        Hashtable nameValues = new Hashtable();
318:                        nameValues.put(OP_TYPE, QUERY);
319:                        nameValues.put(OP_NAME, "queryMBeans");
320:                        nameValues.put(MBEAN_NAME, objectName.toString());
321:                        nameValues.put(QUERY_EXP, queryExp.toString());
322:                        auditLogger.log(Level.FINER, AuditLogMessage
323:                                .getMessage(nameValues));
324:                    }
325:                } catch (Exception e) {
326:                    //drop-through!
327:                }
328:                return set;
329:            }
330:
331:            public Set queryNames(ObjectName objectName, QueryExp queryExp) {
332:                Set set = this .interceptorWrapper.queryNames(objectName,
333:                        queryExp);
334:                try {
335:                    if (auditLogger.isLoggable(Level.FINER)
336:                            && AdminUtil.JMX_DOMAIN.equals(objectName
337:                                    .getDomain())) {
338:                        Hashtable nameValues = new Hashtable();
339:                        nameValues.put(OP_TYPE, QUERY);
340:                        nameValues.put(OP_NAME, "queryNames");
341:                        nameValues.put(MBEAN_NAME, objectName.toString());
342:                        nameValues.put(QUERY_EXP, queryExp.toString());
343:                        auditLogger.log(Level.FINER, AuditLogMessage
344:                                .getMessage(nameValues));
345:                    }
346:                } catch (Exception e) {
347:                    //drop-through!
348:                }
349:                return set;
350:            }
351:
352:            public boolean isRegistered(ObjectName objectName) {
353:                boolean bool = this .interceptorWrapper.isRegistered(objectName);
354:                try {
355:                    if (auditLogger.isLoggable(Level.FINEST)
356:                            && AdminUtil.JMX_DOMAIN.equals(objectName
357:                                    .getDomain())) {
358:                        Hashtable nameValues = new Hashtable();
359:                        nameValues.put(OP_TYPE, INFO);
360:                        nameValues.put(OP_NAME, "isRegistered");
361:                        nameValues.put(MBEAN_NAME, objectName.toString());
362:                        auditLogger.log(Level.FINEST, AuditLogMessage
363:                                .getMessage(nameValues));
364:                    }
365:                } catch (Exception e) {
366:                    //drop-through!
367:                }
368:                return bool;
369:            }
370:
371:            public Integer getMBeanCount() {
372:                return this .interceptorWrapper.getMBeanCount();
373:            }
374:
375:            public Object getAttribute(ObjectName objectName, String s)
376:                    throws MBeanException, AttributeNotFoundException,
377:                    InstanceNotFoundException, ReflectionException {
378:                Object obj = this .interceptorWrapper
379:                        .getAttribute(objectName, s);
380:                try {
381:                    if (auditLogger.isLoggable(Level.FINER)
382:                            && AdminUtil.JMX_DOMAIN.equals(objectName
383:                                    .getDomain())) {
384:                        Hashtable nameValues = new Hashtable();
385:                        nameValues.put(OP_TYPE, GET);
386:                        nameValues.put(OP_NAME, "getAttribute");
387:                        nameValues.put(MBEAN_NAME, objectName.toString());
388:                        nameValues.put(ATTRIBUTE_NAME, s);
389:                        auditLogger.log(Level.FINER, AuditLogMessage
390:                                .getMessage(nameValues));
391:                    }
392:                } catch (Exception e) {
393:                    //drop-through!
394:                }
395:                return obj;
396:            }
397:
398:            public AttributeList getAttributes(ObjectName objectName,
399:                    String[] strings) throws InstanceNotFoundException,
400:                    ReflectionException {
401:                AttributeList list = this .interceptorWrapper.getAttributes(
402:                        objectName, strings);
403:                try {
404:                    if (auditLogger.isLoggable(Level.FINER)
405:                            && AdminUtil.JMX_DOMAIN.equals(objectName
406:                                    .getDomain())) {
407:                        Hashtable nameValues = new Hashtable();
408:                        nameValues.put(OP_TYPE, GET);
409:                        nameValues.put(OP_NAME, "getAttributes");
410:                        nameValues.put(MBEAN_NAME, objectName.toString());
411:                        if (strings != null && strings.length > 0) {
412:                            String[] attrNames = new String[strings.length];
413:                            fill(attrNames);
414:                            fillTable(nameValues, attrNames, strings);
415:                        }
416:                        auditLogger.log(Level.FINER, AuditLogMessage
417:                                .getMessage(nameValues));
418:                    }
419:                } catch (Exception e) {
420:                    //drop-through!
421:                }
422:                return list;
423:            }
424:
425:            private void fill(String[] attrNames) {
426:                for (int i = 0; i < attrNames.length; i++)
427:                    attrNames[i] = ATTRIBUTE_NAME + (i + 1);
428:            }
429:
430:            public void setAttribute(ObjectName objectName, Attribute attribute)
431:                    throws InstanceNotFoundException,
432:                    AttributeNotFoundException, InvalidAttributeValueException,
433:                    MBeanException, ReflectionException {
434:                Hashtable nameValues = new Hashtable();
435:                try {
436:                    if (auditLogger.isLoggable(Level.INFO)
437:                            && AdminUtil.JMX_DOMAIN.equals(objectName
438:                                    .getDomain())) {
439:                        nameValues.put(OP_TYPE, SET);
440:                        nameValues.put(OP_NAME, "setAttribute");
441:                        nameValues.put(MBEAN_NAME, objectName.toString());
442:                        Object obj = this .interceptorWrapper.getAttribute(
443:                                objectName, attribute.getName());
444:                        nameValues.put("Old_" + attribute.getName(), obj);
445:                    }
446:                } catch (Exception e) {
447:                    //drop-through!
448:                }
449:
450:                this .interceptorWrapper.setAttribute(objectName, attribute);
451:                try {
452:                    if (auditLogger.isLoggable(Level.INFO)
453:                            && AdminUtil.JMX_DOMAIN.equals(objectName
454:                                    .getDomain())) {
455:                        nameValues.put(attribute.getName(), attribute
456:                                .getValue());
457:                        //Mask cleartext password values.
458:                        maskPasswordProperties(nameValues);
459:                        auditLogger.log(Level.INFO, AuditLogMessage
460:                                .getMessage(nameValues));
461:                    }
462:                } catch (Exception e) {
463:                    //drop-through!
464:                }
465:            }
466:
467:            private String[] getAttributeNames(AttributeList attributeList) {
468:                String[] attributes = new String[attributeList.size()];
469:                Iterator it = attributeList.iterator();
470:                int i = 0;
471:                while (it.hasNext()) {
472:                    attributes[i] = ((Attribute) it.next()).getName();
473:                    i++;
474:                }
475:                return attributes;
476:            }
477:
478:            public AttributeList setAttributes(ObjectName objectName,
479:                    AttributeList attributeList)
480:                    throws InstanceNotFoundException, ReflectionException {
481:                Hashtable nameValues = new Hashtable();
482:                try {
483:                    if (auditLogger.isLoggable(Level.INFO)
484:                            && AdminUtil.JMX_DOMAIN.equals(objectName
485:                                    .getDomain())) {
486:                        nameValues.put(OP_TYPE, SET);
487:                        nameValues.put(OP_NAME, "setAttributes");
488:                        nameValues.put(MBEAN_NAME, objectName.toString());
489:                        AttributeList oldAttributeList = this .interceptorWrapper
490:                                .getAttributes(objectName,
491:                                        getAttributeNames(attributeList));
492:                        if (oldAttributeList != null) {
493:                            fillOldAttributes(nameValues, oldAttributeList);
494:                        }
495:                    }
496:                } catch (Exception e) {
497:                    //drop-through
498:                }
499:                AttributeList list = this .interceptorWrapper.setAttributes(
500:                        objectName, attributeList);
501:                try {
502:                    if (auditLogger.isLoggable(Level.INFO)
503:                            && AdminUtil.JMX_DOMAIN.equals(objectName
504:                                    .getDomain())) {
505:                        if (attributeList != null)
506:                            fillAttributes(nameValues, attributeList);
507:                        //Mask any cleartext password values.
508:                        maskPasswordProperties(nameValues);
509:                        auditLogger.log(Level.INFO, AuditLogMessage
510:                                .getMessage(nameValues));
511:                    }
512:                } catch (Exception e) {
513:                    //drop-through!
514:                }
515:                return list;
516:            }
517:
518:            private void fillOldAttributes(Hashtable nameValues,
519:                    AttributeList oldAttributeList) {
520:                Iterator it = oldAttributeList.iterator();
521:                while (it.hasNext()) {
522:                    Attribute attr = (Attribute) it.next();
523:                    nameValues.put("Old_" + attr.getName(), attr.getValue());
524:                }
525:            }
526:
527:            private void fillAttributes(Hashtable nameValues,
528:                    AttributeList attributeList) {
529:                Iterator it = attributeList.iterator();
530:                while (it.hasNext()) {
531:                    Attribute attr = (Attribute) it.next();
532:                    nameValues.put(attr.getName(), attr.getValue());
533:                }
534:            }
535:
536:            public Object invoke(ObjectName objectName, String s,
537:                    Object[] objects, String[] strings)
538:                    throws InstanceNotFoundException, MBeanException,
539:                    ReflectionException {
540:                Object obj = this .interceptorWrapper.invoke(objectName, s,
541:                        objects, strings);
542:                try {
543:                    if (auditLogger.isLoggable(Level.INFO)
544:                            && AdminUtil.JMX_DOMAIN.equals(objectName
545:                                    .getDomain())) {
546:                        Hashtable nameValues = new Hashtable();
547:                        nameValues.put(OP_TYPE, INVOKE);
548:                        nameValues.put(OP_NAME, "invoke");
549:                        nameValues.put(MBEAN_NAME, objectName.toString());
550:                        nameValues.put(METHOD_NAME, s);
551:                        if (objects != null && objects.length > 0) {
552:                            fillTable(nameValues, getMethodArguments(server
553:                                    .getObjectInstance(objectName)
554:                                    .getClassName(), s, strings,
555:                                    PortalServerLoggingInterceptor.class
556:                                            .getClassLoader()), objects);
557:                            auditLogger.log(Level.INFO, AuditLogMessage
558:                                    .getMessage(nameValues));
559:                        }
560:                    }
561:                } catch (Exception e) {
562:                    //drop-through!
563:                }
564:                return obj;
565:            }
566:
567:            public String getDefaultDomain() {
568:                return this .interceptorWrapper.getDefaultDomain();
569:            }
570:
571:            public void addNotificationListener(ObjectName objectName,
572:                    NotificationListener notificationListener,
573:                    NotificationFilter notificationFilter, Object o)
574:                    throws InstanceNotFoundException {
575:                this .interceptorWrapper.addNotificationListener(objectName,
576:                        notificationListener, notificationFilter, o);
577:                try {
578:                    if (auditLogger.isLoggable(Level.FINER)
579:                            && AdminUtil.JMX_DOMAIN.equals(objectName
580:                                    .getDomain())) {
581:                        Hashtable nameValues = new Hashtable();
582:                        nameValues.put(OP_TYPE, LISTEN);
583:                        nameValues.put(OP_NAME, "addNotificationListener");
584:                        nameValues.put(MBEAN_NAME, objectName.toString());
585:                        auditLogger.log(Level.FINER, AuditLogMessage
586:                                .getMessage(nameValues));
587:                    }
588:                } catch (Exception e) {
589:                    //drop-through!
590:                }
591:            }
592:
593:            public void addNotificationListener(ObjectName objectName,
594:                    ObjectName objectName1,
595:                    NotificationFilter notificationFilter, Object o)
596:                    throws InstanceNotFoundException {
597:                this .interceptorWrapper.addNotificationListener(objectName,
598:                        objectName1, notificationFilter, o);
599:                try {
600:                    if (auditLogger.isLoggable(Level.FINER)
601:                            && AdminUtil.JMX_DOMAIN.equals(objectName
602:                                    .getDomain())) {
603:                        Hashtable nameValues = new Hashtable();
604:                        nameValues.put(OP_TYPE, LISTEN);
605:                        nameValues.put(OP_NAME, "addNotificationListener");
606:                        nameValues.put(MBEAN_NAME, objectName.toString());
607:                        nameValues.put(LISTENER, objectName1.toString());
608:                        auditLogger.log(Level.FINER, AuditLogMessage
609:                                .getMessage(nameValues));
610:                    }
611:                } catch (Exception e) {
612:                    //drop-through!
613:                }
614:            }
615:
616:            public void removeNotificationListener(ObjectName objectName,
617:                    ObjectName objectName1) throws InstanceNotFoundException,
618:                    ListenerNotFoundException {
619:                this .interceptorWrapper.removeNotificationListener(objectName,
620:                        objectName1);
621:                try {
622:                    if (auditLogger.isLoggable(Level.INFO)
623:                            && AdminUtil.JMX_DOMAIN.equals(objectName
624:                                    .getDomain())) {
625:                        Hashtable nameValues = new Hashtable();
626:                        nameValues.put(OP_TYPE, LISTEN);
627:                        nameValues.put(OP_NAME, "removeNotificationListener");
628:                        nameValues.put(MBEAN_NAME, objectName.toString());
629:                        nameValues.put(LISTENER, objectName1.toString());
630:                        auditLogger.log(Level.INFO, AuditLogMessage
631:                                .getMessage(nameValues));
632:                    }
633:                } catch (Exception e) {
634:                    //drop-through!
635:                }
636:            }
637:
638:            public void removeNotificationListener(ObjectName objectName,
639:                    NotificationListener notificationListener)
640:                    throws InstanceNotFoundException, ListenerNotFoundException {
641:                this .interceptorWrapper.removeNotificationListener(objectName,
642:                        notificationListener);
643:                try {
644:                    if (auditLogger.isLoggable(Level.INFO)
645:                            && AdminUtil.JMX_DOMAIN.equals(objectName
646:                                    .getDomain())) {
647:                        Hashtable nameValues = new Hashtable();
648:                        nameValues.put(OP_TYPE, LISTEN);
649:                        nameValues.put(OP_NAME, "removeNotificationListener");
650:                        nameValues.put(MBEAN_NAME, objectName.toString());
651:                        auditLogger.log(Level.INFO, AuditLogMessage
652:                                .getMessage(nameValues));
653:                    }
654:                } catch (Exception e) {
655:                    //drop-through!
656:                }
657:            }
658:
659:            public MBeanInfo getMBeanInfo(ObjectName objectName)
660:                    throws InstanceNotFoundException, IntrospectionException,
661:                    ReflectionException {
662:                MBeanInfo inf = this .interceptorWrapper
663:                        .getMBeanInfo(objectName);
664:                try {
665:                    if (auditLogger.isLoggable(Level.FINEST)
666:                            && AdminUtil.JMX_DOMAIN.equals(objectName
667:                                    .getDomain())) {
668:                        Hashtable nameValues = new Hashtable();
669:                        nameValues.put(OP_TYPE, INFO);
670:                        nameValues.put(OP_NAME, "getMBeanInfo");
671:                        nameValues.put(MBEAN_NAME, objectName.toString());
672:                        auditLogger.log(Level.FINEST, AuditLogMessage
673:                                .getMessage(nameValues));
674:                    }
675:                } catch (Exception e) {
676:                    //drop-through!
677:                }
678:                return inf;
679:            }
680:
681:            public boolean isInstanceOf(ObjectName objectName, String s)
682:                    throws InstanceNotFoundException {
683:                boolean bool = this .interceptorWrapper.isInstanceOf(objectName,
684:                        s);
685:                try {
686:                    if (auditLogger.isLoggable(Level.FINEST)
687:                            && AdminUtil.JMX_DOMAIN.equals(objectName
688:                                    .getDomain())) {
689:                        Hashtable nameValues = new Hashtable();
690:                        nameValues.put(OP_TYPE, INFO);
691:                        nameValues.put(OP_NAME, "isInstanceOf");
692:                        nameValues.put(MBEAN_NAME, objectName.toString());
693:                        nameValues.put(CLASS_NAME, s);
694:                        auditLogger.log(Level.FINEST, AuditLogMessage
695:                                .getMessage(nameValues));
696:                    }
697:                } catch (Exception e) {
698:                    //drop-through!
699:                }
700:                return bool;
701:            }
702:
703:            public ClassLoader getMBeanClassLoader(ObjectName objectName)
704:                    throws InstanceNotFoundException {
705:                ClassLoader cl = this .interceptorWrapper
706:                        .getMBeanClassLoader(objectName);
707:                try {
708:                    if (auditLogger.isLoggable(Level.FINEST)
709:                            && AdminUtil.JMX_DOMAIN.equals(objectName
710:                                    .getDomain())) {
711:                        Hashtable nameValues = new Hashtable();
712:                        nameValues.put(OP_TYPE, INFO);
713:                        nameValues.put(OP_NAME, "getMBeanClassLoader");
714:                        nameValues.put(MBEAN_NAME, objectName.toString());
715:                        auditLogger.log(Level.FINEST, AuditLogMessage
716:                                .getMessage(nameValues));
717:                    }
718:                } catch (Exception e) {
719:                    //drop-through!
720:                }
721:                return cl;
722:            }
723:
724:            /**
725:             * *
726:             * Non-Interceptor methods
727:             * **
728:             */
729:            private String[] getArgumentNames(ObjectName objectName,
730:                    String method, String[] signature)
731:                    throws InstanceNotFoundException {
732:                String className = server.getObjectInstance(objectName)
733:                        .getClassName();
734:                return getMethodArguments(className, method, signature,
735:                        PortalServerLoggingInterceptor.class.getClassLoader());
736:
737:            }
738:
739:            public String[] getMethodArguments(String className, String method,
740:                    String[] signature, ClassLoader loader) {
741:                String classFile = className.replace('.', '/');
742:                JavaClass bclass = (JavaClass) clazzCache.get(classFile);
743:                try {
744:                    if (bclass == null) {
745:                        InputStream is = loader.getResourceAsStream(classFile
746:                                + ".class");
747:                        ClassParser parser = new ClassParser(is, className);
748:                        bclass = parser.parse();
749:                        clazzCache.put(classFile, bclass);
750:                    }
751:                    org.apache.bcel.classfile.Method[] methods = bclass
752:                            .getMethods();
753:                    org.apache.bcel.classfile.Method this Method = null;
754:                    for (int i = 0; i < methods.length; i++) {
755:                        if (method.equals(methods[i].getName())) {
756:                            Type[] argumentTypes = methods[i]
757:                                    .getArgumentTypes();
758:                            if (argumentTypes.length == signature.length) {
759:                                int k = 0;
760:                                for (k = 0; k < argumentTypes.length; k++) {
761:                                    if (!signature[k]
762:                                            .equals(javaSignature(argumentTypes[k]
763:                                                    .getSignature())))
764:                                        break;
765:                                }
766:                                if (k == argumentTypes.length) {
767:                                    this Method = methods[i];
768:                                    break;
769:                                }
770:                            }
771:                        }
772:                    }
773:                    if (this Method == null)
774:                        return null;
775:                    // Get the Code object, which contains the local variable table.
776:                    int numParams = signature.length;
777:                    Vector temp = new Vector();
778:                    Code code = this Method.getCode();
779:                    if (code == null)
780:                        return null;
781:
782:                    LocalVariableTable attr = this Method
783:                            .getLocalVariableTable();
784:                    if (attr == null)
785:                        return null;
786:
787:                    LocalVariable[] vars = attr.getLocalVariableTable();
788:
789:                    String[] argNames = new String[numParams];
790:
791:                    for (int j = 0; j < vars.length; j++) {
792:                        LocalVariable var = vars[j];
793:                        if (!var.getName().equals("this")) {
794:                            if (temp.size() < var.getIndex() + 1)
795:                                temp.setSize(var.getIndex() + 1);
796:                            temp.setElementAt(var.getName(), var.getIndex());
797:                        }
798:                    }
799:                    int k = 0;
800:                    for (int j = 0; j < temp.size(); j++) {
801:                        if (temp.elementAt(j) != null) {
802:                            argNames[k] = (String) temp.elementAt(j);
803:                            k++;
804:                            if (k == argNames.length)
805:                                break;
806:                        }
807:                    }
808:                    return argNames;
809:
810:                } catch (IOException e) {
811:                    //drop-through
812:                }
813:
814:                return null;
815:            }
816:
817:            private String javaSignature(String sig) {
818:                String javaSig = sig.replace('/', '.');
819:                if (javaSig.startsWith("L") && javaSig.endsWith(";"))
820:                    javaSig = javaSig.substring(1, javaSig.length() - 1);
821:                return javaSig;
822:            }
823:
824:            public static void main(String[] args)
825:                    throws MalformedObjectNameException,
826:                    NotCompliantMBeanException, MBeanRegistrationException,
827:                    InstanceAlreadyExistsException {
828:                MBeanServer myMBeanServer = MBeanServerFactory
829:                        .createMBeanServer();
830:                CommunicatorServer htmlAdaptor = new HtmlAdaptorServer();
831:                try {
832:                    // We let the html protocol adaptor provides its default name
833:                    ObjectInstance htmlAdaptorInstance = myMBeanServer
834:                            .registerMBean(htmlAdaptor, null);
835:                    htmlAdaptorInstance.getObjectName().toString();
836:                } catch (Exception e) {
837:                    e.printStackTrace();
838:                    System.exit(1);
839:                }
840:                htmlAdaptor.start();
841:                MBeanServerInterceptor defaultInterceptor = ((JdmkMBeanServer) myMBeanServer)
842:                        .getMBeanServerInterceptor();
843:                final MBeanServerInterceptor master = new PortalServerLoggingInterceptor(
844:                        defaultInterceptor, null);
845:                ((JdmkMBeanServer) myMBeanServer)
846:                        .setMBeanServerInterceptor(master);
847:                myMBeanServer.registerMBean(new Timer(), new ObjectName(
848:                        ServiceName.DOMAIN + ":name=Timer"));
849:
850:                myMBeanServer.registerMBean(new Timer(), new ObjectName(
851:                        ServiceName.DOMAIN + ":name=Timer22"));
852:                System.out
853:                        .println(((PortalServerLoggingInterceptor) master)
854:                                .getMethodArguments(
855:                                        com.sun.portal.admin.server.PortalServerLoggingInterceptor.class
856:                                                .getName(), "invoke",
857:                                        new String[] {
858:                                                ObjectName.class.getName(),
859:                                                String.class.getName(),
860:                                                Object[].class.getName(),
861:                                                String[].class.getName() },
862:                                        ClassLoader.getSystemClassLoader()));
863:
864:            }
865:
866:            /**
867:             * This function masks the values of password keys.
868:             */
869:            private void maskPasswordProperties(Hashtable nameVal) {
870:                Enumeration keys = nameVal.keys();
871:                while (keys.hasMoreElements()) {
872:                    String key = (String) keys.nextElement();
873:                    if (key.toLowerCase().indexOf("password") >= 0) {
874:                        nameVal.put(key, maskedPassword);
875:                    }
876:                }
877:
878:            }
879:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.