CredenzialeTrasporto.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.core.transazioni.utils.credenziali;

  21. import org.openspcoop2.core.config.constants.TipoAutenticazione;
  22. import org.openspcoop2.core.transazioni.utils.TipoCredenzialeMittente;
  23. import org.openspcoop2.utils.UtilsException;
  24. import org.openspcoop2.utils.certificate.CertificateUtils;
  25. import org.openspcoop2.utils.certificate.PrincipalType;

  26. /**    
  27.  * CredenzialeTrasporto
  28.  *
  29.  * @author Poli Andrea (poli@link.it)
  30.  * @author $Author$
  31.  * @version $Rev$, $Date$
  32.  */
  33. public class CredenzialeTrasporto extends AbstractCredenziale {

  34.     private String tipoAutenticazione;
  35.     private String credential;
  36.    
  37.     public CredenzialeTrasporto(String tipoAutenticazione, String credential) {
  38.         super(TipoCredenzialeMittente.TRASPORTO);
  39.         this.tipoAutenticazione = tipoAutenticazione;
  40.         this.credential = credential;
  41.     }
  42.    
  43.     @Override
  44.     public String getTipo() {
  45.         return getTipoTrasporto(this.tipo, this.tipoAutenticazione);
  46.     }

  47.     public static String getTipoTrasporto(TipoCredenzialeMittente tipo, String tipoAutenticazione) {
  48.         return tipo.getRawValue()+"_"+tipoAutenticazione;
  49.     }
  50.    
  51.     @Override
  52.     public String getCredenziale() throws UtilsException {
  53.         if(isSsl(this.tipoAutenticazione)) {
  54.             return CertificateUtils.formatPrincipal(this.credential, PrincipalType.SUBJECT);
  55.         }
  56.         else {
  57.             return this.credential;
  58.         }
  59.     }
  60.    
  61.     public boolean isSsl() {
  62.         return TipoAutenticazione.SSL.getValue().equalsIgnoreCase(this.tipoAutenticazione);
  63.     }
  64.    
  65.     public static boolean isSsl(String tipoAutenticazione) {
  66.         return TipoAutenticazione.SSL.getValue().equalsIgnoreCase(tipoAutenticazione);
  67.     }
  68.    
  69.     @Override
  70.     public void updateCredenziale(String newCredential) throws UtilsException{
  71.         this.credential = newCredential;
  72.     }
  73. }