TipoAutenticazionePrincipal.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 TipoAutenticazionePrincipal implements IEnumeration , Serializable , Cloneable {

  34.     CONTAINER (CostantiConfigurazione.AUTENTICAZIONE_PRINCIPAL_CONTAINER,CostantiConfigurazione.LABEL_AUTENTICAZIONE_PRINCIPAL_CONTAINER),
  35.     HEADER (CostantiConfigurazione.AUTENTICAZIONE_PRINCIPAL_HEADER,CostantiConfigurazione.LABEL_AUTENTICAZIONE_PRINCIPAL_HEADER),
  36.     FORM (CostantiConfigurazione.AUTENTICAZIONE_PRINCIPAL_FORM,CostantiConfigurazione.LABEL_AUTENTICAZIONE_PRINCIPAL_FORM),
  37.     URL (CostantiConfigurazione.AUTENTICAZIONE_PRINCIPAL_URL,CostantiConfigurazione.LABEL_AUTENTICAZIONE_PRINCIPAL_URL),
  38.     INDIRIZZO_IP (CostantiConfigurazione.AUTENTICAZIONE_PRINCIPAL_INDIRIZZO_IP,CostantiConfigurazione.LABEL_AUTENTICAZIONE_PRINCIPAL_INDIRIZZO_IP),
  39.     INDIRIZZO_IP_X_FORWARDED_FOR (CostantiConfigurazione.AUTENTICAZIONE_PRINCIPAL_INDIRIZZO_IP_X_FORWARDED_FOR,CostantiConfigurazione.LABEL_AUTENTICAZIONE_PRINCIPAL_INDIRIZZO_IP_X_FORWARDED_FOR),
  40.     // Ho levato il contenuto, poichè senno devo fare il digest per poterlo poi cachare
  41.     // CONTENT (CostantiConfigurazione.AUTENTICAZIONE_PRINCIPAL_CONTENT,CostantiConfigurazione.LABEL_AUTENTICAZIONE_PRINCIPAL_CONTENT),
  42.     TOKEN (CostantiConfigurazione.AUTENTICAZIONE_PRINCIPAL_TOKEN,CostantiConfigurazione.LABEL_AUTENTICAZIONE_PRINCIPAL_TOKEN);
  43.    
  44.     /** Value */
  45.     private String value;
  46.     private String label;
  47.     public String getLabel() {
  48.         return this.label;
  49.     }
  50.     @Override
  51.     public String getValue()
  52.     {
  53.         return this.value;
  54.     }


  55.     /** Official Constructor */
  56.     TipoAutenticazionePrincipal(String value,String label)
  57.     {
  58.         this.value = value;
  59.         this.label = label;
  60.     }


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