ModIAuditClaimConfig.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.protocol.modipa.config;

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

  24. import org.apache.commons.lang.StringUtils;
  25. import org.openspcoop2.protocol.sdk.ProtocolException;

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

  34.     public static final String PROPERTY_NOME = "nome";
  35.     public static final String PROPERTY_LABEL = "label";
  36.     public static final String PROPERTY_REQUIRED = "required";
  37.     public static final String PROPERTY_CACHEABLE = "cacheable";
  38.     public static final String PROPERTY_STRING_TYPE = "stringType";
  39.     public static final String PROPERTY_REGEXP = "regexp";
  40.     public static final String PROPERTY_ENUM = "enum";
  41.     public static final String PROPERTY_MIN_LENGTH = "minLength";
  42.     public static final String PROPERTY_MAX_LENGTH = "maxLength";
  43.     public static final String PROPERTY_INFO = "info";
  44.     public static final String PROPERTY_DEFAULT_RULE = "rule";
  45.     public static final String PROPERTY_DEFAULT_RULE_INFO = "rule.info";
  46.     public static final String PROPERTY_FORWARD_BACKEND = "forwardBackend";
  47.     public static final String PROPERTY_TRACE = "trace";
  48.    
  49.     private ModIAuditClaimConfig() {}
  50.     ModIAuditClaimConfig(String prefix, String propertyId, Properties p) throws ProtocolException {
  51.        
  52.         this.propertyId = propertyId;
  53.        
  54.         this.nome = ModIAuditConfig.getProperty(prefix, p, ModIAuditConfig.PROPERTY_CLAIMS+"."+propertyId+"."+PROPERTY_NOME, true);
  55.         this.label = ModIAuditConfig.getProperty(prefix, p, ModIAuditConfig.PROPERTY_CLAIMS+"."+propertyId+"."+PROPERTY_LABEL, true);
  56.         this.required = ModIAuditConfig.getBooleanProperty(prefix, p, ModIAuditConfig.PROPERTY_CLAIMS+"."+propertyId+"."+PROPERTY_REQUIRED, true, true);
  57.         this.cacheable = ModIAuditConfig.getBooleanProperty(prefix, p, ModIAuditConfig.PROPERTY_CLAIMS+"."+propertyId+"."+PROPERTY_CACHEABLE, false, true);
  58.         this.stringType = ModIAuditConfig.getBooleanProperty(prefix, p, ModIAuditConfig.PROPERTY_CLAIMS+"."+propertyId+"."+PROPERTY_STRING_TYPE, true, true);
  59.        
  60.         this.regexp = ModIAuditConfig.getProperty(prefix, p, ModIAuditConfig.PROPERTY_CLAIMS+"."+propertyId+"."+PROPERTY_REGEXP, false);
  61.        
  62.         String tmp = ModIAuditConfig.getProperty(prefix, p, ModIAuditConfig.PROPERTY_CLAIMS+"."+propertyId+"."+PROPERTY_ENUM, false);
  63.         if(tmp!=null && StringUtils.isNotEmpty(tmp)) {
  64.             this.values = new ArrayList<>();
  65.             setList(tmp, this.values);
  66.         }
  67.        
  68.         this.minLength = ModIAuditConfig.getIntProperty(prefix, p, ModIAuditConfig.PROPERTY_CLAIMS+"."+propertyId+"."+PROPERTY_MIN_LENGTH, false, -1);
  69.         this.maxLength = ModIAuditConfig.getIntProperty(prefix, p, ModIAuditConfig.PROPERTY_CLAIMS+"."+propertyId+"."+PROPERTY_MAX_LENGTH, false, -1);
  70.        
  71.         this.info = ModIAuditConfig.getProperty(prefix, p, ModIAuditConfig.PROPERTY_CLAIMS+"."+propertyId+"."+PROPERTY_INFO, true);
  72.        
  73.         tmp = ModIAuditConfig.getProperty(prefix, p, ModIAuditConfig.PROPERTY_CLAIMS+"."+propertyId+"."+PROPERTY_DEFAULT_RULE, true);
  74.         this.rules = new ArrayList<>();
  75.         setList(tmp, this.rules);
  76.            
  77.         tmp = ModIAuditConfig.getProperty(prefix, p, ModIAuditConfig.PROPERTY_CLAIMS+"."+propertyId+"."+PROPERTY_DEFAULT_RULE_INFO, true);
  78.         this.rulesInfo = new ArrayList<>();
  79.         setList(tmp, this.rulesInfo);
  80.        
  81.         this.forwardBackend = ModIAuditConfig.getProperty(prefix, p, ModIAuditConfig.PROPERTY_CLAIMS+"."+propertyId+"."+PROPERTY_FORWARD_BACKEND, false);
  82.        
  83.         this.trace = ModIAuditConfig.getBooleanProperty(prefix, p, ModIAuditConfig.PROPERTY_CLAIMS+"."+propertyId+"."+PROPERTY_TRACE, true, true);
  84.     }
  85.    
  86.     private static void setList(String v, List<String> list) {
  87.         String [] split = v.split(",");
  88.         if(split!=null && split.length>0) {
  89.             for (String s : split) {
  90.                 if(s!=null) {
  91.                     s = s.trim();
  92.                     if(StringUtils.isNotEmpty(s)) {
  93.                         list.add(s);
  94.                     }
  95.                 }
  96.             }
  97.         }
  98.     }
  99.        
  100.     private String propertyId;

  101.     private String nome;
  102.     private String label;
  103.     private boolean required;
  104.     private boolean cacheable;
  105.     private boolean stringType;
  106.     private String regexp;
  107.     private List<String> values;
  108.     private int minLength;
  109.     private int maxLength;
  110.     private String info;
  111.     private List<String> rules;
  112.     private List<String> rulesInfo;
  113.     private String forwardBackend;
  114.     private boolean trace;
  115.    
  116.     public ModIAuditClaimConfig copyNewInstance() {
  117.         ModIAuditClaimConfig newInstance = new ModIAuditClaimConfig();
  118.         newInstance.propertyId = this.propertyId;
  119.         newInstance.nome = this.nome;
  120.         newInstance.label = this.label;
  121.         newInstance.required = this.required;
  122.         newInstance.cacheable = this.cacheable;
  123.         newInstance.stringType = this.stringType;
  124.         newInstance.regexp = this.regexp;
  125.        
  126.         newInstance.values = new ArrayList<>();
  127.         if(this.values!=null && !this.values.isEmpty()) {
  128.             newInstance.values.addAll(this.values);
  129.         }
  130.        
  131.         newInstance.minLength = this.minLength;
  132.         newInstance.maxLength = this.maxLength;
  133.        
  134.         newInstance.info = this.info;
  135.        
  136.         newInstance.rules = new ArrayList<>();
  137.         if(this.rules!=null && !this.rules.isEmpty()) {
  138.             newInstance.rules.addAll(this.rules);
  139.         }
  140.        
  141.         newInstance.rulesInfo = new ArrayList<>();
  142.         if(this.rulesInfo!=null && !this.rulesInfo.isEmpty()) {
  143.             newInstance.rulesInfo.addAll(this.rulesInfo);
  144.         }
  145.        
  146.         newInstance.forwardBackend = this.forwardBackend;
  147.         newInstance.trace = this.trace;
  148.         return newInstance;
  149.     }
  150.    
  151.     public String getPropertyId() {
  152.         return this.propertyId;
  153.     }

  154.     public String getNome() {
  155.         return this.nome;
  156.     }
  157.    
  158.     public String getLabel() {
  159.         return this.label;
  160.     }

  161.     public boolean isRequired() {
  162.         return this.required;
  163.     }
  164.    
  165.     public boolean isCacheable() {
  166.         return this.cacheable;
  167.     }

  168.     public boolean isStringType() {
  169.         return this.stringType;
  170.     }

  171.     public String getRegexp() {
  172.         return this.regexp;
  173.     }
  174.    
  175.     public List<String> getValues() {
  176.         return this.values;
  177.     }
  178.    
  179.     public int getMinLength() {
  180.         return this.minLength;
  181.     }
  182.     public int getMaxLength() {
  183.         return this.maxLength;
  184.     }
  185.    
  186.     public String getInfo() {
  187.         return this.info;
  188.     }

  189.     public List<String> getRules() {
  190.         return this.rules;
  191.     }
  192.     public void setRules(List<String> rules) {
  193.         this.rules = rules;
  194.     }
  195.    
  196.     public List<String> getRulesInfo() {
  197.         return this.rulesInfo;
  198.     }
  199.     public void setRulesInfo(List<String> rulesInfo) {
  200.         this.rulesInfo = rulesInfo;
  201.     }

  202.     public String getForwardBackend() {
  203.         return this.forwardBackend;
  204.     }
  205.     public void setForwardBackend(String forwardBackend) {
  206.         this.forwardBackend = forwardBackend;
  207.     }
  208.    
  209.     public boolean isTrace() {
  210.         return this.trace;
  211.     }
  212.     public void setTrace(boolean trace) {
  213.         this.trace = trace;
  214.     }
  215. }