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

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

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

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