OCSPResponseCache.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.security.keystore.cache;

  21. import java.security.cert.X509Certificate;

  22. import org.openspcoop2.security.SecurityException;
  23. import org.openspcoop2.security.keystore.OCSPResponse;
  24. import org.openspcoop2.utils.transport.http.IOCSPValidator;

  25. /**
  26.  * OCSPResponseCache
  27.  *
  28.  * @author Andrea Poli (apoli@link.it)
  29.  * @author $Author$
  30.  * @version $Rev$, $Date$
  31.  */
  32. public class OCSPResponseCache extends AbstractKeystoreCache<OCSPResponse> {

  33.     @Override
  34.     public OCSPResponse createKeystore(String key, Object... params) throws SecurityException{
  35.         if(params==null){
  36.             throw new SecurityException("Params is null");
  37.         }
  38.         else if(params.length==2){
  39.             if(params[0]==null) {
  40.                 throw new SecurityException("Param[0] must be not null");
  41.             }
  42.             if( ! (params[0] instanceof IOCSPValidator ) ){
  43.                 throw new SecurityException("Param[0] must be IOCSPValidator");
  44.             }
  45.             IOCSPValidator validator = (IOCSPValidator) params[0];
  46.            
  47.             if(params[1]==null) {
  48.                 throw new SecurityException("Param[1] must be not null");
  49.             }
  50.             if( ! (params[1] instanceof X509Certificate ) ){
  51.                 throw new SecurityException("Param[1] must be X509Certificate");
  52.             }
  53.             X509Certificate cer = (X509Certificate) params[1];
  54.            
  55.             return new OCSPResponse(validator, cer);
  56.         }
  57.         else{
  58.             throw new SecurityException("Params [lenght:"+params.length+"] not supported");
  59.         }
  60.     }

  61.     @Override
  62.     public String getPrefixKey() {
  63.         return "OCSPResponse ";
  64.     }
  65. }