OCSPProvider.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.utils.certificate.ocsp;

  21. import java.util.ArrayList;
  22. import java.util.List;

  23. import org.openspcoop2.utils.SortedMap;

  24. /**    
  25.  * OCSPProvider
  26.  *
  27.  * @author Poli Andrea (poli@link.it)
  28.  * @author $Author$
  29.  * @version $Rev$, $Date$
  30.  */
  31. public class OCSPProvider {
  32.    
  33.     private boolean ocsp = false;
  34.     public boolean isOcspEnabled() {
  35.         return this.ocsp;
  36.     }
  37.     private List<String> ocspTypes = new ArrayList<>();
  38.     private List<String> ocspLabels = new ArrayList<>();
  39.     private static final String NO_OCSP = "--no_ocsp--";
  40.     private static List<String> noOCSP = new ArrayList<>();
  41.     static{
  42.         noOCSP.add(NO_OCSP);    
  43.     }
  44.     public OCSPProvider() {
  45.         SortedMap<String> ocspSortedMap = OCSPManager.getInstance().getOCSPConfigTypesLabels();
  46.         this.ocsp = ocspSortedMap!=null && !ocspSortedMap.isEmpty();
  47.         if(this.ocsp) {
  48.             List<String> ocspTypesAdd = new ArrayList<>();
  49.             List<String> ocspLabelsAdd = new ArrayList<>();
  50.             if(!ocspSortedMap.isEmpty()) {
  51.                 for (String type : ocspSortedMap.keys()) {
  52.                     ocspTypesAdd.add(type);
  53.                     ocspLabelsAdd.add(ocspSortedMap.get(type));
  54.                 }
  55.             }
  56.             boolean ocspEnabled = !ocspTypesAdd.isEmpty();
  57.             if(ocspEnabled) {
  58.                 this.ocspTypes.add("");
  59.                 this.ocspTypes.addAll(ocspTypesAdd);
  60.                 this.ocspLabels.add("-");
  61.                 this.ocspLabels.addAll(ocspLabelsAdd);
  62.             }
  63.         }
  64.     }
  65.    
  66.     public List<String> getValues() {
  67.         return this.ocsp ? this.ocspTypes : noOCSP;
  68.     }

  69.     public List<String> getLabels() {
  70.         return this.ocsp ? this.ocspLabels : noOCSP;
  71.     }
  72.    
  73. }