- /*
- * GovWay - A customizable API Gateway
- * https://govway.org
- *
- * Copyright (c) 2005-2025 Link.it srl (https://link.it).
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License version 3, as published by
- * the Free Software Foundation.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- *
- */
- package org.openspcoop2.web.ctrlstat.servlet.config;
- import java.util.List;
- import javax.servlet.http.HttpServletRequest;
- import javax.servlet.http.HttpServletResponse;
- import javax.servlet.http.HttpSession;
- import org.apache.struts.action.Action;
- import org.apache.struts.action.ActionForm;
- import org.apache.struts.action.ActionForward;
- import org.apache.struts.action.ActionMapping;
- import org.openspcoop2.web.ctrlstat.core.ControlStationCore;
- import org.openspcoop2.web.ctrlstat.servlet.GeneralHelper;
- import org.openspcoop2.web.ctrlstat.servlet.audit.AuditingCore;
- import org.openspcoop2.web.lib.audit.dao.Appender;
- import org.openspcoop2.web.lib.audit.dao.AppenderProperty;
- import org.openspcoop2.web.lib.audit.dao.Configurazione;
- import org.openspcoop2.web.lib.audit.web.AuditCostanti;
- import org.openspcoop2.web.lib.audit.web.AuditHelper;
- import org.openspcoop2.web.lib.mvc.Costanti;
- import org.openspcoop2.web.lib.mvc.DataElement;
- import org.openspcoop2.web.lib.mvc.GeneralData;
- import org.openspcoop2.web.lib.mvc.PageData;
- import org.openspcoop2.web.lib.mvc.ServletUtils;
- /**
- * auditing
- *
- * @author Andrea Poli (apoli@link.it)
- * @author Stefano Corallo (corallo@link.it)
- * @author Sandra Giangrandi (sandra@link.it)
- * @author $Author$
- * @version $Rev$, $Date$
- *
- */
- public final class ConfigurazioneAuditing extends Action {
- @Override
- public ActionForward execute(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception {
- HttpSession session = request.getSession(true);
- // Inizializzo PageData
- PageData pd = new PageData();
- GeneralHelper generalHelper = new GeneralHelper(session);
- // Inizializzo GeneralData
- GeneralData gd = generalHelper.initGeneralData(request);
- String userLogin = ServletUtils.getUserLoginFromSession(session);
- try {
- ConfigurazioneHelper confHelper = new ConfigurazioneHelper(request, pd, session);
- String statoaudit = confHelper.getParameter( AuditCostanti.PARAMETRO_AUDIT_STATO_AUDIT);
- String stato = confHelper.getParameter(AuditCostanti.PARAMETRO_AUDIT_STATO);
- String dump = confHelper.getParameter(AuditCostanti.PARAMETRO_AUDIT_DUMP);
- String formatodump = confHelper.getParameter(AuditCostanti.PARAMETRO_AUDIT_FORMATO_DUMP);
- String log4j = confHelper.getParameter(AuditCostanti.PARAMETRO_AUDIT_LOG4J);
- ConfigurazioneCore confCore = new ConfigurazioneCore();
- AuditHelper ah = new AuditHelper(request, pd, session);
- AuditingCore auditingCore = new AuditingCore(confCore);
- Configurazione c = auditingCore.getConfigurazioneAudit();
- // Preparo il menu
- confHelper.makeMenu();
- // setto la barra del titolo
- ServletUtils.setPageDataTitle_ServletFirst(pd, AuditCostanti.LABEL_AUDIT, AuditCostanti.SERVLET_NAME_AUDIT);
- // Se idhid != null, modifico i dati dell'audit nel db
- if (!confHelper.isEditModeInProgress()) {
- // Controlli sui campi immessi
- String msg = ah.auditCheckData(statoaudit, stato, dump, formatodump, log4j);
- if (!msg.equals("")) {
- pd.setMessage(msg);
- Configurazione tmpConf = auditingCore.getConfigurazioneAudit();
- // preparo i campi
- List<DataElement> dati = ah.addAuditingToDati(
- statoaudit, stato, dump, formatodump, log4j,
- tmpConf.sizeFiltri());
- pd.setDati(dati);
- ServletUtils.setGeneralAndPageDataIntoSession(request, session, gd, pd);
- return ServletUtils.getStrutsForwardEditModeCheckError(mapping,
- AuditCostanti.OBJECT_NAME_CONFIGURAZIONE_AUDITING, AuditCostanti.TIPO_OPERAZIONE_CONFIGURAZIONE_AUDITING
- );
- }
- // Modifico i dati dell'audit nel db
- Configurazione newConfigurazione = auditingCore.getConfigurazioneAudit();
- newConfigurazione.setAuditEngineEnabled(
- statoaudit.equals(AuditCostanti.DEFAULT_VALUE_ABILITATO));
- newConfigurazione.setAuditEnabled(
- stato.equals(AuditCostanti.DEFAULT_VALUE_ABILITATO));
- newConfigurazione.setDumpEnabled(
- dump.equals(AuditCostanti.DEFAULT_VALUE_ABILITATO));
- newConfigurazione.setDumpFormat(formatodump);
- if (log4j.equals(AuditCostanti.DEFAULT_VALUE_ABILITATO)) {
- boolean giaPresente = false;
- for(int i=0; i<newConfigurazione.sizeAppender(); i++){
- if(AuditCostanti.DEFAULT_VALUE_PARAMETRO_AUDIT_APPENDER_NOME.equals(newConfigurazione.getAppender(i).getNome())){
- giaPresente=true;
- break;
- }
- }
- if (!giaPresente) {
- Appender appender = new Appender();
- appender.setNome(AuditCostanti.DEFAULT_VALUE_PARAMETRO_AUDIT_APPENDER_NOME);
- appender.setClassName(AuditCostanti.DEFAULT_VALUE_PARAMETRO_AUDIT_APPENDER_CLASS_NAME);
- AppenderProperty pr1 = new AppenderProperty();
- pr1.setName(AuditCostanti.DEFAULT_VALUE_PARAMETRO_AUDIT_APPENDER_PROPERTY_FILE_CONFIGURAZIONE_NAME);
- pr1.setValue(AuditCostanti.DEFAULT_VALUE_PARAMETRO_AUDIT_APPENDER_PROPERTY_FILE_CONFIGURAZIONE_VALUE);
- appender.addProperty(pr1);
- AppenderProperty pr2 = new AppenderProperty();
- pr2.setName(AuditCostanti.DEFAULT_VALUE_PARAMETRO_AUDIT_APPENDER_PROPERTY_CATEGORY_NAME);
- pr2.setValue(AuditCostanti.DEFAULT_VALUE_PARAMETRO_AUDIT_APPENDER_PROPERTY_CATEGORY_VALUE);
- appender.addProperty(pr2);
- AppenderProperty pr3 = new AppenderProperty();
- pr3.setName(AuditCostanti.DEFAULT_VALUE_PARAMETRO_AUDIT_APPENDER_PROPERTY_XML_NAME);
- pr3.setValue(AuditCostanti.DEFAULT_VALUE_PARAMETRO_AUDIT_APPENDER_PROPERTY_XML_VALUE);
- appender.addProperty(pr3);
- newConfigurazione.addAppender(appender);
- }
- } else {
- for(int i=0; i<newConfigurazione.sizeAppender(); i++){
- if(AuditCostanti.DEFAULT_VALUE_PARAMETRO_AUDIT_APPENDER_NOME.equals(newConfigurazione.getAppender(i).getNome())){
- newConfigurazione.removeAppender(i);
- break;
- }
- }
- }
- confCore.performUpdateOperation(userLogin, confHelper.smista(), newConfigurazione);
- // preparo i campi
- List<DataElement> dati = ah.addAuditingToDati(
- statoaudit, stato, dump, formatodump, log4j,
- c.sizeFiltri());
- dati.add(ServletUtils.getDataElementForEditModeFinished());
- pd.setDati(dati);
- pd.setMessage(AuditCostanti.LABEL_AUDIT_CONFIGURAZIONE_MODIFICATA, Costanti.MESSAGE_TYPE_INFO);
- ServletUtils.setGeneralAndPageDataIntoSession(request, session, gd, pd);
- return ServletUtils.getStrutsForwardEditModeFinished(mapping,
- AuditCostanti.OBJECT_NAME_CONFIGURAZIONE_AUDITING, AuditCostanti.TIPO_OPERAZIONE_CONFIGURAZIONE_AUDITING);
- }
- if (statoaudit == null)
- statoaudit = c.isAuditEngineEnabled() ? AuditCostanti.DEFAULT_VALUE_ABILITATO : AuditCostanti.DEFAULT_VALUE_DISABILITATO;
- stato = c.isAuditEnabled() ? AuditCostanti.DEFAULT_VALUE_ABILITATO : AuditCostanti.DEFAULT_VALUE_DISABILITATO;
- dump = c.isDumpEnabled() ? AuditCostanti.DEFAULT_VALUE_ABILITATO :AuditCostanti.DEFAULT_VALUE_DISABILITATO;
- formatodump = c.getDumpFormat();
- log4j = AuditCostanti.DEFAULT_VALUE_DISABILITATO;
- if(c.sizeAppender()>0){
- for(int i=0; i<c.sizeAppender(); i++){
- if(AuditCostanti.DEFAULT_VALUE_PARAMETRO_AUDIT_APPENDER_NOME.equals(c.getAppender(i).getNome())){
- log4j = ConfigurazioneCostanti.DEFAULT_VALUE_ABILITATO;
- break;
- }
- }
- }
- // preparo i campi
- List<DataElement> dati = ah.addAuditingToDati(
- statoaudit, stato, dump, formatodump, log4j,
- c.sizeFiltri());
- dati.add(ServletUtils.getDataElementForEditModeFinished());
- pd.setDati(dati);
- ServletUtils.setGeneralAndPageDataIntoSession(request, session, gd, pd);
- return ServletUtils.getStrutsForwardEditModeInProgress(mapping,
- AuditCostanti.OBJECT_NAME_CONFIGURAZIONE_AUDITING, AuditCostanti.TIPO_OPERAZIONE_CONFIGURAZIONE_AUDITING);
- } catch (Exception e) {
- return ServletUtils.getStrutsForwardError(ControlStationCore.getLog(), e, pd, request, session, gd, mapping,
- AuditCostanti.OBJECT_NAME_CONFIGURAZIONE_AUDITING, AuditCostanti.TIPO_OPERAZIONE_CONFIGURAZIONE_AUDITING);
- }
- }
- }