1 23 24 package com.sun.enterprise.security.audit; 25 26 import java.util.Properties ; 27 28 import com.sun.enterprise.config.ConfigContext; 29 import com.sun.enterprise.config.ConfigException; 30 import com.sun.enterprise.config.serverbeans.AuditModule; 31 import com.sun.enterprise.config.serverbeans.ElementProperty; 32 import com.sun.enterprise.config.serverbeans.SecurityService; 33 import com.sun.enterprise.config.serverbeans.ServerBeansFactory; 34 import com.sun.enterprise.admin.event.AdminEventListenerException; 35 import com.sun.enterprise.admin.event.AuditModuleEvent; 36 import com.sun.enterprise.admin.event.AuditModuleEventListener; 37 38 43 public class AuditModuleEventListenerImpl implements AuditModuleEventListener { 44 45 52 public void auditModuleCreated(AuditModuleEvent event) 53 throws AdminEventListenerException { 54 try { 55 String moduleName = event.getModuleName(); 56 AuditModule am = getAuditModule(moduleName, 57 event.getConfigContext()); 58 String classname = am.getClassname(); 59 Properties props = getAuditModuleProperties(am); 60 61 AuditManager manager = 62 AuditManagerFactory.getInstance().getAuditManagerInstance(); 63 manager.addAuditModule(moduleName, classname, props); 64 } catch(Exception ex) { 65 throw new AdminEventListenerException(ex); 66 } 67 } 68 69 76 public void auditModuleDeleted(AuditModuleEvent event) 77 throws AdminEventListenerException { 78 try { 79 String moduleName = event.getModuleName(); 80 AuditManager manager = 81 AuditManagerFactory.getInstance().getAuditManagerInstance(); 82 manager.removeAuditModule(moduleName); 83 } catch(Exception ex) { 84 throw new AdminEventListenerException(ex); 85 } 86 } 87 88 95 public void auditModuleUpdated(AuditModuleEvent event) 96 throws AdminEventListenerException { 97 try { 98 String moduleName = event.getModuleName(); 99 100 AuditModule am = getAuditModule(moduleName, 101 event.getConfigContext()); 102 String classname = am.getClassname(); 103 Properties props = getAuditModuleProperties(am); 104 105 AuditModule oldAm = getAuditModule(moduleName, 106 event.getOldConfigContext()); 107 String oldClassname = oldAm.getClassname(); 108 Properties oldProps = getAuditModuleProperties(oldAm); 109 110 AuditManager manager = 111 AuditManagerFactory.getInstance().getAuditManagerInstance(); 112 if (!classname.equals(oldClassname)) { 113 manager.addAuditModule(moduleName, classname, props); 114 } else if (!props.equals(oldProps)) { 115 com.sun.appserv.security.AuditModule auditModule = 116 manager.getAuditModule(moduleName); 117 auditModule.init(props); 118 } 119 } catch(Exception ex) { 120 throw new AdminEventListenerException(ex); 121 } 122 } 123 124 private AuditModule getAuditModule(String moduleName, 125 ConfigContext configContext) throws ConfigException { 126 SecurityService security = 127 ServerBeansFactory.getSecurityServiceBean(configContext); 128 return security.getAuditModuleByName(moduleName); 129 130 } 131 132 private Properties getAuditModuleProperties(AuditModule am) { 133 ElementProperty[] elementProps = am.getElementProperty(); 134 int size = (elementProps != null) ? elementProps.length : 0; 135 Properties props = new Properties (); 136 props.setProperty(AuditManager.NAME, am.getName()); 138 props.setProperty(AuditManager.CLASSNAME, am.getClassname()); 139 for (int i = 0; i < size; i++) { 140 props.setProperty(elementProps[i].getName(), 141 elementProps[i].getValue()); 142 } 143 return props; 144 } 145 } 146 | Popular Tags |