ExternalResourceCache.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.ExternalResource;
  23. import org.openspcoop2.utils.transport.http.ExternalResourceConfig;

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

  32.     @Override
  33.     public ExternalResource createKeystore(String key, Object... params) throws SecurityException{
  34.         if(params==null){
  35.             throw new SecurityException("Params is null");
  36.         }
  37.         if(params.length==0){
  38.             return new ExternalResource(key, key, new ExternalResourceConfig()); // l'id della risorsa esterna è la url stessa della risorsa, non serve un id aggiuntivo
  39.         }
  40.         else if(params.length==1){
  41.             if( params[0]!=null && !(params[0] instanceof ExternalResourceConfig) ){
  42.                 throw new SecurityException("Param[0] must be ExternalResourceConfig");
  43.             }
  44.             ExternalResourceConfig externalConfig = (params[0]==null) ? new ExternalResourceConfig() : (ExternalResourceConfig) params[0];
  45.             return new ExternalResource(key, key, externalConfig); // l'id della risorsa esterna è la url stessa della risorsa, non serve un id aggiuntivo
  46.         }
  47.         else{
  48.             throw new SecurityException("Params [lenght:"+params.length+"] not supported");
  49.         }
  50.     }

  51.     @Override
  52.     public String getPrefixKey() {
  53.         return "ExternalResource ";
  54.     }
  55. }