ApiKeyState.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.web.ctrlstat.servlet;

  21. import java.util.ArrayList;
  22. import java.util.List;

  23. import org.openspcoop2.core.commons.ModalitaIdentificazione;
  24. import org.openspcoop2.pdd.core.autenticazione.ParametriAutenticazioneApiKey;
  25. import org.openspcoop2.web.lib.mvc.Costanti;
  26. import org.openspcoop2.web.lib.mvc.ServletUtils;

  27. /**
  28.  * ApiKeyState
  29.  *
  30.  * @author Andrea Poli (apoli@link.it)
  31.  * @author $Author$
  32.  * @version $Rev$, $Date$
  33.  *
  34.  */
  35. public class ApiKeyState {

  36.     // posizione 0: appId
  37.     String appId = null;
  38.     public boolean appIdSelected = false;

  39.     // posizione
  40.     List<String> posizioneValues = new ArrayList<>();
  41.     List<String> posizioneLabels = new ArrayList<>();
  42.     List<String> posizioneSelected = new ArrayList<>();
  43.     // posizione 1: queryParameter
  44.     String queryParameter = Costanti.CHECK_BOX_ENABLED;
  45.     boolean queryParameterEnabled = true;
  46.     // posizione 2: header
  47.     String header = Costanti.CHECK_BOX_ENABLED;
  48.     boolean headerEnabled = true;
  49.     // posizione 3: cookie
  50.     String cookie = Costanti.CHECK_BOX_ENABLED;
  51.     boolean cookieEnabled = true;
  52.    
  53.     // posizione 4: useOAS3Names
  54.     String useOAS3Names = Costanti.CHECK_BOX_ENABLED;
  55.     boolean useOAS3NamesSelected = true;
  56.    
  57.     // posizione 5: cleanApiKey
  58.     String forwardApiKey = null;
  59.     boolean forwardApiKeySelected = false;
  60.    
  61.     // posizione 6: cleanAppId
  62.     String forwardAppId = null;
  63.     boolean forwardAppIdSelected = false;

  64.     // posizione 7: queryParameterApiKey
  65.     String queryParameterApiKey = ParametriAutenticazioneApiKey.DEFAULT_QUERY_PARAMETER_API_KEY;
  66.    
  67.     // posizione 8: headerApiKey
  68.     String headerApiKey = ParametriAutenticazioneApiKey.DEFAULT_HEADER_API_KEY;
  69.    
  70.     // posizione 9: cookieApiKey
  71.     String cookieApiKey = ParametriAutenticazioneApiKey.DEFAULT_COOKIE_API_KEY;
  72.    
  73.     // posizione 10: queryParameterAppId
  74.     String queryParameterAppId = ParametriAutenticazioneApiKey.DEFAULT_QUERY_PARAMETER_APP_ID;
  75.    
  76.     // posizione 11: headerAppId
  77.     String headerAppId = ParametriAutenticazioneApiKey.DEFAULT_HEADER_APP_ID;
  78.    
  79.     // posizione 12: cookieAppId
  80.     String cookieAppId = ParametriAutenticazioneApiKey.DEFAULT_COOKIE_APP_ID;
  81.    
  82.     public ApiKeyState(List<String> autenticazioneParametroList){

  83.         this.posizioneValues.add(ParametriAutenticazioneApiKey.QUERY_PARAMETER);
  84.         this.posizioneValues.add(ParametriAutenticazioneApiKey.HEADER);
  85.         this.posizioneValues.add(ParametriAutenticazioneApiKey.COOKIE);
  86.        
  87.         this.posizioneLabels.add(ModalitaIdentificazione.FORM_BASED.getLabel());
  88.         this.posizioneLabels.add(ModalitaIdentificazione.HEADER_BASED.getLabel());
  89.         this.posizioneLabels.add(ModalitaIdentificazione.COOKIE_BASED.getLabel());
  90.        
  91.         this.posizioneSelected.addAll(this.posizioneValues);// default
  92.        
  93.         if(autenticazioneParametroList!=null && !autenticazioneParametroList.isEmpty()) {
  94.             if(autenticazioneParametroList.size()>0) {
  95.                 this.appId = autenticazioneParametroList.get(0);
  96.                 this.appIdSelected = ServletUtils.isCheckBoxEnabled(this.appId);
  97.             }
  98.             if(autenticazioneParametroList.size()>1) {
  99.                 this.posizioneSelected = new ArrayList<>();
  100.                 this.queryParameter = autenticazioneParametroList.get(1);
  101.                 this.queryParameterEnabled = ServletUtils.isCheckBoxEnabled(this.queryParameter);
  102.                 if(this.queryParameterEnabled) {
  103.                     this.posizioneSelected.add(ParametriAutenticazioneApiKey.QUERY_PARAMETER);
  104.                 }
  105.             }
  106.             if(autenticazioneParametroList.size()>2) {
  107.                 this.header = autenticazioneParametroList.get(2);
  108.                 this.headerEnabled = ServletUtils.isCheckBoxEnabled(this.header);
  109.                 if(this.headerEnabled) {
  110.                     this.posizioneSelected.add(ParametriAutenticazioneApiKey.HEADER);
  111.                 }
  112.             }
  113.             if(autenticazioneParametroList.size()>3) {
  114.                 this.cookie = autenticazioneParametroList.get(3);
  115.                 this.cookieEnabled = ServletUtils.isCheckBoxEnabled(this.cookie);
  116.                 if(this.cookieEnabled) {
  117.                     this.posizioneSelected.add(ParametriAutenticazioneApiKey.COOKIE);
  118.                 }
  119.             }
  120.             if(autenticazioneParametroList.size()>4) {
  121.                 this.useOAS3Names = autenticazioneParametroList.get(4);
  122.                 this.useOAS3NamesSelected = ServletUtils.isCheckBoxEnabled(this.useOAS3Names);
  123.             }
  124.             if(autenticazioneParametroList.size()>5) {
  125.                 String cleanApiKey = autenticazioneParametroList.get(5);
  126.                 if(ServletUtils.isCheckBoxEnabled(cleanApiKey)) {
  127.                     this.forwardApiKey = Costanti.CHECK_BOX_DISABLED;
  128.                 }
  129.                 else {
  130.                     this.forwardApiKey = Costanti.CHECK_BOX_ENABLED;
  131.                 }
  132.                 this.forwardApiKeySelected = ServletUtils.isCheckBoxEnabled(this.forwardApiKey);
  133.             }
  134.             if(autenticazioneParametroList.size()>6) {
  135.                 String cleanAppId = autenticazioneParametroList.get(6);
  136.                 if(ServletUtils.isCheckBoxEnabled(cleanAppId)) {
  137.                     this.forwardAppId = Costanti.CHECK_BOX_DISABLED;
  138.                 }
  139.                 else {
  140.                     this.forwardAppId = Costanti.CHECK_BOX_ENABLED;
  141.                 }
  142.                 this.forwardAppIdSelected = ServletUtils.isCheckBoxEnabled(this.forwardAppId);
  143.             }
  144.             if(autenticazioneParametroList.size()>7) {
  145.                 this.queryParameterApiKey = autenticazioneParametroList.get(7);
  146.             }
  147.             if(autenticazioneParametroList.size()>8) {
  148.                 this.headerApiKey = autenticazioneParametroList.get(8);
  149.             }
  150.             if(autenticazioneParametroList.size()>9) {
  151.                 this.cookieApiKey = autenticazioneParametroList.get(9);
  152.             }
  153.             if(autenticazioneParametroList.size()>10) {
  154.                 this.queryParameterAppId = autenticazioneParametroList.get(10);
  155.             }
  156.             if(autenticazioneParametroList.size()>11) {
  157.                 this.headerAppId = autenticazioneParametroList.get(11);
  158.             }
  159.             if(autenticazioneParametroList.size()>12) {
  160.                 this.cookieAppId = autenticazioneParametroList.get(12);
  161.             }
  162.         }
  163.     }
  164.    
  165. }