MerlinTruststoreCache.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 org.openspcoop2.security.SecurityException;
  22. import org.openspcoop2.security.keystore.MerlinTruststore;

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

  31.     @Override
  32.     public MerlinTruststore createKeystore(String key, Object... params) throws SecurityException{
  33.         if(params==null){
  34.             throw new SecurityException("Params is null");
  35.         }
  36.         if(params.length==0){
  37.             String propertyFilePath = key;
  38.             return new MerlinTruststore(propertyFilePath);
  39.         }
  40.         else if(params.length==2){
  41.             if( ! (params[0] instanceof String) ){
  42.                 throw new SecurityException("Param[0] must be String (tipoStore)");
  43.             }
  44.             if( params[1]!=null && ! (params[1] instanceof String) ){
  45.                 throw new SecurityException("Param[1] must be String (passwordStore)");
  46.             }
  47.             String pathStore = key;
  48.             String tipoStore = (String) params[0];
  49.             String passwordStore = (String) params[1];
  50.             return new MerlinTruststore(pathStore, tipoStore, passwordStore);
  51.         }
  52.         else if(params.length==3){
  53.             if( ! (params[0] instanceof byte[]) ){
  54.                 throw new SecurityException("Param[0] must be byte[] (store)");
  55.             }
  56.             if( ! (params[1] instanceof String) ){
  57.                 throw new SecurityException("Param[1] must be String (tipoStore)");
  58.             }
  59.             if( params[2]!=null && ! (params[2] instanceof String) ){
  60.                 throw new SecurityException("Param[2] must be String (passwordStore)");
  61.             }
  62.             byte [] store = (byte[]) params[0];
  63.             String tipoStore = (String) params[1];
  64.             String passwordStore = (String) params[2];
  65.             return new MerlinTruststore(store, tipoStore, passwordStore);
  66.         }
  67.         else{
  68.             throw new SecurityException("Params [lenght:"+params.length+"] not supported");
  69.         }
  70.     }

  71.     @Override
  72.     public String getPrefixKey() {
  73.         return "Truststore ";
  74.     }
  75. }