RemoteKeyType.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.certificate.remote;

  21. import java.io.Serializable;

  22. /**
  23.  * RemoteKeyType
  24.  *
  25.  * @author Poli Andrea (apoli@link.it)
  26.  * @author $Author$
  27.  * @version $Rev$, $Date$
  28.  */
  29. public enum RemoteKeyType implements Serializable {

  30.     PUBLIC_KEY ("public","Public Key"),
  31.     JWK ("jwk","JWK (Json Web Key)"),
  32.     X509 ("x509","X.509 Certificate");
  33.    
  34.     private final String nome;
  35.     private final String label;

  36.     RemoteKeyType(String nome, String label)
  37.     {
  38.         this.nome = nome;
  39.         this.label = label;
  40.     }

  41.     public String getNome()
  42.     {
  43.         return this.nome;
  44.     }

  45.     public String getLabel() {
  46.         if(this.label!=null) {
  47.             return this.label;
  48.         }
  49.         return this.nome;
  50.     }

  51.    
  52.     @Override
  53.     public String toString() {
  54.         return this.nome;
  55.     }
  56.    
  57.     public static RemoteKeyType toEnumFromName(String name) {
  58.         RemoteKeyType [] tipi = RemoteKeyType.values();
  59.         for (int i = 0; i < tipi.length; i++) {
  60.             RemoteKeyType tipo = tipi[i];
  61.             if(tipo.getNome().equals(name)) {
  62.                 return tipo;
  63.             }
  64.         }
  65.         return null;
  66.     }
  67.     public static RemoteKeyType toEnumFromLabel(String label) {
  68.         RemoteKeyType [] tipi = RemoteKeyType.values();
  69.         for (int i = 0; i < tipi.length; i++) {
  70.             RemoteKeyType tipo = tipi[i];
  71.             if(tipo.getLabel().equals(label)) {
  72.                 return tipo;
  73.             }
  74.         }
  75.         return null;
  76.     }
  77.    
  78. }