CRLCertstoreCache.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.util.Map;

  22. import org.openspcoop2.security.SecurityException;
  23. import org.openspcoop2.security.keystore.CRLCertstore;

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

  32.     @SuppressWarnings("unchecked")
  33.     @Override
  34.     public CRLCertstore createKeystore(String key, Object... params) throws SecurityException{
  35.         if(params==null){
  36.             throw new SecurityException("Params is null");
  37.         }
  38.         if(params.length==0){
  39.             String propertyCrlPath = key;
  40.             return new CRLCertstore(propertyCrlPath);
  41.         }
  42.         else if(params.length==1){
  43.             if( ! (params[0] instanceof Map ) ){
  44.                 throw new SecurityException("Param[0] must be Map<String, byte[]>");
  45.             }
  46.             Map<String, byte[]>  localResources = null;
  47.             try {
  48.                 localResources = (Map<String, byte[]> ) params[0];
  49.             }catch(Exception t) {
  50.                 throw new SecurityException("Param[0] must be Map<String, byte[]>: "+t.getMessage(),t);
  51.             }
  52.             String propertyCrlPath = key;
  53.             return new CRLCertstore(propertyCrlPath, localResources);
  54.         }
  55.         else{
  56.             throw new SecurityException("Params [lenght:"+params.length+"] not supported");
  57.         }
  58.     }

  59.     @Override
  60.     public String getPrefixKey() {
  61.         return "CRLCertstore ";
  62.     }
  63. }