FileDocCategorySizeDatePackage
AuditModuleEventListenerImpl.javaAPI DocGlassfish v2 API6848Fri May 04 22:35:24 BST 2007com.sun.enterprise.security.audit

AuditModuleEventListenerImpl

public class AuditModuleEventListenerImpl extends Object implements com.sun.enterprise.admin.event.AuditModuleEventListener
Listener interface to handle audit module events. So that audit module can be dynamically created/update/deleted.
author
Shing Wai Chan

Fields Summary
Constructors Summary
Methods Summary
public voidauditModuleCreated(com.sun.enterprise.admin.event.AuditModuleEvent event)
New audit module created. It is called whenever a AuditModuleEvent with action of AuditModuleEvent.ACTION_CREATE is received.

throws
AdminEventListenerException when the listener is unable to process the event.

        try {
            String moduleName = event.getModuleName();
            AuditModule am = getAuditModule(moduleName,
                    event.getConfigContext());
            String classname = am.getClassname();
            Properties props = getAuditModuleProperties(am);      

            AuditManager manager =
                    AuditManagerFactory.getInstance().getAuditManagerInstance();
            manager.addAuditModule(moduleName, classname, props);
        } catch(Exception ex) {
            throw new AdminEventListenerException(ex);
        }
    
public voidauditModuleDeleted(com.sun.enterprise.admin.event.AuditModuleEvent event)
Audit module deleted. It is called whenever a AuditModuleEvent with action of AuditModuleEvent.ACTION_DELETE is received.

throws
AdminEventListenerException when the listener is unable to process the event.

        try {
            String moduleName = event.getModuleName();
            AuditManager manager =
                    AuditManagerFactory.getInstance().getAuditManagerInstance();
            manager.removeAuditModule(moduleName);
        } catch(Exception ex) {
            throw new AdminEventListenerException(ex);
        }
    
public voidauditModuleUpdated(com.sun.enterprise.admin.event.AuditModuleEvent event)
Audit module updated (attributes change). It is called whenever a AuditModuleEvent with action of AuditModuleEvent.ACTION_UPDATE is received.

throws
AdminEventListenerException when the listener is unable to process the event.

        try {
            String moduleName = event.getModuleName();

            AuditModule am = getAuditModule(moduleName,
                    event.getConfigContext());
            String classname = am.getClassname();
            Properties props = getAuditModuleProperties(am);      

            AuditModule oldAm = getAuditModule(moduleName,
                    event.getOldConfigContext());
            String oldClassname = oldAm.getClassname();
            Properties oldProps = getAuditModuleProperties(oldAm);      

            AuditManager manager =
                    AuditManagerFactory.getInstance().getAuditManagerInstance();
            if (!classname.equals(oldClassname)) {
                manager.addAuditModule(moduleName, classname, props);
            } else if (!props.equals(oldProps)) {
                com.sun.appserv.security.AuditModule auditModule =
                        manager.getAuditModule(moduleName);
                auditModule.init(props);
            }
        } catch(Exception ex) {
            throw new AdminEventListenerException(ex);
        }
    
private com.sun.enterprise.config.serverbeans.AuditModulegetAuditModule(java.lang.String moduleName, com.sun.enterprise.config.ConfigContext configContext)

        SecurityService security = 
            ServerBeansFactory.getSecurityServiceBean(configContext);
        return security.getAuditModuleByName(moduleName);

    
private java.util.PropertiesgetAuditModuleProperties(com.sun.enterprise.config.serverbeans.AuditModule am)

        ElementProperty[] elementProps = am.getElementProperty();
        int size = (elementProps != null) ? elementProps.length : 0;
        Properties props = new Properties();
        //XXX should we set this?
        props.setProperty(AuditManager.NAME, am.getName());
        props.setProperty(AuditManager.CLASSNAME, am.getClassname());
        for (int i = 0; i < size; i++) {
            props.setProperty(elementProps[i].getName(),
                    elementProps[i].getValue());
        }
        return props;