Search in sources :

Example 1 with BaseAuditModule

use of com.sun.enterprise.security.BaseAuditModule in project Payara by payara.

the class BaseAuditManager method loadAuditModules.

/**
 * This method initializes BaseAuditManager which load audit modules and
 * audit enabled flag
 */
@Override
public void loadAuditModules() {
    try {
        SecurityService securityBean = serverContext.getDefaultServices().getService(SecurityService.class, ServerEnvironment.DEFAULT_INSTANCE_NAME);
        assert (securityBean != null);
        // @todo will be removed to incorporate the new structure.
        // v3:Commented boolean auditFlag = securityBean.isAuditEnabled();
        boolean auditFlag = Boolean.parseBoolean(securityBean.getAuditEnabled());
        setAuditOn(auditFlag);
        /*V3:Commented
            com.sun.enterprise.config.serverbeans.AuditModule[] am =
                    securityBean.getAuditModule();*/
        List<com.sun.enterprise.config.serverbeans.AuditModule> am = securityBean.getAuditModule();
        for (com.sun.enterprise.config.serverbeans.AuditModule it : am) {
            // V3:Commented for (int i = 0; i < am.length; i++){
            try {
                // V3:Commented String name = am[i].getName();
                // V3:Commented String classname = am[i].getClassname();
                String name = it.getName();
                String classname = it.getClassname();
                Properties p = new Properties();
                // XXX should we remove this two extra properties
                p.setProperty(NAME, name);
                p.setProperty(CLASSNAME, classname);
                List<Property> ep = it.getProperty();
                /*V3:Commented
                    ElementProperty[] ep = am[i].getElementProperty();
                    int epsize = am[i].sizeElementProperty();
                    for (int j = 0; j < epsize; j++){
                        String nme = ep[j].getName();
                        String val = ep[j].getValue();
                        p.setProperty(nme, val);
                    }*/
                for (Property prop : ep) {
                    p.setProperty(prop.getName(), prop.getValue());
                }
                BaseAuditModule auditModule = loadAuditModule(classname, p);
                instances.add(auditModule);
                moduleToNameMap.put(auditModule, name);
                nameToModuleMap.put(name, auditModule);
                if (isAuditModuleOfParameterizedType(auditModule)) {
                    typedModules.add((T) auditModule);
                }
            } catch (Exception ex) {
                String msg = _localStrings.getLocalString("auditmgr.loaderror", "Audit: Cannot load AuditModule = {0}", // V3:Commented new Object[]{ am[i].getName() });
                new Object[] { it.getName() });
                _logger.log(Level.WARNING, msg, ex);
            }
        }
    } catch (Exception e) {
        String msg = _localStrings.getLocalString("auditmgr.badinit", "Audit: Cannot load Audit Module Initialization information. AuditModules will not be loaded.");
        _logger.log(Level.WARNING, msg, e);
    }
}
Also used : AuditModule(com.sun.enterprise.config.serverbeans.AuditModule) Properties(java.util.Properties) SecurityService(com.sun.enterprise.config.serverbeans.SecurityService) AuditModule(com.sun.enterprise.config.serverbeans.AuditModule) BaseAuditModule(com.sun.enterprise.security.BaseAuditModule) Property(org.jvnet.hk2.config.types.Property) BaseAuditModule(com.sun.enterprise.security.BaseAuditModule)

Example 2 with BaseAuditModule

use of com.sun.enterprise.security.BaseAuditModule in project Payara by payara.

the class BaseAuditManager method loadAuditModule.

/**
 * This method return auditModule with given classname and properties.
 * @param classname
 * @param props
 * @exception
 */
private BaseAuditModule loadAuditModule(String classname, Properties props) throws Exception {
    BaseAuditModule auditModule;
    ClassLoader loader = Thread.currentThread().getContextClassLoader();
    Class am = Class.forName(classname, true, loader);
    Object obj = am.newInstance();
    auditModule = (BaseAuditModule) obj;
    auditModule.init(props);
    return auditModule;
}
Also used : BaseAuditModule(com.sun.enterprise.security.BaseAuditModule)

Example 3 with BaseAuditModule

use of com.sun.enterprise.security.BaseAuditModule in project Payara by payara.

the class BaseAuditManager method removeAuditModule.

/**
 * Remove the audit module of given name from the loaded list.
 * @param name of auditModule
 */
public BaseAuditModule removeAuditModule(String name) {
    final BaseAuditModule am = nameToModuleMap.get(name);
    if (am != null) {
        nameToModuleMap.remove(name);
        moduleToNameMap.remove(am);
        // clone list to resolve multi-thread issues in looping instances
        instances = copyAndRemove(instances, am);
        if (isAuditModuleOfParameterizedType(am)) {
            typedModules = copyAndRemove(typedModules, (T) am);
        }
    }
    return am;
}
Also used : BaseAuditModule(com.sun.enterprise.security.BaseAuditModule)

Example 4 with BaseAuditModule

use of com.sun.enterprise.security.BaseAuditModule in project Payara by payara.

the class BaseAuditManager method addAuditModule.

/**
 * Add the given audit module to the list of loaded audit module.
 * Adding the same name twice will override previous one.
 * @param name of auditModule
 * @param am an instance of a class extending BaseAuditModule that has been
 * successfully loaded into the system.
 * @exception
 */
public BaseAuditModule addAuditModule(String name, String classname, Properties props) throws Exception {
    // make sure only a name corresponding to only one auditModule
    removeAuditModule(name);
    BaseAuditModule am = loadAuditModule(classname, props);
    moduleToNameMap.put(am, name);
    nameToModuleMap.put(name, am);
    // clone list to resolve multi-thread issues in looping instances
    instances = copyAndAdd(instances, am);
    if (isAuditModuleOfParameterizedType(am)) {
        typedModules = copyAndAdd(typedModules, (T) am);
    }
    return am;
}
Also used : BaseAuditModule(com.sun.enterprise.security.BaseAuditModule)

Aggregations

BaseAuditModule (com.sun.enterprise.security.BaseAuditModule)4 AuditModule (com.sun.enterprise.config.serverbeans.AuditModule)1 SecurityService (com.sun.enterprise.config.serverbeans.SecurityService)1 Properties (java.util.Properties)1 Property (org.jvnet.hk2.config.types.Property)1