TipoAutenticazione.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.config.constants;

  21. import java.io.Serializable;
  22. import java.util.ArrayList;
  23. import java.util.List;

  24. import org.openspcoop2.generic_project.beans.IEnumeration;
  25. import org.openspcoop2.generic_project.exception.NotFoundException;

  26. /**    
  27.  * Enumeration TipoAutenticazione
  28.  *
  29.  * @author Poli Andrea (poli@link.it)
  30.  * @author $Author$
  31.  * @version $Rev$, $Date$
  32.  */
  33. public enum TipoAutenticazione implements IEnumeration , Serializable , Cloneable {

  34.     DISABILITATO (CostantiConfigurazione.AUTENTICAZIONE_NONE,CostantiConfigurazione.LABEL_CREDENZIALE_DISABILITATO),
  35.     SSL (CostantiConfigurazione.AUTENTICAZIONE_SSL,CostantiConfigurazione.LABEL_CREDENZIALE_SSL),
  36.     BASIC (CostantiConfigurazione.AUTENTICAZIONE_BASIC,CostantiConfigurazione.LABEL_CREDENZIALE_BASIC),
  37.     APIKEY (CostantiConfigurazione.AUTENTICAZIONE_APIKEY,CostantiConfigurazione.LABEL_CREDENZIALE_APIKEY),
  38.     PRINCIPAL (CostantiConfigurazione.AUTENTICAZIONE_PRINCIPAL,CostantiConfigurazione.LABEL_CREDENZIALE_PRINCIPAL);
  39.    
  40.     /** Value */
  41.     private String value;
  42.     private String label;
  43.     public String getLabel() {
  44.         return this.label;
  45.     }
  46.     @Override
  47.     public String getValue()
  48.     {
  49.         return this.value;
  50.     }


  51.     /** Official Constructor */
  52.     TipoAutenticazione(String value,String label)
  53.     {
  54.         this.value = value;
  55.         this.label = label;
  56.     }


  57.    
  58.     @Override
  59.     public String toString(){
  60.         return this.value;
  61.     }
  62.     public boolean equals(String object){
  63.         if(object==null)
  64.             return false;
  65.         return object.equals(this.getValue());  
  66.     }
  67.    
  68.        
  69.    
  70.     /** compatibility with the generated bean (reflection) */
  71.     public boolean equals(Object object,List<String> fieldsNotCheck){
  72.         if( !(object instanceof TipoAutenticazione) ){
  73.             throw new RuntimeException("Wrong type: "+object.getClass().getName());
  74.         }
  75.         return this.equals(((TipoAutenticazione)object));
  76.     }
  77.     public String toString(boolean reportHTML){
  78.         return toString();
  79.     }
  80.     public String toString(boolean reportHTML,List<String> fieldsNotIncluded){
  81.         return toString();
  82.     }
  83.     public String diff(Object object,StringBuilder bf,boolean reportHTML){
  84.         return bf.toString();
  85.     }
  86.     public String diff(Object object,StringBuilder bf,boolean reportHTML,List<String> fieldsNotIncluded){
  87.         return bf.toString();
  88.     }
  89.    
  90.    
  91.     /** Utilities */
  92.    
  93.     public static List<String> getValues(){
  94.         List<String> l = new ArrayList<>();
  95.         for (TipoAutenticazione tmp : values()) {
  96.             l.add(tmp.getValue());
  97.         }
  98.         return l;
  99.     }
  100.     public static List<String> getLabels(){
  101.         List<String> l = new ArrayList<>();
  102.         for (TipoAutenticazione tmp : values()) {
  103.             l.add(tmp.getLabel());
  104.         }
  105.         return l;
  106.     }
  107.    
  108.     public static String[] toArray(){
  109.         String[] res = new String[values().length];
  110.         int i=0;
  111.         for (TipoAutenticazione tmp : values()) {
  112.             res[i]=tmp.getValue();
  113.             i++;
  114.         }
  115.         return res;
  116.     }  
  117.     public static String[] toStringArray(){
  118.         String[] res = new String[values().length];
  119.         int i=0;
  120.         for (TipoAutenticazione tmp : values()) {
  121.             res[i]=tmp.toString();
  122.             i++;
  123.         }
  124.         return res;
  125.     }
  126.     public static String[] toEnumNameArray(){
  127.         String[] res = new String[values().length];
  128.         int i=0;
  129.         for (TipoAutenticazione tmp : values()) {
  130.             res[i]=tmp.name();
  131.             i++;
  132.         }
  133.         return res;
  134.     }
  135.    
  136.     public static boolean contains(String value){
  137.         return toEnumConstant(value)!=null;
  138.     }
  139.    
  140.     public static TipoAutenticazione toEnumConstant(String value){
  141.         try{
  142.             return toEnumConstant(value,false);
  143.         }catch(NotFoundException notFound){
  144.             return null;
  145.         }
  146.     }
  147.     public static TipoAutenticazione toEnumConstant(String value, boolean throwNotFoundException) throws NotFoundException{
  148.         TipoAutenticazione res = null;
  149.         for (TipoAutenticazione tmp : values()) {
  150.             if(tmp.getValue().equals(value)){
  151.                 res = tmp;
  152.                 break;
  153.             }
  154.         }
  155.         if(res==null && throwNotFoundException){
  156.             throw new NotFoundException("Enum with value ["+value+"] not found");
  157.         }
  158.         return res;
  159.     }
  160.    
  161.     public static IEnumeration toEnumConstantFromString(String value){
  162.         try{
  163.             return toEnumConstantFromString(value,false);
  164.         }catch(NotFoundException notFound){
  165.             return null;
  166.         }
  167.     }
  168.     public static IEnumeration toEnumConstantFromString(String value, boolean throwNotFoundException) throws NotFoundException{
  169.         TipoAutenticazione res = null;
  170.         for (TipoAutenticazione tmp : values()) {
  171.             if(tmp.toString().equals(value)){
  172.                 res = tmp;
  173.                 break;
  174.             }
  175.         }
  176.         if(res==null && throwNotFoundException){
  177.             throw new NotFoundException("Enum with value ["+value+"] not found");
  178.         }
  179.         return res;
  180.     }
  181. }