RemoteStoreClientInfoCache.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.RemoteStoreClientInfo;
  23. import org.openspcoop2.utils.certificate.remote.IRemoteStoreProvider;
  24. import org.openspcoop2.utils.certificate.remote.RemoteStoreConfig;

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

  33.     @Override
  34.     public RemoteStoreClientInfo createKeystore(String key, Object... params) throws SecurityException{
  35.         if(params==null){
  36.             throw new SecurityException("Params is null");
  37.         }
  38.         if(params.length==5){
  39.             // key e' formata dalla tripla remoteStoreConfigName, keyId e RemoteKeyType
  40.             if( ! (params[0] instanceof String) ){
  41.                 throw new SecurityException("Param[0] must be String");
  42.             }
  43.             if( ! (params[1] instanceof String) ){
  44.                 throw new SecurityException("Param[1] must be String");
  45.             }
  46.             if( ! (params[2] instanceof RemoteStoreConfig) ){
  47.                 throw new SecurityException("Param[2] must be RemoteStoreConfig");
  48.             }
  49.             if( ! (params[3] instanceof IRemoteStoreProvider) ){
  50.                 throw new SecurityException("Param[3] must be IRemoteStoreProvider");
  51.             }
  52.             if( ! (params[4] instanceof org.openspcoop2.utils.Map) ){
  53.                 throw new SecurityException("Param[4] must be org.openspcoop2.utils.Map");
  54.             }
  55.             String keyId = (String) params[0];
  56.             String clientId = (String) params[1];
  57.             RemoteStoreConfig remoteStoreConfig = (RemoteStoreConfig) params[2];
  58.             IRemoteStoreProvider provider = (IRemoteStoreProvider) params[3];
  59.             org.openspcoop2.utils.Map<Object> context = readMapUtils(params);
  60.             return new RemoteStoreClientInfo(keyId, clientId, remoteStoreConfig, provider, context);
  61.         }
  62.         else{
  63.             throw new SecurityException("Params [lenght:"+params.length+"] not supported");
  64.         }
  65.     }
  66.     @SuppressWarnings("unchecked")
  67.     private org.openspcoop2.utils.Map<Object> readMapUtils(Object... params){
  68.         return (org.openspcoop2.utils.Map<Object>) params[4];
  69.     }

  70.     public static final String RESTORE_STORE_CLIENT_INFO_PREFIX = "RemoteStoreClientInfo ";
  71.    
  72.     @Override
  73.     public String getPrefixKey() {
  74.         return RESTORE_STORE_CLIENT_INFO_PREFIX;
  75.     }
  76.    
  77.     public static String getPrefixKeyCache(RemoteStoreConfig remoteStoreConfig) throws SecurityException {
  78.         if(remoteStoreConfig==null) {
  79.             throw new SecurityException("RemoteStoreConfig undefined");
  80.         }
  81.         String remoteStoreName = remoteStoreConfig.getStoreName();
  82.         if(remoteStoreName==null) {
  83.             throw new SecurityException("RemoteStoreConfig name undefined");
  84.         }
  85.        
  86.         return remoteStoreName+"_";
  87.     }
  88.     public static String getKeyCache(RemoteStoreConfig remoteStoreConfig, String keyId) throws SecurityException {
  89.         // key e' formata dalla tripla remoteStoreConfigName, keyId
  90.         // NOTA: il clientId non serve e comunque non sarebbe più disponibile nella remove della cache
  91.        
  92.         if(keyId==null) {
  93.             throw new SecurityException("KeyId undefined");
  94.         }
  95.        
  96.         return getPrefixKeyCache(remoteStoreConfig)+keyId;
  97.     }
  98. }