PrincipalReaderFactory.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.utils.transport.http.credential;

  21. import java.lang.reflect.Constructor;

  22. import org.slf4j.Logger;

  23. /**
  24.  * Factory per i PrincipalReader
  25.  *
  26.  * @author Pintori Giuliano (pintori@link.it)
  27.  * @author $Author$
  28.  * @version $Rev$, $Date$
  29.  */
  30. public class PrincipalReaderFactory {
  31.    
  32.     public static IPrincipalReader getReader(Logger log, String nomePrincipalReader) throws PrincipalReaderException{
  33.        
  34.         log.debug("Caricamento Principal Reader ["+nomePrincipalReader+"] in corso...");
  35.        
  36.         PrincipalReaderType principalReaderType = PrincipalReaderType.toEnumConstant(nomePrincipalReader);
  37.        
  38.         String className = null;
  39.         if(principalReaderType != null){
  40.             switch(principalReaderType){
  41.             case PRINCIPAL:
  42.                 return new IdentityPrincipalReader(log);
  43.             case HEADER:
  44.                 return new IdentityHttpReader(log);
  45.             }
  46.         } else {
  47.             // se non ho trovato una classe corrispondente al paramentro allora carico la classe indicata
  48.             className = nomePrincipalReader;
  49.         }
  50.        
  51.         log.debug("Caricamento classe ["+className+"] in corso...");
  52.         try{
  53.             Class<?> c = Class.forName(className);
  54.             Constructor<?> constructor = c.getConstructor(Logger.class);
  55.             IPrincipalReader p = (IPrincipalReader) constructor.newInstance(log);
  56.             return  p;
  57.         } catch (Exception e) {
  58.             throw new PrincipalReaderException("Impossibile caricare la classe indicata ["+className+"] " + e.getMessage(), e);
  59.         }
  60.     }
  61. }