Search in sources :

Example 1 with AuditModule

use of com.sun.enterprise.config.serverbeans.AuditModule in project Payara by payara.

the class DeleteAuditModule method chooseAuditModule.

private AuditModule chooseAuditModule(final ActionReport report) {
    config = CLIUtil.chooseConfig(domain, target, report);
    if (config == null) {
        return null;
    }
    securityService = config.getSecurityService();
    for (AuditModule am : securityService.getAuditModule()) {
        if (am.getName().equals(auditModuleName)) {
            return am;
        }
    }
    return null;
}
Also used : AuditModule(com.sun.enterprise.config.serverbeans.AuditModule)

Example 2 with AuditModule

use of com.sun.enterprise.config.serverbeans.AuditModule in project Payara by payara.

the class ListAuditModule method execute.

/**
 * Executes the command with the command parameters passed as Properties
 * where the keys are the paramter names and the values the parameter values
 *
 * @param context information
 */
public void execute(AdminCommandContext context) {
    final ActionReport report = context.getActionReport();
    report.getTopMessagePart().setChildrenType("audit-module");
    for (AuditModule am : securityService.getAuditModule()) {
        ActionReport.MessagePart part = report.getTopMessagePart().addChild();
        part.setMessage(am.getName());
    }
}
Also used : AuditModule(com.sun.enterprise.config.serverbeans.AuditModule) ActionReport(org.glassfish.api.ActionReport)

Example 3 with AuditModule

use of com.sun.enterprise.config.serverbeans.AuditModule 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 4 with AuditModule

use of com.sun.enterprise.config.serverbeans.AuditModule in project Payara by payara.

the class CreateAuditModule method execute.

/**
 * Executes the command with the command parameters passed as Properties
 * where the keys are paramter names and the values the parameter values
 *
 * @param context information
 */
public void execute(AdminCommandContext context) {
    final ActionReport report = context.getActionReport();
    // check if there exists an audit module by the specified name
    // if so return failure.
    List<AuditModule> ams = securityService.getAuditModule();
    for (AuditModule am : ams) {
        if (am.getName().equals(auditModuleName)) {
            report.setMessage(localStrings.getLocalString("create.audit.module.duplicatefound", "AuditModule named {0} exists. " + "Cannot add duplicate AuditModule.", auditModuleName));
            report.setActionExitCode(ActionReport.ExitCode.FAILURE);
            return;
        }
    }
    // No duplicate audit modules found. So add one.
    try {
        ConfigSupport.apply(new SingleConfigCode<SecurityService>() {

            public Object run(SecurityService param) throws PropertyVetoException, TransactionFailure {
                AuditModule newAuditModule = param.createChild(AuditModule.class);
                populateAuditModuleElement(newAuditModule);
                param.getAuditModule().add(newAuditModule);
                return newAuditModule;
            }
        }, securityService);
    } catch (TransactionFailure e) {
        report.setMessage(localStrings.getLocalString("create.audit.module.fail", "Creation of AuditModule {0} failed", auditModuleName));
        report.setActionExitCode(ActionReport.ExitCode.FAILURE);
        report.setFailureCause(e);
        return;
    }
    report.setActionExitCode(ActionReport.ExitCode.SUCCESS);
// report.setMessage(localStrings.getLocalString("create.audit.module.success",
// "Creation of AuditModule {0} completed successfully", auditModuleName));
}
Also used : PropertyVetoException(java.beans.PropertyVetoException) TransactionFailure(org.jvnet.hk2.config.TransactionFailure) SecurityService(com.sun.enterprise.config.serverbeans.SecurityService) AuditModule(com.sun.enterprise.config.serverbeans.AuditModule) ActionReport(org.glassfish.api.ActionReport)

Aggregations

AuditModule (com.sun.enterprise.config.serverbeans.AuditModule)4 SecurityService (com.sun.enterprise.config.serverbeans.SecurityService)2 ActionReport (org.glassfish.api.ActionReport)2 BaseAuditModule (com.sun.enterprise.security.BaseAuditModule)1 PropertyVetoException (java.beans.PropertyVetoException)1 Properties (java.util.Properties)1 TransactionFailure (org.jvnet.hk2.config.TransactionFailure)1 Property (org.jvnet.hk2.config.types.Property)1