SymmetricKeystoreCache.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.SymmetricKeystore;
  23. import org.openspcoop2.utils.certificate.byok.BYOKRequestParams;

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

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

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