AbstractConfigChecker.java

  1. /*
  2.  * GovWay - A customizable API Gateway
  3.  * https://govway.org
  4.  *
  5.  * Copyright (c) 2005-2025 Link.it srl (https://link.it).
  6.  *
  7.  * This program is free software: you can redistribute it and/or modify
  8.  * it under the terms of the GNU General Public License version 3, as published by
  9.  * the Free Software Foundation.
  10.  *
  11.  * This program is distributed in the hope that it will be useful,
  12.  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  14.  * GNU General Public License for more details.
  15.  *
  16.  * You should have received a copy of the GNU General Public License
  17.  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
  18.  *
  19.  */

  20. package org.openspcoop2.pdd.core.jmx;

  21. import java.util.ArrayList;
  22. import java.util.HashMap;
  23. import java.util.List;
  24. import java.util.Map;

  25. import org.openspcoop2.core.commons.CoreException;
  26. import org.openspcoop2.core.config.GenericProperties;
  27. import org.openspcoop2.core.config.ServizioApplicativo;
  28. import org.openspcoop2.core.constants.StatoCheck;
  29. import org.openspcoop2.core.registry.Soggetto;
  30. import org.openspcoop2.pdd.config.ConfigurazioneNodiRuntime;
  31. import org.openspcoop2.pdd.config.ConfigurazionePdDReader;
  32. import org.openspcoop2.pdd.config.InvokerNodiRuntime;
  33. import org.openspcoop2.pdd.core.connettori.ConnettoreCheck;
  34. import org.openspcoop2.protocol.registry.CertificateCheck;
  35. import org.openspcoop2.protocol.registry.RegistroServiziReader;
  36. import org.slf4j.Logger;


  37. /**
  38.  * AbstractConfigChecker
  39.  *
  40.  * @author Poli Andrea (apoli@link.it)
  41.  * @author $Author$
  42.  * @version $Rev$, $Date$
  43.  */
  44. public abstract class AbstractConfigChecker {

  45.     private static String getErrorMessage(String risorsa,String nomeNodoRuntime,Exception e) {
  46.         return "Errore durante la verifica dei certificati (jmxResource '"+risorsa+"') (node:"+nomeNodoRuntime+"): "+e.getMessage();
  47.     }
  48.     private static String getErrorMessageClasseNonGestita(Object o) {
  49.         return "Classe '"+o.getClass().getName()+"' non gestita";
  50.     }
  51.    
  52.     public static void addErrore(Map<String,List<String>> mapErrori, String errore, String nomeNodoRuntime) {
  53.         if(mapErrori.containsKey(errore)) {
  54.             List<String> l = mapErrori.get(errore);
  55.             l.add(nomeNodoRuntime);
  56.         }
  57.         else {
  58.             List<String> l = new ArrayList<>();
  59.             l.add(nomeNodoRuntime);
  60.             mapErrori.put(errore, l);
  61.         }
  62.     }
  63.    
  64.     public static void printErrore(Map<String,List<String>> mapErrori, StringBuilder sbDetails) {
  65.         printErrore(mapErrori, sbDetails, -1, "");
  66.     }
  67.     public static void printErrore(Map<String,List<String>> mapErrori, StringBuilder sbDetails, int nodes, String multipleNodeSeparator) {
  68.         if(!mapErrori.isEmpty()) {
  69.             if(mapErrori.size()==1) {
  70.                 if(sbDetails.length()>0) {
  71.                     sbDetails.append("\n");
  72.                 }
  73.                 String errore = mapErrori.keySet().iterator().next();
  74.                
  75.                 List<String> nodiRuntimeErrore = mapErrori.get(errore);
  76.                 if(nodes>1 && (nodiRuntimeErrore!=null && nodiRuntimeErrore.size()!=nodes)) {
  77.                     String nodesLabel = printNodes(mapErrori, errore);
  78.                     sbDetails.append("(").append(nodesLabel).append(") ");
  79.                 }
  80.                
  81.                 sbDetails.append(errore);
  82.             }
  83.             else {
  84.                 boolean first = true;
  85.                 for (String errore : mapErrori.keySet()) {
  86.                     if(sbDetails.length()>0) {
  87.                         sbDetails.append("\n");
  88.                         sbDetails.append(multipleNodeSeparator);
  89.                     }
  90.                     else {
  91.                         if(first) {
  92.                             first = false;
  93.                         }
  94.                         else {
  95.                             sbDetails.append("\n");
  96.                             sbDetails.append(multipleNodeSeparator);
  97.                         }
  98.                     }
  99.                    
  100.                     String nodesLabel = printNodes(mapErrori, errore);
  101.                     sbDetails.append("(").append(nodesLabel).append(") ");
  102.                    
  103.                     sbDetails.append(errore);
  104.                 }
  105.             }
  106.         }
  107.     }
  108.     private static String printNodes(Map<String,List<String>> mapErrori, String errore) {
  109.         List<String> nodiRuntimeErrore = mapErrori.get(errore);
  110.         StringBuilder sbNodir = new StringBuilder();
  111.         for (String nodo : nodiRuntimeErrore) {
  112.             if(sbNodir.length()>0) {
  113.                 sbNodir.append(", ");
  114.             }
  115.             sbNodir.append(nodo);
  116.         }
  117.         return sbNodir.toString();
  118.     }
  119.    
  120.     protected String getMultipleNodeSeparator() {
  121.         return "";
  122.     }
  123.    
  124.     public abstract void error(String msg);
  125.     public abstract void error(String msg, Throwable t);
  126.     public abstract Logger getInternalLogger();
  127.    
  128.     public abstract boolean isUseApiCertificatoApplicativoById() throws CoreException;
  129.     public abstract boolean isUseApiCertificatoSoggettoById() throws CoreException;
  130.    
  131.     public abstract String getJmxResourceType() throws CoreException;
  132.     public abstract String getJmxResourceNomeRisorsaConfigurazionePdD() throws CoreException;
  133.     public abstract String getJmxResourceNomeRisorsaAccessoRegistroServizi() throws CoreException;
  134.    
  135.     public abstract String getJmxResourceNomeMetodoCheckConnettoreById() throws CoreException;
  136.     public abstract String getJmxResourceNomeMetodoCheckCertificatoApplicativoById() throws CoreException;
  137.     public abstract String getJmxResourceNomeMetodoCheckCertificatoModIApplicativoById() throws CoreException;
  138.     public abstract String getJmxResourceNomeMetodoCheckCertificatoSoggettoById() throws CoreException;
  139.     public abstract String getJmxResourceNomeMetodoCheckCertificatiConnettoreHttpsById() throws CoreException;
  140.     public abstract String getJmxResourceNomeMetodoCheckCertificatiModIErogazioneById() throws CoreException;
  141.     public abstract String getJmxResourceNomeMetodoCheckCertificatiModIFruizioneById() throws CoreException;
  142.     public abstract String getJmxResourceNomeMetodoCheckCertificatiMessageSecurityErogazioneById() throws CoreException;
  143.     public abstract String getJmxResourceNomeMetodoCheckCertificatiMessageSecurityFruizioneById() throws CoreException;
  144.     public abstract String getJmxResourceNomeMetodoCheckCertificatiJvm() throws CoreException;
  145.     public abstract String getJmxResourceNomeMetodoCheckCertificatiConnettoreHttpsTokenPolicyValidazione() throws CoreException;
  146.     public abstract String getJmxResourceNomeMetodoCheckCertificatiValidazioneJwtTokenPolicyValidazione() throws CoreException;
  147.     public abstract String getJmxResourceNomeMetodoCheckCertificatiForwardToJwtTokenPolicyValidazione() throws CoreException;
  148.     public abstract String getJmxResourceNomeMetodoCheckCertificatiConnettoreHttpsTokenPolicyNegoziazione() throws CoreException;
  149.     public abstract String getJmxResourceNomeMetodoCheckCertificatiSignedJwtTokenPolicyNegoziazione() throws CoreException;
  150.     public abstract String getJmxResourceNomeMetodoCheckCertificatiConnettoreHttpsAttributeAuthority() throws CoreException;
  151.     public abstract String getJmxResourceNomeMetodoCheckCertificatiAttributeAuthorityJwtRichiesta() throws CoreException;
  152.     public abstract String getJmxResourceNomeMetodoCheckCertificatiAttributeAuthorityJwtRisposta() throws CoreException;
  153.    
  154.     private InvokerNodiRuntime invoker;
  155.     private ConfigurazioneNodiRuntime config;
  156.     private List<String> nodiRuntime;
  157.     protected AbstractConfigChecker(InvokerNodiRuntime invoker, ConfigurazioneNodiRuntime config, List<String> nodiRuntime) {
  158.         this.invoker = invoker;
  159.         this.config = config;
  160.         this.nodiRuntime = nodiRuntime;
  161.     }
  162.    
  163.     public void checkApplicativo(StringBuilder sbDetailsError, StringBuilder sbDetailsWarning,
  164.             boolean ssl, boolean sicurezzaModi, boolean connettoreHttps, org.openspcoop2.core.config.ServizioApplicativo servizioApplicativo,
  165.             int sogliaWarningGiorni) throws CoreException {
  166.        
  167.         StringBuilder sbError = new StringBuilder();
  168.        
  169.         StringBuilder sbWarning = new StringBuilder();
  170.         StringBuilder sbWarningModi = new StringBuilder();
  171.         StringBuilder sbWarningConnettore = new StringBuilder();
  172.        
  173.         if(ssl) {
  174.             checkCertificate(sbError, sbWarning,
  175.                     sogliaWarningGiorni,
  176.                     servizioApplicativo);
  177.         }
  178.        
  179.         if(sbError.length()<=0 &&
  180.             sicurezzaModi) {
  181.             checkCertificateModI(sbError, sbWarningModi,
  182.                     sogliaWarningGiorni,
  183.                     servizioApplicativo);
  184.         }
  185.        
  186.         if(sbError.length()<=0 &&
  187.             connettoreHttps) {
  188.             org.openspcoop2.core.config.Connettore connettore = null;
  189.             if(servizioApplicativo.getInvocazioneServizio()!=null) {
  190.                 connettore = servizioApplicativo.getInvocazioneServizio().getConnettore();
  191.             }
  192.             if(connettore!=null) {
  193.                 checkCertificate(sbError, sbWarningConnettore,
  194.                         sogliaWarningGiorni,
  195.                         connettore);    
  196.             }
  197.         }
  198.        
  199.         if(sbError.length()>0) {
  200.             sbDetailsError.append(sbError.toString());
  201.         }
  202.         else {
  203.             if(sbWarning.length()>0) {
  204.                 sbDetailsWarning.append(sbWarning.toString());
  205.             }
  206.             else if(sbWarningModi.length()>0) {
  207.                 sbDetailsWarning.append(sbWarningModi.toString());
  208.             }
  209.             else if(sbWarningConnettore.length()>0) {
  210.                 sbDetailsWarning.append(sbWarningConnettore.toString());
  211.             }
  212.         }
  213.        
  214.     }
  215.    
  216.     public void checkSoggetto(StringBuilder sbDetailsError, StringBuilder sbDetailsWarning,
  217.             boolean ssl, org.openspcoop2.core.registry.Soggetto soggetto,
  218.             int sogliaWarningGiorni) throws CoreException {
  219.        
  220.         StringBuilder sbError = new StringBuilder();
  221.        
  222.         StringBuilder sbWarning = new StringBuilder();
  223.        
  224.         if(ssl) {
  225.             checkCertificate(sbError, sbWarning,
  226.                     sogliaWarningGiorni,
  227.                     soggetto);
  228.         }
  229.        
  230.         if(sbError.length()>0) {
  231.             sbDetailsError.append(sbError.toString());
  232.         }
  233.         else {
  234.             if(sbWarning.length()>0) {
  235.                 sbDetailsWarning.append(sbWarning.toString());
  236.             }
  237.         }
  238.        
  239.     }
  240.    
  241.     public void checkErogazione(StringBuilder sbDetailsError, StringBuilder sbDetailsWarning,
  242.             boolean connettoreSsl, org.openspcoop2.core.config.Connettore connettore,
  243.             boolean sicurezzaModi,
  244.             boolean messageSecurity,
  245.             org.openspcoop2.core.registry.AccordoServizioParteSpecifica asps,
  246.             int sogliaWarningGiorni) throws CoreException {
  247.         List<org.openspcoop2.core.config.Connettore> connettori = null;
  248.         if(connettore!=null) {
  249.             connettori = new ArrayList<>();
  250.             connettori.add(connettore);
  251.         }
  252.         checkErogazione(sbDetailsError, sbDetailsWarning,
  253.                 connettoreSsl, connettori,
  254.                 sicurezzaModi,
  255.                 messageSecurity,
  256.                 asps,
  257.                 sogliaWarningGiorni);
  258.     }
  259.     public void checkErogazione(StringBuilder sbDetailsError, StringBuilder sbDetailsWarning,
  260.             boolean connettoreSsl, List<org.openspcoop2.core.config.Connettore> connettori,
  261.             boolean sicurezzaModi,
  262.             boolean messageSecurity,
  263.             org.openspcoop2.core.registry.AccordoServizioParteSpecifica asps,
  264.             int sogliaWarningGiorni) throws CoreException {
  265.        
  266.         StringBuilder sbError = new StringBuilder();
  267.        
  268.         StringBuilder sbWarning = new StringBuilder();
  269.         StringBuilder sbWarningModi = new StringBuilder();
  270.         StringBuilder sbWarningSicurezzaMessaggio = new StringBuilder();
  271.        
  272.         if(connettoreSsl && connettori!=null && !connettori.isEmpty()) {
  273.             for (org.openspcoop2.core.config.Connettore connettore : connettori) {
  274.                 StringBuilder sbWarningConnettore = new StringBuilder();
  275.                 if(sbError.length()<=0) {
  276.                     checkCertificate(sbError, sbWarningConnettore,
  277.                             sogliaWarningGiorni,
  278.                             connettore);    
  279.                 }
  280.                 if(sbWarning.length()<=0 && sbWarningConnettore.length()>0) {
  281.                     sbWarning.append(sbWarningConnettore.toString()); // tengo solo un warning alla volta, come per gli errori
  282.                 }
  283.             }
  284.         }
  285.        
  286.         if(sbError.length()<=0 &&
  287.             sicurezzaModi) {
  288.             checkCertificateModI(sbError, sbWarningModi,
  289.                     sogliaWarningGiorni,
  290.                     asps);
  291.         }
  292.        
  293.         if(sbError.length()<=0 &&
  294.                 messageSecurity) {
  295.                 checkCertificateMessageSecurity(sbError, sbWarningSicurezzaMessaggio,
  296.                         sogliaWarningGiorni,
  297.                         asps);
  298.             }
  299.        
  300.         if(sbError.length()>0) {
  301.             sbDetailsError.append(sbError.toString());
  302.         }
  303.         else {
  304.             if(sbWarning.length()>0) {
  305.                 sbDetailsWarning.append(sbWarning.toString());
  306.             }
  307.             else if(sbWarningModi.length()>0) {
  308.                 sbDetailsWarning.append(sbWarningModi.toString());
  309.             }
  310.             else if(sbWarningSicurezzaMessaggio.length()>0) {
  311.                 sbDetailsWarning.append(sbWarningSicurezzaMessaggio.toString());
  312.             }
  313.         }
  314.        
  315.     }
  316.    
  317.     public void checkFruizione(StringBuilder sbDetailsError, StringBuilder sbDetailsWarning,
  318.             boolean connettoreSsl, org.openspcoop2.core.registry.Connettore connettore,
  319.             boolean sicurezzaModi,
  320.             boolean messageSecurity,
  321.             org.openspcoop2.core.registry.AccordoServizioParteSpecifica asps, org.openspcoop2.core.registry.Fruitore fruitore,
  322.             int sogliaWarningGiorni) throws CoreException {
  323.         List<org.openspcoop2.core.registry.Connettore> connettori = null;
  324.         if(connettore!=null) {
  325.             connettori = new ArrayList<>();
  326.             connettori.add(connettore);
  327.         }
  328.         checkFruizione(sbDetailsError, sbDetailsWarning,
  329.                 connettoreSsl, connettori,
  330.                 sicurezzaModi,
  331.                 messageSecurity,
  332.                 asps, fruitore,
  333.                 sogliaWarningGiorni);
  334.     }
  335.     public void checkFruizione(StringBuilder sbDetailsError, StringBuilder sbDetailsWarning,
  336.             boolean connettoreSsl, List<org.openspcoop2.core.registry.Connettore> connettori,
  337.             boolean sicurezzaModi,
  338.             boolean messageSecurity,
  339.             org.openspcoop2.core.registry.AccordoServizioParteSpecifica asps, org.openspcoop2.core.registry.Fruitore fruitore,
  340.             int sogliaWarningGiorni) throws CoreException {
  341.        
  342.         if(asps!=null) {
  343.             // nop
  344.         }
  345.        
  346.         StringBuilder sbError = new StringBuilder();
  347.        
  348.         StringBuilder sbWarning = new StringBuilder();
  349.         StringBuilder sbWarningModi = new StringBuilder();
  350.         StringBuilder sbWarningSicurezzaMessaggio = new StringBuilder();
  351.        
  352.         if(connettoreSsl && connettori!=null && !connettori.isEmpty()) {
  353.             for (org.openspcoop2.core.registry.Connettore connettore : connettori) {
  354.                 StringBuilder sbWarningConnettore = new StringBuilder();
  355.                 if(sbError.length()<=0) {
  356.                     checkCertificate(sbError, sbWarningConnettore,
  357.                             sogliaWarningGiorni,
  358.                             connettore);    
  359.                 }
  360.                 if(sbWarning.length()<=0 && sbWarningConnettore.length()>0) {
  361.                     sbWarning.append(sbWarningConnettore.toString()); // tengo solo un warning alla volta, come per gli errori
  362.                 }
  363.             }
  364.         }
  365.        
  366.         if(sbError.length()<=0 &&
  367.             sicurezzaModi) {
  368.             checkCertificateModI(sbError, sbWarningModi,
  369.                     sogliaWarningGiorni,
  370.                     fruitore);
  371.         }
  372.        
  373.         if(sbError.length()<=0 &&
  374.                 messageSecurity) {
  375.             checkCertificateMessageSecurity(sbError, sbWarningSicurezzaMessaggio,
  376.                     sogliaWarningGiorni,
  377.                     fruitore);
  378.         }
  379.        
  380.         if(sbError.length()>0) {
  381.             sbDetailsError.append(sbError.toString());
  382.         }
  383.         else {
  384.             if(sbWarning.length()>0) {
  385.                 sbDetailsWarning.append(sbWarning.toString());
  386.             }
  387.             else if(sbWarningModi.length()>0) {
  388.                 sbDetailsWarning.append(sbWarningModi.toString());
  389.             }
  390.             else if(sbWarningSicurezzaMessaggio.length()>0) {
  391.                 sbDetailsWarning.append(sbWarningSicurezzaMessaggio.toString());
  392.             }
  393.         }
  394.        
  395.     }
  396.    
  397.    
  398.     public void checkConfigurazioneJvm(StringBuilder sbDetailsError, StringBuilder sbDetailsWarning,
  399.             int sogliaWarningGiorni) throws CoreException {
  400.        
  401.         StringBuilder sbError = new StringBuilder();
  402.        
  403.         StringBuilder sbWarning = new StringBuilder();
  404.        
  405.         checkCertificate(sbError, sbWarning,
  406.                     sogliaWarningGiorni,
  407.                     new org.openspcoop2.core.config.Configurazione());
  408.        
  409.         if(sbError.length()>0) {
  410.             sbDetailsError.append(sbError.toString());
  411.         }
  412.         else {
  413.             if(sbWarning.length()>0) {
  414.                 sbDetailsWarning.append(sbWarning.toString());
  415.             }
  416.         }
  417.        
  418.     }
  419.    
  420.    
  421.     public void checkTokenPolicyValidazione(StringBuilder sbDetailsError, StringBuilder sbDetailsWarning,
  422.             boolean httpsDynamicDiscovery, boolean httpsValidazioneJWT, boolean httpsIntrospection, boolean httpsUserInfo,
  423.             boolean validazioneJwt, boolean forwardToJwt,
  424.             GenericProperties gp,
  425.             int sogliaWarningGiorni) throws CoreException {
  426.        
  427.         StringBuilder sbError = new StringBuilder();
  428.        
  429.         StringBuilder sbWarningDynamicDiscovery = new StringBuilder();
  430.         StringBuilder sbWarningValidazioneJwtHttps = new StringBuilder();
  431.         StringBuilder sbWarningIntrospection = new StringBuilder();
  432.         StringBuilder sbWarningUserInfo = new StringBuilder();
  433.         StringBuilder sbWarningValidazioneJwt = new StringBuilder();
  434.         StringBuilder sbWarningForwardToJwt = new StringBuilder();
  435.        
  436.         if(httpsDynamicDiscovery) {
  437.             checkCertificateGenericProperties(sbError, sbWarningDynamicDiscovery,
  438.                     sogliaWarningGiorni,
  439.                     getJmxResourceNomeMetodoCheckCertificatiConnettoreHttpsTokenPolicyValidazione(),
  440.                     gp.getNome(), ConnettoreCheck.POLICY_TIPO_ENDPOINT_DYNAMIC_DISCOVERY);
  441.         }
  442.         if(sbError.length()<=0 &&
  443.             httpsValidazioneJWT) {
  444.             checkCertificateGenericProperties(sbError, sbWarningValidazioneJwtHttps,
  445.                     sogliaWarningGiorni,
  446.                     getJmxResourceNomeMetodoCheckCertificatiConnettoreHttpsTokenPolicyValidazione(),
  447.                     gp.getNome(), ConnettoreCheck.POLICY_TIPO_ENDPOINT_VALIDAZIONE_JWT);
  448.         }
  449.         if(sbError.length()<=0 &&
  450.             httpsIntrospection) {
  451.             checkCertificateGenericProperties(sbError, sbWarningIntrospection,
  452.                     sogliaWarningGiorni,
  453.                     getJmxResourceNomeMetodoCheckCertificatiConnettoreHttpsTokenPolicyValidazione(),
  454.                     gp.getNome(), ConnettoreCheck.POLICY_TIPO_ENDPOINT_INTROSPECTION);
  455.         }
  456.         if(sbError.length()<=0 &&
  457.             httpsUserInfo) {
  458.             checkCertificateGenericProperties(sbError, sbWarningUserInfo,
  459.                     sogliaWarningGiorni,
  460.                     getJmxResourceNomeMetodoCheckCertificatiConnettoreHttpsTokenPolicyValidazione(),
  461.                     gp.getNome(), ConnettoreCheck.POLICY_TIPO_ENDPOINT_USERINFO);
  462.         }
  463.         if(sbError.length()<=0 &&
  464.             validazioneJwt) {
  465.             checkCertificateGenericProperties(sbError, sbWarningValidazioneJwt,
  466.                     sogliaWarningGiorni,
  467.                     getJmxResourceNomeMetodoCheckCertificatiValidazioneJwtTokenPolicyValidazione(),
  468.                     gp.getNome());
  469.         }
  470.         if(sbError.length()<=0 &&
  471.             forwardToJwt) {
  472.             checkCertificateGenericProperties(sbError, sbWarningForwardToJwt,
  473.                     sogliaWarningGiorni,
  474.                     getJmxResourceNomeMetodoCheckCertificatiForwardToJwtTokenPolicyValidazione(),
  475.                     gp.getNome());
  476.         }
  477.        
  478.         if(sbError.length()>0) {
  479.             sbDetailsError.append(sbError.toString());
  480.         }
  481.         else {
  482.             if(sbWarningDynamicDiscovery.length()>0) {
  483.                 sbDetailsWarning.append(sbWarningDynamicDiscovery.toString());
  484.             }
  485.             else if(sbWarningValidazioneJwtHttps.length()>0) {
  486.                 sbDetailsWarning.append(sbWarningValidazioneJwtHttps.toString());
  487.             }
  488.             else if(sbWarningIntrospection.length()>0) {
  489.                 sbDetailsWarning.append(sbWarningIntrospection.toString());
  490.             }
  491.             else if(sbWarningUserInfo.length()>0) {
  492.                 sbDetailsWarning.append(sbWarningUserInfo.toString());
  493.             }
  494.             else if(sbWarningValidazioneJwt.length()>0) {
  495.                 sbDetailsWarning.append(sbWarningValidazioneJwt.toString());
  496.             }
  497.             else if(sbWarningForwardToJwt.length()>0) {
  498.                 sbDetailsWarning.append(sbWarningForwardToJwt.toString());
  499.             }
  500.         }
  501.        
  502.     }
  503.    
  504.    
  505.     public void checkTokenPolicyNegoziazione(StringBuilder sbDetailsError, StringBuilder sbDetailsWarning,
  506.             boolean https, boolean signedJwt,
  507.             GenericProperties gp,
  508.             int sogliaWarningGiorni) throws CoreException {
  509.        
  510.         StringBuilder sbError = new StringBuilder();
  511.        
  512.         StringBuilder sbWarning = new StringBuilder();
  513.         StringBuilder sbWarningSignedJwt = new StringBuilder();
  514.        
  515.         if(https) {
  516.             checkCertificateGenericProperties(sbError, sbWarning,
  517.                     sogliaWarningGiorni,
  518.                     getJmxResourceNomeMetodoCheckCertificatiConnettoreHttpsTokenPolicyNegoziazione(),
  519.                     gp.getNome());
  520.         }
  521.         if(sbError.length()<=0 &&
  522.             signedJwt) {
  523.             checkCertificateGenericProperties(sbError, sbWarningSignedJwt,
  524.                     sogliaWarningGiorni,
  525.                     getJmxResourceNomeMetodoCheckCertificatiSignedJwtTokenPolicyNegoziazione(),
  526.                     gp.getNome());
  527.         }
  528.        
  529.         if(sbError.length()>0) {
  530.             sbDetailsError.append(sbError.toString());
  531.         }
  532.         else {
  533.             if(sbWarning.length()>0) {
  534.                 sbDetailsWarning.append(sbWarning.toString());
  535.             }
  536.             else if(sbWarningSignedJwt.length()>0) {
  537.                 sbDetailsWarning.append(sbWarningSignedJwt.toString());
  538.             }
  539.         }
  540.        
  541.     }
  542.    
  543.    
  544.     public void checkAttributeAuthority(StringBuilder sbDetailsError, StringBuilder sbDetailsWarning,
  545.             boolean https, boolean jwtRichiesta, boolean jwtRisposta,
  546.             GenericProperties gp,
  547.             int sogliaWarningGiorni) throws CoreException {
  548.        
  549.         StringBuilder sbError = new StringBuilder();
  550.        
  551.         StringBuilder sbWarning = new StringBuilder();
  552.         StringBuilder sbWarningJwtRichiesta = new StringBuilder();
  553.         StringBuilder sbWarningJwtRisposta = new StringBuilder();
  554.        
  555.         if(https) {
  556.             checkCertificateGenericProperties(sbError, sbWarning,
  557.                     sogliaWarningGiorni,
  558.                     getJmxResourceNomeMetodoCheckCertificatiConnettoreHttpsAttributeAuthority(),
  559.                     gp.getNome());
  560.         }
  561.         if(sbError.length()<=0 &&
  562.             jwtRichiesta) {
  563.             checkCertificateGenericProperties(sbError, sbWarningJwtRichiesta,
  564.                     sogliaWarningGiorni,
  565.                     getJmxResourceNomeMetodoCheckCertificatiAttributeAuthorityJwtRichiesta(),
  566.                     gp.getNome());
  567.         }
  568.         if(sbError.length()<=0 &&
  569.             jwtRisposta) {
  570.             checkCertificateGenericProperties(sbError, sbWarningJwtRisposta,
  571.                     sogliaWarningGiorni,
  572.                     getJmxResourceNomeMetodoCheckCertificatiAttributeAuthorityJwtRisposta(),
  573.                     gp.getNome());
  574.         }
  575.        
  576.         if(sbError.length()>0) {
  577.             sbDetailsError.append(sbError.toString());
  578.         }
  579.         else {
  580.             if(sbWarning.length()>0) {
  581.                 sbDetailsWarning.append(sbWarning.toString());
  582.             }
  583.             else if(sbWarningJwtRichiesta.length()>0) {
  584.                 sbDetailsWarning.append(sbWarningJwtRichiesta.toString());
  585.             }
  586.             else if(sbWarningJwtRisposta.length()>0) {
  587.                 sbDetailsWarning.append(sbWarningJwtRisposta.toString());
  588.             }
  589.         }
  590.        
  591.     }
  592.    
  593.    
  594.     private void checkCertificate(StringBuilder sbDetailsError, StringBuilder sbDetailsWarning,  
  595.             int sogliaWarningGiorni,
  596.             Object o) throws CoreException {
  597.        
  598.         String risorsa = null;
  599.         String metodo = null;
  600.         boolean useApi = false;
  601.         boolean applicativo = false;
  602.         boolean soggetto = false;
  603.         boolean connettoreErogazione = false;
  604.         boolean connettoreFruizione = false;
  605.         long idObject = -1;
  606.         boolean withId = true;
  607.         if(o instanceof ServizioApplicativo) {
  608.             applicativo = true;
  609.         }
  610.         else if(o instanceof Soggetto) {
  611.             soggetto = true;
  612.         }
  613.         else if(o instanceof org.openspcoop2.core.config.Connettore) {
  614.             connettoreErogazione = true;
  615.         }
  616.         else if(o instanceof org.openspcoop2.core.registry.Connettore) {
  617.             connettoreFruizione = true;
  618.         }
  619.         else if(o instanceof org.openspcoop2.core.config.Configurazione) {
  620.             risorsa = this.getJmxResourceNomeRisorsaConfigurazionePdD();
  621.             metodo = this.getJmxResourceNomeMetodoCheckCertificatiJvm();
  622.             withId = false;
  623.         }
  624.         else {
  625.             throw new CoreException(getErrorMessageClasseNonGestita(o));
  626.         }
  627.        
  628.         if(applicativo) {
  629.             idObject = ((ServizioApplicativo)o).getId();
  630.             useApi = this.isUseApiCertificatoApplicativoById();
  631.             if(!useApi) {
  632.                 risorsa = this.getJmxResourceNomeRisorsaConfigurazionePdD();
  633.                 metodo = this.getJmxResourceNomeMetodoCheckCertificatoApplicativoById();
  634.             }
  635.         }
  636.         else if(soggetto) {
  637.             idObject = ((Soggetto)o).getId();
  638.             useApi = this.isUseApiCertificatoSoggettoById();
  639.             if(!useApi) {
  640.                 risorsa = this.getJmxResourceNomeRisorsaAccessoRegistroServizi();
  641.                 metodo = this.getJmxResourceNomeMetodoCheckCertificatoSoggettoById();
  642.             }
  643.         }
  644.         else if(connettoreErogazione) {
  645.             idObject = ((org.openspcoop2.core.config.Connettore)o).getId();
  646.             risorsa = this.getJmxResourceNomeRisorsaConfigurazionePdD();
  647.             metodo = this.getJmxResourceNomeMetodoCheckCertificatiConnettoreHttpsById();
  648.         }
  649.         else if(connettoreFruizione) {
  650.             idObject = ((org.openspcoop2.core.registry.Connettore)o).getId();
  651.             risorsa = this.getJmxResourceNomeRisorsaAccessoRegistroServizi();
  652.             metodo = this.getJmxResourceNomeMetodoCheckCertificatiConnettoreHttpsById();
  653.         }
  654.        
  655.         Map<String,List<String>> mapErrori = new HashMap<>();
  656.         Map<String,List<String>> mapWarning = new HashMap<>();
  657.        
  658.         String error = StatoCheck.ERROR.toString();
  659.         String warn = StatoCheck.WARN.toString();
  660.         String ok = StatoCheck.OK.toString();
  661.        
  662.         List<String> nodiRuntimeEsaminati = new ArrayList<>();
  663.         if(useApi) {
  664.             nodiRuntimeEsaminati.add("SDK");
  665.         }
  666.         else {
  667.             nodiRuntimeEsaminati.addAll(this.nodiRuntime);
  668.         }
  669.        
  670.         for (String nomeNodoRuntime : nodiRuntimeEsaminati) {
  671.             String stato = null;
  672.             String descrizione = null;
  673.             String errorDetail = null;
  674.             String warnDetail = null;
  675.             try{        
  676.                 if(useApi) {
  677.                     boolean addCertificateDetails = true;
  678.                     String separator = ": ";
  679.                     String newLine = "\n";
  680.                     try {
  681.                         CertificateCheck statoCheck = null;
  682.                         if(applicativo) {
  683.                             statoCheck = ConfigurazionePdDReader.checkCertificatoApplicativo(((ServizioApplicativo)o), sogliaWarningGiorni,
  684.                                     addCertificateDetails, separator, newLine,
  685.                                     this.getInternalLogger());
  686.                         }
  687.                         else if(soggetto) {
  688.                             statoCheck = RegistroServiziReader.checkCertificatoSoggetto(((Soggetto)o), sogliaWarningGiorni,
  689.                                     addCertificateDetails, separator, newLine,
  690.                                     this.getInternalLogger());
  691.                         }
  692.                         else {
  693.                             throw new CoreException("Incorrect invocation: (useApi:"+useApi+" applicativo:"+applicativo+" soggetto:"+soggetto+")");
  694.                         }
  695.                         stato = statoCheck.toString(newLine);
  696.                     }catch(Exception e){
  697.                         stato = JMXUtils.MSG_OPERAZIONE_NON_EFFETTUATA+e.getMessage();
  698.                     }
  699.                 }
  700.                 else {
  701.                     if(this.config.containsNode(nomeNodoRuntime)) {
  702.                         descrizione = this.config.getDescrizione(nomeNodoRuntime);
  703.                     }
  704.                    
  705.                     if(withId) {
  706.                         stato = this.invoker.invokeJMXMethod(nomeNodoRuntime, this.getJmxResourceType(),
  707.                                 risorsa,
  708.                                 metodo,
  709.                                 idObject, sogliaWarningGiorni);
  710.                     }
  711.                     else {
  712.                         stato = this.invoker.invokeJMXMethod(nomeNodoRuntime, this.getJmxResourceType(),
  713.                                 risorsa,
  714.                                 metodo,
  715.                                 sogliaWarningGiorni);
  716.                     }
  717.                 }
  718.                
  719.                 if(stato!=null && stato.equals(error)){
  720.                     errorDetail = stato;
  721.                 }
  722.                 else if(stato!=null && stato.startsWith(error+"\n")){
  723.                     errorDetail = stato.substring((error+"\n").length());
  724.                 }
  725.                 else if(stato!=null && stato.equals(warn)){
  726.                     warnDetail = warn;
  727.                 }
  728.                 else if(stato!=null && stato.startsWith(warn+"\n")){
  729.                     warnDetail = stato.substring((warn+"\n").length());
  730.                 }
  731.                 else if(stato!=null && stato.startsWith(ok)){
  732.                     // nop
  733.                 }
  734.                 else {
  735.                     errorDetail = stato;
  736.                 }
  737.             }catch(Exception e){
  738.                 this.error(getErrorMessage(risorsa,nomeNodoRuntime,e),e);
  739.                 stato = e.getMessage();
  740.                 errorDetail = stato;
  741.             }
  742.            
  743.             if(errorDetail!=null) {
  744.                 AbstractConfigChecker.addErrore(mapErrori, errorDetail,
  745.                         descrizione!=null ? descrizione : nomeNodoRuntime);
  746.             }
  747.             else if(warnDetail!=null) {
  748.                 AbstractConfigChecker.addErrore(mapWarning, warnDetail,
  749.                         descrizione!=null ? descrizione : nomeNodoRuntime);
  750.             }
  751.         }
  752.        
  753.         if(!mapErrori.isEmpty()) {
  754.             AbstractConfigChecker.printErrore(mapErrori, sbDetailsError, nodiRuntimeEsaminati.size(), getMultipleNodeSeparator());
  755.         }
  756.         else if(!mapWarning.isEmpty()) {
  757.             AbstractConfigChecker.printErrore(mapWarning, sbDetailsWarning, nodiRuntimeEsaminati.size(), getMultipleNodeSeparator());
  758.         }

  759.     }
  760.    
  761.     private void checkCertificateModI(StringBuilder sbDetailsError, StringBuilder sbDetailsWarning,
  762.             int sogliaWarningGiorni,
  763.             Object o) throws CoreException {
  764.        
  765.         String risorsa = null;
  766.         String metodo = null;
  767.         boolean applicativo = false;
  768.         boolean erogazione = false;
  769.         boolean fruizione = false;
  770.         long idObject = -1;
  771.         if(o instanceof ServizioApplicativo) {
  772.             applicativo = true;
  773.         }
  774.         else if(o instanceof org.openspcoop2.core.registry.AccordoServizioParteSpecifica) {
  775.             erogazione = true;
  776.         }
  777.         else if(o instanceof org.openspcoop2.core.registry.Fruitore) {
  778.             fruizione = true;
  779.         }
  780.         else {
  781.             throw new CoreException(getErrorMessageClasseNonGestita(o));
  782.         }
  783.        
  784.         if(applicativo) {
  785.             idObject = ((ServizioApplicativo)o).getId();
  786.             risorsa = this.getJmxResourceNomeRisorsaConfigurazionePdD();
  787.             metodo = this.getJmxResourceNomeMetodoCheckCertificatoModIApplicativoById();
  788.         }
  789.         else if(erogazione) {
  790.             idObject = ((org.openspcoop2.core.registry.AccordoServizioParteSpecifica)o).getId();
  791.             risorsa = this.getJmxResourceNomeRisorsaAccessoRegistroServizi();
  792.             metodo = this.getJmxResourceNomeMetodoCheckCertificatiModIErogazioneById();
  793.         }
  794.         else if(fruizione) {
  795.             idObject = ((org.openspcoop2.core.registry.Fruitore)o).getId();
  796.             risorsa = this.getJmxResourceNomeRisorsaAccessoRegistroServizi();
  797.             metodo = this.getJmxResourceNomeMetodoCheckCertificatiModIFruizioneById();
  798.         }
  799.        
  800.         Map<String,List<String>> mapErrori = new HashMap<>();
  801.         Map<String,List<String>> mapWarning = new HashMap<>();
  802.        
  803.         String error = StatoCheck.ERROR.toString();
  804.         String warn = StatoCheck.WARN.toString();
  805.         String ok = StatoCheck.OK.toString();
  806.        
  807.         for (String nomeNodoRuntime : this.nodiRuntime) {
  808.             String stato = null;
  809.             String descrizione = null;
  810.             String errorDetail = null;
  811.             String warnDetail = null;
  812.             try{        
  813.                 if(this.config.containsNode(nomeNodoRuntime)) {
  814.                     descrizione = this.config.getDescrizione(nomeNodoRuntime);
  815.                 }
  816.                
  817.                 stato = this.invoker.invokeJMXMethod(nomeNodoRuntime, this.getJmxResourceType(),
  818.                         risorsa,
  819.                         metodo,
  820.                         idObject, sogliaWarningGiorni);
  821.                
  822.                 if(stato!=null && stato.equals(error)){
  823.                     errorDetail = stato;
  824.                 }
  825.                 else if(stato!=null && stato.startsWith(error+"\n")){
  826.                     errorDetail = stato.substring((error+"\n").length());
  827.                 }
  828.                 else if(stato!=null && stato.equals(warn)){
  829.                     warnDetail = warn;
  830.                 }
  831.                 else if(stato!=null && stato.startsWith(warn+"\n")){
  832.                     warnDetail = stato.substring((warn+"\n").length());
  833.                 }
  834.                 else if(stato!=null && stato.startsWith(ok)){
  835.                     // nop
  836.                 }
  837.                 else {
  838.                     errorDetail = stato;
  839.                 }
  840.             }catch(Exception e){
  841.                 this.error(getErrorMessage(risorsa,nomeNodoRuntime,e),e);
  842.                 stato = e.getMessage();
  843.                 errorDetail = stato;
  844.             }
  845.            
  846.             if(errorDetail!=null) {
  847.                 AbstractConfigChecker.addErrore(mapErrori, errorDetail,
  848.                         descrizione!=null ? descrizione : nomeNodoRuntime);
  849.             }
  850.             else if(warnDetail!=null) {
  851.                 AbstractConfigChecker.addErrore(mapWarning, warnDetail,
  852.                         descrizione!=null ? descrizione : nomeNodoRuntime);
  853.             }
  854.         }
  855.        
  856.         if(!mapErrori.isEmpty()) {
  857.             AbstractConfigChecker.printErrore(mapErrori, sbDetailsError, this.nodiRuntime.size(), getMultipleNodeSeparator());
  858.         }
  859.         else if(!mapWarning.isEmpty()) {
  860.             AbstractConfigChecker.printErrore(mapWarning, sbDetailsWarning, this.nodiRuntime.size(), getMultipleNodeSeparator());
  861.         }

  862.     }
  863.    
  864.     private void checkCertificateMessageSecurity(StringBuilder sbDetailsError, StringBuilder sbDetailsWarning,
  865.             int sogliaWarningGiorni,
  866.             Object o) throws CoreException {
  867.        
  868.         String risorsa = null;
  869.         String metodo = null;
  870.         boolean erogazione = false;
  871.         boolean fruizione = false;
  872.         long idObject = -1;
  873.         if(o instanceof org.openspcoop2.core.registry.AccordoServizioParteSpecifica) {
  874.             erogazione = true;
  875.         }
  876.         else if(o instanceof org.openspcoop2.core.registry.Fruitore) {
  877.             fruizione = true;
  878.         }
  879.         else {
  880.             throw new CoreException(getErrorMessageClasseNonGestita(o));
  881.         }
  882.        
  883.         if(erogazione) {
  884.             idObject = ((org.openspcoop2.core.registry.AccordoServizioParteSpecifica)o).getId();
  885.             risorsa = this.getJmxResourceNomeRisorsaConfigurazionePdD();
  886.             metodo = this.getJmxResourceNomeMetodoCheckCertificatiMessageSecurityErogazioneById();
  887.         }
  888.         else if(fruizione) {
  889.             idObject = ((org.openspcoop2.core.registry.Fruitore)o).getId();
  890.             risorsa = this.getJmxResourceNomeRisorsaConfigurazionePdD();
  891.             metodo = this.getJmxResourceNomeMetodoCheckCertificatiMessageSecurityFruizioneById();
  892.         }
  893.        
  894.         Map<String,List<String>> mapErrori = new HashMap<>();
  895.         Map<String,List<String>> mapWarning = new HashMap<>();
  896.        
  897.         String error = StatoCheck.ERROR.toString();
  898.         String warn = StatoCheck.WARN.toString();
  899.         String ok = StatoCheck.OK.toString();
  900.        
  901.         for (String nomeNodoRuntime : this.nodiRuntime) {
  902.             String stato = null;
  903.             String descrizione = null;
  904.             String errorDetail = null;
  905.             String warnDetail = null;
  906.             try{        
  907.                 if(this.config.containsNode(nomeNodoRuntime)) {
  908.                     descrizione = this.config.getDescrizione(nomeNodoRuntime);
  909.                 }
  910.                
  911.                 stato = this.invoker.invokeJMXMethod(nomeNodoRuntime, this.getJmxResourceType(),
  912.                         risorsa,
  913.                         metodo,
  914.                         idObject, sogliaWarningGiorni);
  915.                
  916.                 if(stato!=null && stato.equals(error)){
  917.                     errorDetail = stato;
  918.                 }
  919.                 else if(stato!=null && stato.startsWith(error+"\n")){
  920.                     errorDetail = stato.substring((error+"\n").length());
  921.                 }
  922.                 else if(stato!=null && stato.equals(warn)){
  923.                     warnDetail = warn;
  924.                 }
  925.                 else if(stato!=null && stato.startsWith(warn+"\n")){
  926.                     warnDetail = stato.substring((warn+"\n").length());
  927.                 }
  928.                 else if(stato!=null && stato.startsWith(ok)){
  929.                     // nop
  930.                 }
  931.                 else {
  932.                     errorDetail = stato;
  933.                 }
  934.             }catch(Exception e){
  935.                 this.error(getErrorMessage(risorsa,nomeNodoRuntime,e),e);
  936.                 stato = e.getMessage();
  937.                 errorDetail = stato;
  938.             }
  939.            
  940.             if(errorDetail!=null) {
  941.                 AbstractConfigChecker.addErrore(mapErrori, errorDetail,
  942.                         descrizione!=null ? descrizione : nomeNodoRuntime);
  943.             }
  944.             else if(warnDetail!=null) {
  945.                 AbstractConfigChecker.addErrore(mapWarning, warnDetail,
  946.                         descrizione!=null ? descrizione : nomeNodoRuntime);
  947.             }
  948.         }
  949.        
  950.         if(!mapErrori.isEmpty()) {
  951.             AbstractConfigChecker.printErrore(mapErrori, sbDetailsError, this.nodiRuntime.size(), getMultipleNodeSeparator());
  952.         }
  953.         else if(!mapWarning.isEmpty()) {
  954.             AbstractConfigChecker.printErrore(mapWarning, sbDetailsWarning, this.nodiRuntime.size(), getMultipleNodeSeparator());
  955.         }

  956.     }
  957.    
  958.     private void checkCertificateGenericProperties(StringBuilder sbDetailsError, StringBuilder sbDetailsWarning,
  959.             int sogliaWarningGiorni,
  960.             String metodo, String nomePolicy) throws CoreException {
  961.         checkCertificateGenericProperties(sbDetailsError, sbDetailsWarning,
  962.                 sogliaWarningGiorni,
  963.                 metodo, nomePolicy, null);
  964.     }
  965.     private void checkCertificateGenericProperties(StringBuilder sbDetailsError, StringBuilder sbDetailsWarning,
  966.             int sogliaWarningGiorni,
  967.             String metodo, String nomePolicy, String tipo) throws CoreException {
  968.        
  969.         String risorsa = this.getJmxResourceNomeRisorsaConfigurazionePdD();
  970.                
  971.         Map<String,List<String>> mapErrori = new HashMap<>();
  972.         Map<String,List<String>> mapWarning = new HashMap<>();
  973.        
  974.         String error = StatoCheck.ERROR.toString();
  975.         String warn = StatoCheck.WARN.toString();
  976.         String ok = StatoCheck.OK.toString();
  977.        
  978.         for (String nomeNodoRuntime : this.nodiRuntime) {
  979.             String stato = null;
  980.             String descrizione = null;
  981.             String errorDetail = null;
  982.             String warnDetail = null;
  983.             try{        
  984.                 if(this.config.containsNode(nomeNodoRuntime)) {
  985.                     descrizione = this.config.getDescrizione(nomeNodoRuntime);
  986.                 }
  987.                
  988.                 if(tipo!=null) {
  989.                     stato = this.invoker.invokeJMXMethod(nomeNodoRuntime, this.getJmxResourceType(),
  990.                             risorsa,
  991.                             metodo,
  992.                             nomePolicy, tipo, sogliaWarningGiorni);
  993.                 }
  994.                 else {
  995.                     stato = this.invoker.invokeJMXMethod(nomeNodoRuntime, this.getJmxResourceType(),
  996.                             risorsa,
  997.                             metodo,
  998.                             nomePolicy, sogliaWarningGiorni);
  999.                 }
  1000.                
  1001.                 if(stato!=null && stato.equals(error)){
  1002.                     errorDetail = stato;
  1003.                 }
  1004.                 else if(stato!=null && stato.startsWith(error+"\n")){
  1005.                     errorDetail = stato.substring((error+"\n").length());
  1006.                 }
  1007.                 else if(stato!=null && stato.equals(warn)){
  1008.                     warnDetail = warn;
  1009.                 }
  1010.                 else if(stato!=null && stato.startsWith(warn+"\n")){
  1011.                     warnDetail = stato.substring((warn+"\n").length());
  1012.                 }
  1013.                 else if(stato!=null && stato.startsWith(ok)){
  1014.                     // nop
  1015.                 }
  1016.                 else {
  1017.                     errorDetail = stato;
  1018.                 }
  1019.             }catch(Exception e){
  1020.                 this.error(getErrorMessage(risorsa,nomeNodoRuntime,e),e);
  1021.                 stato = e.getMessage();
  1022.                 errorDetail = stato;
  1023.             }
  1024.            
  1025.             if(errorDetail!=null) {
  1026.                 AbstractConfigChecker.addErrore(mapErrori, errorDetail,
  1027.                         descrizione!=null ? descrizione : nomeNodoRuntime);
  1028.             }
  1029.             else if(warnDetail!=null) {
  1030.                 AbstractConfigChecker.addErrore(mapWarning, warnDetail,
  1031.                         descrizione!=null ? descrizione : nomeNodoRuntime);
  1032.             }
  1033.         }
  1034.        
  1035.         if(!mapErrori.isEmpty()) {
  1036.             AbstractConfigChecker.printErrore(mapErrori, sbDetailsError, this.nodiRuntime.size(), getMultipleNodeSeparator());
  1037.         }
  1038.         else if(!mapWarning.isEmpty()) {
  1039.             AbstractConfigChecker.printErrore(mapWarning, sbDetailsWarning, this.nodiRuntime.size(), getMultipleNodeSeparator());
  1040.         }

  1041.     }
  1042. }