SAMLBuilderConfig.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.security.message.saml;

  21. import java.io.File;
  22. import java.io.FileInputStream;
  23. import java.io.IOException;
  24. import java.io.InputStream;
  25. import java.text.SimpleDateFormat;
  26. import java.util.ArrayList;
  27. import java.util.Collections;
  28. import java.util.Date;
  29. import java.util.Enumeration;
  30. import java.util.List;
  31. import java.util.Map;
  32. import java.util.Properties;
  33. import java.util.concurrent.ConcurrentHashMap;

  34. import org.apache.wss4j.common.crypto.Crypto;
  35. import org.apache.wss4j.common.crypto.CryptoFactory;
  36. import org.apache.wss4j.common.saml.bean.Version;
  37. import org.opensaml.saml.saml2.core.NameIDType;
  38. import org.openspcoop2.core.commons.DBUtils;
  39. import org.openspcoop2.protocol.sdk.state.RequestInfo;
  40. import org.openspcoop2.security.keystore.KeystoreConstants;
  41. import org.openspcoop2.utils.SemaphoreLock;
  42. import org.openspcoop2.utils.Utilities;
  43. import org.openspcoop2.utils.certificate.KeystoreType;

  44. /**
  45.  * SAMLCallbackHandler
  46.  *  
  47.  * @author Andrea Poli (apoli@link.it)
  48.  * @author $Author$
  49.  * @version $Rev$, $Date$
  50.  */
  51. public class SAMLBuilderConfig {

  52.     // ---- STATIC CONFIG CACHE -----
  53.    
  54.     private static Map<String, SAMLBuilderConfig> samlCacheConfig = new ConcurrentHashMap<>();
  55.     private static org.openspcoop2.utils.Semaphore semaphore = new org.openspcoop2.utils.Semaphore("SAMLBuilderConfig");
  56.     private static void addSamlConfig(String propertiesName,SAMLBuilderConfig p){
  57.         SemaphoreLock lock = semaphore.acquireThrowRuntime("addSamlConfig");
  58.         try {
  59.             if(!samlCacheConfig.containsKey(propertiesName)){
  60.                 samlCacheConfig.put(propertiesName, p);
  61.             }
  62.         }finally {
  63.             semaphore.release(lock, "addSamlConfig");
  64.         }
  65.     }
  66.     public static SAMLBuilderConfig getSamlConfig(String properties, RequestInfo requestInfo) throws IOException {
  67.         InputStream is = null;
  68.         try{
  69.             File f = new File(properties);
  70.             if(f.exists()){
  71.                 is = new FileInputStream(f);
  72.             }
  73.             else{
  74.                 is = SAMLBuilderConfig.class.getResourceAsStream("/"+properties);
  75.             }
  76.             if(is==null){
  77.                 throw new IOException("SAMLPropFile ["+properties+"]: not found");
  78.             }
  79.             try{
  80.                 return getSamlConfig(Utilities.getAsProperties(is), requestInfo);
  81.             }catch(Exception e){
  82.                 throw new IOException("SAMLPropFile ["+properties+"]: "+e.getMessage(),e);
  83.             }      
  84.         }
  85.         finally{
  86.             try{
  87.                 if(is!=null){
  88.                     is.close();
  89.                 }
  90.             }catch(Exception eClose){
  91.                 // close
  92.             }
  93.         }
  94.     }

  95.     private static final String SAML_CONFIG_BUILD_PROPERTY_PREFIX = "SAML Config Builder: property [";
  96.     private static final String SAML_CONFIG_BUILD_REQUIRED_PROPERTY_PREFIX = "SAML Config Builder: required property [";
  97.     private static final String SAML_CONFIG_BUILD_PROPERTY_OR = "] or [";
  98.     private static final String SAML_CONFIG_BUILD_PROPERTY_IF_USE = "] if use property [";
  99.    
  100.     public static SAMLBuilderConfig getSamlConfig(Properties p, RequestInfo requestInfoParam) throws IOException {
  101.        
  102.         String propertiesName = p.getProperty(SAMLBuilderConfigConstants.SAML_CONFIG_BUILDER_CONFIG_NAME);
  103.         if(propertiesName!=null){
  104.             propertiesName = propertiesName.trim();
  105.         }
  106.        
  107.         boolean cacheConfig = isTrue(p, SAMLBuilderConfigConstants.SAML_CONFIG_BUILDER_CACHE, false);
  108.         if(cacheConfig && propertiesName==null) {
  109.             throw new IOException(SAML_CONFIG_BUILD_PROPERTY_PREFIX+SAMLBuilderConfigConstants.SAML_CONFIG_BUILDER_CONFIG_NAME+"] not found");
  110.         }
  111.        
  112.         RequestInfo requestInfo = null;
  113.         if(!cacheConfig) {
  114.             // altrimenti la configurazione verrà riutilizzata su più richieste
  115.             requestInfo = requestInfoParam;
  116.         }
  117.        
  118.         if(cacheConfig &&
  119.             samlCacheConfig.containsKey(propertiesName)){
  120.             return samlCacheConfig.get(propertiesName);
  121.         }
  122.         try{
  123.             SAMLBuilderConfig config = new SAMLBuilderConfig(p, requestInfo);
  124.             if(cacheConfig) {
  125.                 addSamlConfig(propertiesName,config);
  126.             }
  127.             return config;
  128.         }catch(Exception e){
  129.             throw new IOException("Properties config ["+propertiesName+"]: "+e.getMessage(),e);
  130.         }
  131.     }  
  132.     private static boolean isTrue(Properties p,String name, boolean defaultValue) throws IOException{
  133.         String tmp = p.getProperty(name);
  134.         if(tmp!=null){
  135.             try{
  136.                 return Boolean.parseBoolean(tmp.trim());
  137.             }catch(Exception e){
  138.                 throw new IOException("SAML Config Builder: boolean property ["+name+"] with wrong format: "+e.getMessage());
  139.             }
  140.         }
  141.         return defaultValue;
  142.     }
  143.     private static Integer getIntProperty(Properties p,String name, boolean required) throws IOException{
  144.         String tmp = getProperty(p, name, required);
  145.         if(tmp!=null){
  146.             try{
  147.                 return Integer.parseInt(tmp);
  148.             }catch(Exception e){
  149.                 throw new IOException("SAML Config Builder: integer property ["+name+"] with wrong format: "+e.getMessage());
  150.             }
  151.         }
  152.         return null;
  153.     }
  154.     private static String getProperty(Properties p,String name, boolean required) throws IOException{
  155.         String tmp = p.getProperty(name);
  156.         if(tmp!=null){
  157.             return tmp.trim();
  158.         }
  159.         else{
  160.             if(required){
  161.                 throw new IOException(SAML_CONFIG_BUILD_PROPERTY_PREFIX+name+"] not found");
  162.             }
  163.             else{
  164.                 return null;
  165.             }
  166.         }
  167.     }
  168.    
  169.    
  170.    
  171.     // ---- INSTANCE -----
  172.    
  173.     private RequestInfo requestInfo;
  174.    
  175.     private Properties p;  
  176.    
  177.     // Usage keystore caching
  178.     private boolean useKeystoreCache = false;
  179.    
  180.     // Version
  181.     private Version version = null;

  182.     // Issuer
  183.     private String issuerValue;
  184.     private String issuerQualifier;
  185.     private String issuerFormat;
  186.    
  187.     // Signature
  188.     private boolean signAssertion = false;
  189.     private Crypto signAssertionCrypto = null;
  190.     private String signAssertionCryptoPropFile = null;
  191.     private String signAssertionCryptoPropRefId = null;
  192.     private String signAssertionCryptoPropCustomKeystoreType = null;
  193.     private String signAssertionCryptoPropCustomKeystoreFile = null;
  194.     private String signAssertionCryptoPropCustomKeystoreBYOKPolicy = null;
  195.     private String signAssertionCryptoPropCustomKeystorePassword = null;
  196.     private String signAssertionIssuerKeyPassword = null;
  197.     private String signAssertionIssuerKeyName = null;
  198.     private boolean signAssertionSendKeyValue = false;
  199.     private String signAssertionSignatureAlgorithm;
  200.     private String signAssertionSignatureDigestAlgorithm;
  201.     private String signAssertionCanonicalizationAlgorithm;

  202.     // Subject
  203.     private boolean subjectEnabled = true;
  204.     private String subjectNameIDValue;
  205.     private String subjectNameIDQualifier;
  206.     private String subjectNameIDFormat = NameIDType.UNSPECIFIED;
  207.     private String subjectConfirmationMethod = null;
  208.     private int subjectConfirmationDataNotBefore = 0;
  209.     private int subjectConfirmationDataNotOnOrAfter = 1 * 60; // 1 ora
  210.     private String subjectConfirmationDataAddress;
  211.     private String subjectConfirmationDataInResponseTo;
  212.     private String subjectConfirmationDataRecipient;
  213.     private Crypto subjectConfirmationMethodHolderOfKeyCrypto = null;
  214.     private String subjectConfirmationMethodHolderOfKeyCryptoPropertiesFile = null;
  215.     private String subjectConfirmationMethodHolderOfKeyCryptoPropertiesRefId = null;
  216.     private String subjectConfirmationMethodHolderOfKeyCryptoPropertiesCustomKeystoreType = null;
  217.     private String subjectConfirmationMethodHolderOfKeyCryptoPropertiesCustomKeystoreFile = null;
  218.     private String subjectConfirmationMethodHolderOfKeyCryptoPropertiesCustomKeystoreBYOKPolicy = null;
  219.     private String subjectConfirmationMethodHolderOfKeyCryptoPropertiesCustomKeystorePassword = null;
  220.     private String subjectConfirmationMethodHolderOfKeyCryptoCertificateAlias = null;
  221.    
  222.     // Conditions
  223.     private boolean conditionsEnabled = true;
  224.     private int conditionsDataNotBefore = 0;
  225.     private int conditionsDataNotOnOrAfter = 1 * 60; // 1 ora
  226.     private String conditionsAudienceURI = null;
  227.    
  228.     // Authn
  229.     private boolean authnStatementEnabled = true;
  230.     private int authnStatementDataInstant = 0;
  231.     private Date authnStatementDataInstantDate = null;
  232.     private int authnStatementDataNotOnOrAfter = 1 * 60; // 1 ora
  233.     private Date authnStatementDataNotOnOrAfterDate = null;
  234.     private String authnStatementClassRef;
  235.     private String authnSubjectLocalityIpAddress;
  236.     private String authnSubjectLocalityDnsAddress;
  237.    
  238.     // Attribute
  239.     private List<SAMLBuilderConfigAttribute> attributes = new ArrayList<>();
  240.    
  241.     public SAMLBuilderConfig(Properties p, RequestInfo requestInfo) throws IOException{
  242.         this.p = p;
  243.         this.requestInfo = requestInfo;
  244.        
  245.         // Usage keystore caching
  246.         this.useKeystoreCache = isTrue(this.p, SAMLBuilderConfigConstants.SAML_CONFIG_BUILDER_USE_KEYSTORE_CACHE, false);
  247.        
  248.         // Version
  249.         boolean saml2 = false;
  250.         String versionP = getProperty(this.p, SAMLBuilderConfigConstants.SAML_CONFIG_BUILDER_VERSION, true);
  251.         if(SAMLBuilderConfigConstants.SAML_CONFIG_BUILDER_VERSION_10.equals(versionP)){
  252.             this.version = Version.SAML_10;
  253.         }
  254.         else
  255.         if(SAMLBuilderConfigConstants.SAML_CONFIG_BUILDER_VERSION_11.equals(versionP)){
  256.             this.version = Version.SAML_11;
  257.         }
  258.         else if(SAMLBuilderConfigConstants.SAML_CONFIG_BUILDER_VERSION_20.equals(versionP)){
  259.             this.version = Version.SAML_20;
  260.             saml2 = true;
  261.         }
  262.         else{
  263.             throw new IOException(SAML_CONFIG_BUILD_PROPERTY_PREFIX+SAMLBuilderConfigConstants.SAML_CONFIG_BUILDER_VERSION+"] not supported");
  264.         }
  265.        
  266.         // Issuer
  267.         this.issuerValue = getProperty(this.p, SAMLBuilderConfigConstants.SAML_CONFIG_BUILDER_ISSUER_VALUE, true);
  268.         this.issuerQualifier = getProperty(this.p, SAMLBuilderConfigConstants.SAML_CONFIG_BUILDER_ISSUER_QUALIFIER, false);
  269.        
  270.         String tmp = getProperty(this.p, SAMLBuilderConfigConstants.SAML_CONFIG_BUILDER_ISSUER_FORMAT, false);
  271.         if(tmp!=null){
  272.             this.issuerFormat = getNameIDFormat(tmp);
  273.         }
  274.        

  275.         // Signature    
  276.         this.signAssertion = isTrue(this.p, SAMLBuilderConfigConstants.SAML_CONFIG_BUILDER_SIGN_ASSERTION, false);
  277.         if(this.signAssertion){
  278.             this.signAssertionCryptoPropFile = getProperty(this.p, SAMLBuilderConfigConstants.SAML_CONFIG_BUILDER_SIGN_ASSERTION_CRYPTO_PROP_FILE, false);
  279.             this.signAssertionCryptoPropRefId = getProperty(this.p, SAMLBuilderConfigConstants.SAML_CONFIG_BUILDER_SIGN_ASSERTION_CRYPTO_PROP_REF_ID, false);
  280.             this.signAssertionCryptoPropCustomKeystoreType = getProperty(this.p, SAMLBuilderConfigConstants.SAML_CONFIG_BUILDER_SIGN_ASSERTION_CRYPTO_PROP_KEYSTORE_TYPE, false);
  281.             this.signAssertionCryptoPropCustomKeystoreFile =  getProperty(this.p, SAMLBuilderConfigConstants.SAML_CONFIG_BUILDER_SIGN_ASSERTION_CRYPTO_PROP_KEYSTORE_FILE, false);
  282.             this.signAssertionCryptoPropCustomKeystoreBYOKPolicy =  getProperty(this.p, SAMLBuilderConfigConstants.SAML_CONFIG_BUILDER_SIGN_ASSERTION_CRYPTO_PROP_KEYSTORE_BYOK_POLICY, false);
  283.             this.signAssertionCryptoPropCustomKeystorePassword =  getProperty(this.p, SAMLBuilderConfigConstants.SAML_CONFIG_BUILDER_SIGN_ASSERTION_CRYPTO_PROP_KEYSTORE_PASSWORD, false);
  284.             if(this.signAssertionCryptoPropFile==null && this.signAssertionCryptoPropRefId==null && this.signAssertionCryptoPropCustomKeystoreFile==null) {
  285.                 throw new IOException(SAML_CONFIG_BUILD_REQUIRED_PROPERTY_PREFIX+SAMLBuilderConfigConstants.SAML_CONFIG_BUILDER_SIGN_ASSERTION_CRYPTO_PROP_FILE+SAML_CONFIG_BUILD_PROPERTY_OR+
  286.                                         SAMLBuilderConfigConstants.SAML_CONFIG_BUILDER_SIGN_ASSERTION_CRYPTO_PROP_REF_ID+SAML_CONFIG_BUILD_PROPERTY_OR+
  287.                                         SAMLBuilderConfigConstants.SAML_CONFIG_BUILDER_SIGN_ASSERTION_CRYPTO_PROP_KEYSTORE_FILE+"]");
  288.             }
  289.             if(this.signAssertionCryptoPropCustomKeystoreFile!=null && this.signAssertionCryptoPropCustomKeystorePassword==null) {
  290.                 boolean required = true;
  291.                 if(KeystoreType.JKS.isType(this.signAssertionCryptoPropCustomKeystoreType)) {
  292.                     required = DBUtils.isKeystoreJksPasswordRequired();
  293.                 }
  294.                 else if(KeystoreType.PKCS12.isType(this.signAssertionCryptoPropCustomKeystoreType)) {
  295.                     required = DBUtils.isKeystorePkcs12PasswordRequired();
  296.                 }
  297.                 if(required) {
  298.                     throw new IOException(SAML_CONFIG_BUILD_REQUIRED_PROPERTY_PREFIX+SAMLBuilderConfigConstants.SAML_CONFIG_BUILDER_SIGN_ASSERTION_CRYPTO_PROP_KEYSTORE_PASSWORD+SAML_CONFIG_BUILD_PROPERTY_IF_USE+
  299.                             SAMLBuilderConfigConstants.SAML_CONFIG_BUILDER_SIGN_ASSERTION_CRYPTO_PROP_KEYSTORE_FILE+"]");
  300.                 }
  301.             }
  302.             this.signAssertionIssuerKeyName = getProperty(this.p, SAMLBuilderConfigConstants.SAML_CONFIG_BUILDER_SIGN_ASSERTION_KEY_NAME, true);
  303.             boolean requiredKey = true;
  304.             if(KeystoreType.JKS.isType(this.signAssertionCryptoPropCustomKeystoreType)) {
  305.                 requiredKey = DBUtils.isKeystoreJksKeyPasswordRequired();
  306.             }
  307.             else if(KeystoreType.PKCS12.isType(this.signAssertionCryptoPropCustomKeystoreType)) {
  308.                 requiredKey = DBUtils.isKeystorePkcs12KeyPasswordRequired();
  309.             }
  310.             this.signAssertionIssuerKeyPassword = getProperty(this.p, SAMLBuilderConfigConstants.SAML_CONFIG_BUILDER_SIGN_ASSERTION_KEY_PASSWORD, requiredKey);
  311.             this.signAssertionSendKeyValue = isTrue(this.p, SAMLBuilderConfigConstants.SAML_CONFIG_BUILDER_SIGN_ASSERTION_SEND_KEY_VALUE, false);
  312.             this.signAssertionSignatureAlgorithm = getProperty(this.p, SAMLBuilderConfigConstants.SAML_CONFIG_BUILDER_SIGN_ASSERTION_SIGNATURE_ALGORITHM, false);
  313.             this.signAssertionSignatureDigestAlgorithm = getProperty(this.p, SAMLBuilderConfigConstants.SAML_CONFIG_BUILDER_SIGN_ASSERTION_SIGNATURE_DIGEST_ALGORITHM, false);
  314.             this.signAssertionCanonicalizationAlgorithm = getProperty(this.p, SAMLBuilderConfigConstants.SAML_CONFIG_BUILDER_SIGN_ASSERTION_SIGNATURE_CANONICALIZATION_ALGORITHM, false);
  315.         }
  316.        
  317.         // Subject
  318.         //this.subjectEnabled = isTrue(this.p, SAMLBuilderConfigConstants.SAML_CONFIG_BUILDER_SUBJECT_ENABLED, true); E' OBBLIGATORIO IL SUBJECT, SENNO VA IN NULL POINTER OPENSAML
  319.         this.subjectNameIDValue = getProperty(this.p, SAMLBuilderConfigConstants.SAML_CONFIG_BUILDER_SUBJECT_NAMEID_VALUE, true);
  320.         this.subjectNameIDQualifier = getProperty(this.p, SAMLBuilderConfigConstants.SAML_CONFIG_BUILDER_SUBJECT_NAMEID_QUALIFIER, false);
  321.        
  322.         tmp = getProperty(this.p, SAMLBuilderConfigConstants.SAML_CONFIG_BUILDER_SUBJECT_NAMEID_FORMAT, false);
  323.         if(tmp!=null){
  324.             this.subjectNameIDFormat = getNameIDFormat(tmp);
  325.         }
  326.        
  327.         tmp = getProperty(this.p, SAMLBuilderConfigConstants.SAML_CONFIG_BUILDER_SUBJECT_CONFIRMATION_METHOD, true);
  328.         this.subjectConfirmationMethod = getSubjectConfirmationMethod(tmp, saml2);
  329.         boolean holderOfKey = this.isHolderOfKeySubjectConfirmationMethod(this.subjectConfirmationMethod);
  330.        
  331.         Integer tmpInt = getIntProperty(this.p, SAMLBuilderConfigConstants.SAML_CONFIG_BUILDER_SUBJECT_CONFIRMATION_DATA_NOT_BEFORE, false);
  332.         if(tmpInt!=null){
  333.             this.subjectConfirmationDataNotBefore = tmpInt;
  334.         }
  335.         tmpInt = getIntProperty(this.p, SAMLBuilderConfigConstants.SAML_CONFIG_BUILDER_SUBJECT_CONFIRMATION_DATA_NOT_ON_OR_AFTER, false);
  336.         if(tmpInt!=null){
  337.             this.subjectConfirmationDataNotOnOrAfter = tmpInt;
  338.         }
  339.        
  340.         this.subjectConfirmationDataAddress = getProperty(this.p, SAMLBuilderConfigConstants.SAML_CONFIG_BUILDER_SUBJECT_CONFIRMATION_DATA_ADDRESS, false);
  341.         this.subjectConfirmationDataInResponseTo = getProperty(this.p, SAMLBuilderConfigConstants.SAML_CONFIG_BUILDER_SUBJECT_CONFIRMATION_DATA_IN_RESPONSE_TO, false);
  342.         this.subjectConfirmationDataRecipient = getProperty(this.p, SAMLBuilderConfigConstants.SAML_CONFIG_BUILDER_SUBJECT_CONFIRMATION_DATA_RECIPIENT, false);
  343.        
  344.         if(holderOfKey){
  345.             this.subjectConfirmationMethodHolderOfKeyCryptoPropertiesFile = getProperty(this.p, SAMLBuilderConfigConstants.SAML_CONFIG_BUILDER_SUBJECT_CONFIRMATION_METHOD_HOLDER_OF_KEY_CRYPTO_PROPERTIES_FILE, false);
  346.             this.subjectConfirmationMethodHolderOfKeyCryptoPropertiesRefId = getProperty(this.p, SAMLBuilderConfigConstants.SAML_CONFIG_BUILDER_SUBJECT_CONFIRMATION_METHOD_HOLDER_OF_KEY_CRYPTO_PROPERTIES_REF_ID, false);
  347.             this.subjectConfirmationMethodHolderOfKeyCryptoPropertiesCustomKeystoreType = getProperty(this.p, SAMLBuilderConfigConstants.SAML_CONFIG_BUILDER_SUBJECT_CONFIRMATION_METHOD_HOLDER_OF_KEY_CRYPTO_PROPERTIES_KEYSTORE_TYPE, false);
  348.             this.subjectConfirmationMethodHolderOfKeyCryptoPropertiesCustomKeystoreFile =  getProperty(this.p, SAMLBuilderConfigConstants.SAML_CONFIG_BUILDER_SUBJECT_CONFIRMATION_METHOD_HOLDER_OF_KEY_CRYPTO_PROPERTIES_KEYSTORE_FILE, false);
  349.             this.subjectConfirmationMethodHolderOfKeyCryptoPropertiesCustomKeystoreBYOKPolicy = getProperty(this.p, SAMLBuilderConfigConstants.SAML_CONFIG_BUILDER_SUBJECT_CONFIRMATION_METHOD_HOLDER_OF_KEY_CRYPTO_PROPERTIES_KEYSTORE_BYOK_POLICY, false);
  350.             this.subjectConfirmationMethodHolderOfKeyCryptoPropertiesCustomKeystorePassword =  getProperty(this.p, SAMLBuilderConfigConstants.SAML_CONFIG_BUILDER_SUBJECT_CONFIRMATION_METHOD_HOLDER_OF_KEY_CRYPTO_PROPERTIES_KEYSTORE_PASSWORD, false);
  351.             if(this.subjectConfirmationMethodHolderOfKeyCryptoPropertiesFile==null && this.subjectConfirmationMethodHolderOfKeyCryptoPropertiesRefId==null && this.subjectConfirmationMethodHolderOfKeyCryptoPropertiesCustomKeystoreFile==null) {
  352.                 throw new IOException(SAML_CONFIG_BUILD_REQUIRED_PROPERTY_PREFIX+SAMLBuilderConfigConstants.SAML_CONFIG_BUILDER_SUBJECT_CONFIRMATION_METHOD_HOLDER_OF_KEY_CRYPTO_PROPERTIES_FILE+SAML_CONFIG_BUILD_PROPERTY_OR+
  353.                                         SAMLBuilderConfigConstants.SAML_CONFIG_BUILDER_SUBJECT_CONFIRMATION_METHOD_HOLDER_OF_KEY_CRYPTO_PROPERTIES_REF_ID+SAML_CONFIG_BUILD_PROPERTY_OR+
  354.                                         SAMLBuilderConfigConstants.SAML_CONFIG_BUILDER_SUBJECT_CONFIRMATION_METHOD_HOLDER_OF_KEY_CRYPTO_PROPERTIES_KEYSTORE_FILE+"]");
  355.             }
  356.             if(this.subjectConfirmationMethodHolderOfKeyCryptoPropertiesCustomKeystoreFile!=null && this.subjectConfirmationMethodHolderOfKeyCryptoPropertiesCustomKeystorePassword==null) {
  357.                 boolean required = true;
  358.                 if(KeystoreType.JKS.isType(this.subjectConfirmationMethodHolderOfKeyCryptoPropertiesCustomKeystoreType)) {
  359.                     required = DBUtils.isKeystoreJksKeyPasswordRequired();
  360.                 }
  361.                 else if(KeystoreType.PKCS12.isType(this.subjectConfirmationMethodHolderOfKeyCryptoPropertiesCustomKeystoreType)) {
  362.                     required = DBUtils.isKeystorePkcs12KeyPasswordRequired();
  363.                 }
  364.                 if(required) {
  365.                     throw new IOException(SAML_CONFIG_BUILD_REQUIRED_PROPERTY_PREFIX+SAMLBuilderConfigConstants.SAML_CONFIG_BUILDER_SUBJECT_CONFIRMATION_METHOD_HOLDER_OF_KEY_CRYPTO_PROPERTIES_KEYSTORE_PASSWORD+SAML_CONFIG_BUILD_PROPERTY_IF_USE+
  366.                             SAMLBuilderConfigConstants.SAML_CONFIG_BUILDER_SUBJECT_CONFIRMATION_METHOD_HOLDER_OF_KEY_CRYPTO_PROPERTIES_KEYSTORE_FILE+"]");
  367.                 }
  368.             }
  369.             this.subjectConfirmationMethodHolderOfKeyCryptoCertificateAlias = getProperty(this.p, SAMLBuilderConfigConstants.SAML_CONFIG_BUILDER_SUBJECT_CONFIRMATION_METHOD_HOLDER_OF_KEY_CRYPTO_ALIAS, true);
  370.         }
  371.        
  372.        
  373.         // Conditions
  374.        
  375.         //this.conditionsEnabled = isTrue(this.p, SAMLBuilderConfigConstants.SAML_CONFIG_BUILDER_CONDITIONS_ENABLED, true); //VENGONO GENERATE COMUNQUE
  376.         tmpInt = getIntProperty(this.p, SAMLBuilderConfigConstants.SAML_CONFIG_BUILDER_CONDITIONS_DATA_NOT_BEFORE, false);
  377.         if(tmpInt!=null){
  378.             this.conditionsDataNotBefore = tmpInt;
  379.         }
  380.         tmpInt = getIntProperty(this.p, SAMLBuilderConfigConstants.SAML_CONFIG_BUILDER_CONDITIONS_DATA_NOT_ON_OR_AFTER, false);
  381.         if(tmpInt!=null){
  382.             this.conditionsDataNotOnOrAfter = tmpInt;
  383.         }
  384.         this.conditionsAudienceURI = getProperty(this.p, SAMLBuilderConfigConstants.SAML_CONFIG_BUILDER_CONDITIONS_AUDIENCE_URI, false);
  385.        
  386.        
  387.         // Authn
  388.        
  389.         this.authnStatementEnabled = isTrue(this.p, SAMLBuilderConfigConstants.SAML_CONFIG_BUILDER_AUTHN_STATEMENT_ENABLED, true);
  390.        
  391.         tmpInt = getIntProperty(this.p, SAMLBuilderConfigConstants.SAML_CONFIG_BUILDER_AUTHN_STATEMENT_DATA_INSTANT, false);
  392.         if(tmpInt!=null){
  393.             this.authnStatementDataInstant = tmpInt; // se si vuole andare indietro deve essere fornito un valore negativo nella proprietà
  394.         }
  395.         tmp = getProperty(this.p, SAMLBuilderConfigConstants.SAML_CONFIG_BUILDER_AUTHN_STATEMENT_DATA_INSTANT_VALUE, false);
  396.         if(tmp!=null) {
  397.             String value = tmp;
  398.             tmp = getProperty(this.p, SAMLBuilderConfigConstants.SAML_CONFIG_BUILDER_AUTHN_STATEMENT_DATA_INSTANT_FORMAT, false);
  399.             if(tmp!=null) {
  400.                 String format = tmp;
  401.                 SimpleDateFormat sdf = new SimpleDateFormat(format);
  402.                 try {
  403.                     this.authnStatementDataInstantDate = sdf.parse(value);
  404.                 }catch(Exception e) {
  405.                     throw new IOException("SAML Config Builder: failed parsing property value ["+SAMLBuilderConfigConstants.SAML_CONFIG_BUILDER_AUTHN_STATEMENT_DATA_INSTANT_VALUE+"="+value+"] with format ["+
  406.                             SAMLBuilderConfigConstants.SAML_CONFIG_BUILDER_AUTHN_STATEMENT_DATA_INSTANT_FORMAT+"="+format+"]: "+e.getMessage(),e);
  407.                 }
  408.             }
  409.             else {
  410.                 throw new IOException(SAML_CONFIG_BUILD_REQUIRED_PROPERTY_PREFIX+SAMLBuilderConfigConstants.SAML_CONFIG_BUILDER_AUTHN_STATEMENT_DATA_INSTANT_FORMAT+SAML_CONFIG_BUILD_PROPERTY_IF_USE+
  411.                         SAMLBuilderConfigConstants.SAML_CONFIG_BUILDER_AUTHN_STATEMENT_DATA_INSTANT_VALUE+"]");
  412.             }
  413.         }

  414.         tmpInt = getIntProperty(this.p, SAMLBuilderConfigConstants.SAML_CONFIG_BUILDER_AUTHN_STATEMENT_DATA_NOT_ON_OR_AFTER, false);
  415.         if(tmpInt!=null){
  416.             this.authnStatementDataNotOnOrAfter = tmpInt;
  417.         }
  418.         tmp = getProperty(this.p, SAMLBuilderConfigConstants.SAML_CONFIG_BUILDER_AUTHN_STATEMENT_DATA_NOT_ON_OR_AFTER_VALUE, false);
  419.         if(tmp!=null) {
  420.             String value = tmp;
  421.             tmp = getProperty(this.p, SAMLBuilderConfigConstants.SAML_CONFIG_BUILDER_AUTHN_STATEMENT_DATA_NOT_ON_OR_AFTER_FORMAT, false);
  422.             if(tmp!=null) {
  423.                 String format = tmp;
  424.                 SimpleDateFormat sdf = new SimpleDateFormat(format);
  425.                 try {
  426.                     this.authnStatementDataNotOnOrAfterDate = sdf.parse(value);
  427.                 }catch(Exception e) {
  428.                     throw new IOException("SAML Config Builder: failed parsing property value ["+SAMLBuilderConfigConstants.SAML_CONFIG_BUILDER_AUTHN_STATEMENT_DATA_NOT_ON_OR_AFTER_VALUE+"="+value+"] with format ["+
  429.                             SAMLBuilderConfigConstants.SAML_CONFIG_BUILDER_AUTHN_STATEMENT_DATA_NOT_ON_OR_AFTER_FORMAT+"="+format+"]: "+e.getMessage(),e);
  430.                 }
  431.             }
  432.             else {
  433.                 throw new IOException(SAML_CONFIG_BUILD_REQUIRED_PROPERTY_PREFIX+SAMLBuilderConfigConstants.SAML_CONFIG_BUILDER_AUTHN_STATEMENT_DATA_NOT_ON_OR_AFTER_FORMAT+SAML_CONFIG_BUILD_PROPERTY_IF_USE+
  434.                         SAMLBuilderConfigConstants.SAML_CONFIG_BUILDER_AUTHN_STATEMENT_DATA_NOT_ON_OR_AFTER_VALUE+"]");
  435.             }
  436.         }

  437.         tmp = getProperty(this.p, SAMLBuilderConfigConstants.SAML_CONFIG_BUILDER_AUTHN, this.authnStatementEnabled);
  438.         if(tmp!=null){
  439.             this.authnStatementClassRef = getAuthStatementMethod(tmp, saml2);
  440.         }
  441.         this.authnSubjectLocalityIpAddress = getProperty(this.p, SAMLBuilderConfigConstants.SAML_CONFIG_BUILDER_AUTHN_SUBJECT_LOCALITY_IP_ADDRESS, false);
  442.         this.authnSubjectLocalityDnsAddress = getProperty(this.p, SAMLBuilderConfigConstants.SAML_CONFIG_BUILDER_AUTHN_SUBJECT_LOCALITY_DNS_ADDRESS, false);

  443.        
  444.         // Attribute
  445.        
  446.         Properties pAttribute = null;
  447.         try{
  448.             pAttribute = Utilities.readProperties(SAMLBuilderConfigConstants.SAML_CONFIG_BUILDER_ATTRIBUTE_PREFIX, this.p);
  449.         }catch(Exception e){
  450.             throw new IOException(e.getMessage(),e);
  451.         }
  452.         if(pAttribute!=null && p.size()>0){
  453.             List<String> attrNames = new ArrayList<>();
  454.             Enumeration<?> enAttributes = pAttribute.keys();
  455.             if(enAttributes!=null){
  456.                 while (enAttributes.hasMoreElements()) {
  457.                     Object objectName = enAttributes.nextElement();
  458.                     if(objectName instanceof String){
  459.                         String key = (String) objectName;
  460.                         if(key.endsWith(SAMLBuilderConfigConstants.SAML_CONFIG_BUILDER_ATTRIBUTE_SUFFIX_VALUE)){
  461.                             String attrName = key.substring(0, key.indexOf(SAMLBuilderConfigConstants.SAML_CONFIG_BUILDER_ATTRIBUTE_SUFFIX_VALUE));
  462.                             attrNames.add(attrName);
  463.                         }
  464.                     }
  465.                 }
  466.             }
  467.             Collections.sort(attrNames);
  468.             for (String attrName : attrNames) {
  469.                 SAMLBuilderConfigAttribute attr = new SAMLBuilderConfigAttribute(attrName);
  470.                
  471.                 String qualifiedName = attrName + SAMLBuilderConfigConstants.SAML_CONFIG_BUILDER_ATTRIBUTE_SUFFIX_QUALIFIED_NAME;
  472.                 String simpleName = attrName + SAMLBuilderConfigConstants.SAML_CONFIG_BUILDER_ATTRIBUTE_SUFFIX_SIMPLE_NAME;
  473.                 String qualifiedNameTmp = getProperty(pAttribute, qualifiedName, !saml2); // sono obbligatori entrambi solamente per saml 1.1
  474.                 String simpleNameTmp = getProperty(pAttribute, simpleName, !saml2); // sono obbligatori entrambi solamente per saml 1.1
  475.                 if(qualifiedNameTmp==null && simpleNameTmp==null){
  476.                     throw new IOException("SAML Config Builder: attribute ["+attrName+"] requires at least one of the following properties: "+
  477.                             qualifiedName+", "+simpleName);
  478.                 }
  479.                 attr.setQualifiedName(qualifiedNameTmp);
  480.                 attr.setSimpleName(simpleNameTmp);
  481.                
  482.                 String format = attrName + SAMLBuilderConfigConstants.SAML_CONFIG_BUILDER_ATTRIBUTE_SUFFIX_FORMAT_NAME;
  483.                 if(saml2){
  484.                     String formatTmp = getProperty(pAttribute, format, true);
  485.                     attr.setFormatName(this.getAttributeFormat(formatTmp));
  486.                 }
  487.                 else{
  488.                     String formatTmp = getProperty(pAttribute, format, false);
  489.                     if(formatTmp!=null){
  490.                         throw new IOException("SAML Config Builder: name format unsupported in SAML 1.1; found in attribute ["+attrName+"]");
  491.                     }
  492.                 }
  493.                
  494.                 String separator = attrName + SAMLBuilderConfigConstants.SAML_CONFIG_BUILDER_ATTRIBUTE_SUFFIX_VALUE_SEPARATOR;
  495.                 String separatorTmp = getProperty(pAttribute, separator, false);
  496.                 if(separatorTmp==null || "".equals(separatorTmp)){
  497.                     separatorTmp = ","; // default
  498.                 }
  499.                
  500.                 String values = attrName + SAMLBuilderConfigConstants.SAML_CONFIG_BUILDER_ATTRIBUTE_SUFFIX_VALUE;
  501.                 String valuesTmp = getProperty(pAttribute, values, true);
  502.                 String [] splitValues = valuesTmp.split(separatorTmp);
  503.                 if(splitValues==null || splitValues.length<=0){
  504.                     throw new IOException("SAML Config Builder: values not found in attribute ["+attrName+"] using separator ["+valuesTmp+"]");
  505.                 }
  506.                 for (int i = 0; i < splitValues.length; i++) {
  507.                     attr.addValue(splitValues[i].trim());
  508.                 }
  509.                
  510.                 this.attributes.add(attr);
  511.             }
  512.         }
  513.     }
  514.    
  515.    
  516.     private String getNameIDFormat(String tmpParam){
  517.         String tmp = tmpParam.trim();
  518.         if(SAMLBuilderConfigConstants.SAML_CONFIG_BUILDER_SUBJECT_NAMEID_FORMAT_VALUE_UNSPECIFIED.equals(tmp)){
  519.             tmp = NameIDType.UNSPECIFIED;
  520.         }
  521.         else if(SAMLBuilderConfigConstants.SAML_CONFIG_BUILDER_SUBJECT_NAMEID_FORMAT_VALUE_EMAIL.equals(tmp)){
  522.             tmp = NameIDType.EMAIL;
  523.         }
  524.         else if(SAMLBuilderConfigConstants.SAML_CONFIG_BUILDER_SUBJECT_NAMEID_FORMAT_VALUE_X509_SUBJECT.equals(tmp)){
  525.             tmp = NameIDType.X509_SUBJECT;
  526.         }
  527.         else if(SAMLBuilderConfigConstants.SAML_CONFIG_BUILDER_SUBJECT_NAMEID_FORMAT_VALUE_WIN_DOMAIN_QUALIFIED.equals(tmp)){
  528.             tmp = NameIDType.WIN_DOMAIN_QUALIFIED;
  529.         }
  530.         else if(SAMLBuilderConfigConstants.SAML_CONFIG_BUILDER_SUBJECT_NAMEID_FORMAT_VALUE_KERBEROS.equals(tmp)){
  531.             tmp = NameIDType.KERBEROS;
  532.         }
  533.         else if(SAMLBuilderConfigConstants.SAML_CONFIG_BUILDER_SUBJECT_NAMEID_FORMAT_VALUE_ENTITY.equals(tmp)){
  534.             tmp = NameIDType.ENTITY;
  535.         }
  536.         else if(SAMLBuilderConfigConstants.SAML_CONFIG_BUILDER_SUBJECT_NAMEID_FORMAT_VALUE_PERSISTENT.equals(tmp)){
  537.             tmp = NameIDType.PERSISTENT;
  538.         }
  539.         else if(SAMLBuilderConfigConstants.SAML_CONFIG_BUILDER_SUBJECT_NAMEID_FORMAT_VALUE_TRANSIENT.equals(tmp)){
  540.             tmp = NameIDType.TRANSIENT;
  541.         }
  542.         else if(SAMLBuilderConfigConstants.SAML_CONFIG_BUILDER_SUBJECT_NAMEID_FORMAT_VALUE_ENCRYPTED.equals(tmp)){
  543.             tmp = NameIDType.ENCRYPTED;
  544.         }
  545.         else{
  546.             // lascio il valore impostato dall'utente nel file di proprietà. Deve inserire un formato valido
  547.             // Cosi' supporto anche eventuali formati futuri.
  548.         }
  549.         return tmp;
  550.     }
  551.    
  552.     private String getSubjectConfirmationMethod(String tmpParam, boolean saml2){
  553.         String tmp = tmpParam.trim();
  554.         if(SAMLBuilderConfigConstants.SAML_CONFIG_BUILDER_SUBJECT_CONFIRMATION_METHOD_VALUE_ARTIFACT.equals(tmp) && !saml2){
  555.             tmp = SAMLBuilderConfigConstants.SAML_CONFIG_BUILDER_SUBJECT_CONFIRMATION_METHOD_ARTIFACT_SAML_10;
  556.         }
  557.         else if(SAMLBuilderConfigConstants.SAML_CONFIG_BUILDER_SUBJECT_CONFIRMATION_METHOD_VALUE_IDENTITY.equals(tmp) && !saml2){
  558.             tmp = SAMLBuilderConfigConstants.SAML_CONFIG_BUILDER_SUBJECT_CONFIRMATION_METHOD_IDENTITY_SAML_10;
  559.         }
  560.         else if(SAMLBuilderConfigConstants.SAML_CONFIG_BUILDER_SUBJECT_CONFIRMATION_METHOD_VALUE_BEARER.equals(tmp)){
  561.             if(saml2){
  562.                 tmp = SAMLBuilderConfigConstants.SAML_CONFIG_BUILDER_SUBJECT_CONFIRMATION_METHOD_BEARER_SAML_20;
  563.             }else{
  564.                 tmp = SAMLBuilderConfigConstants.SAML_CONFIG_BUILDER_SUBJECT_CONFIRMATION_METHOD_BEARER_SAML_10;
  565.             }
  566.         }
  567.         else if(SAMLBuilderConfigConstants.SAML_CONFIG_BUILDER_SUBJECT_CONFIRMATION_METHOD_VALUE_HOLDER_OF_KEY.equals(tmp)){
  568.             if(saml2){
  569.                 tmp = SAMLBuilderConfigConstants.SAML_CONFIG_BUILDER_SUBJECT_CONFIRMATION_METHOD_HOLDER_OF_KEY_SAML_20;
  570.             }else{
  571.                 tmp = SAMLBuilderConfigConstants.SAML_CONFIG_BUILDER_SUBJECT_CONFIRMATION_METHOD_HOLDER_OF_KEY_SAML_10;
  572.             }
  573.         }
  574.         else if(SAMLBuilderConfigConstants.SAML_CONFIG_BUILDER_SUBJECT_CONFIRMATION_METHOD_VALUE_SENDER_VOUCHES.equals(tmp)){
  575.             if(saml2){
  576.                 tmp = SAMLBuilderConfigConstants.SAML_CONFIG_BUILDER_SUBJECT_CONFIRMATION_METHOD_SENDER_VOUCHES_SAML_20;
  577.             }else{
  578.                 tmp = SAMLBuilderConfigConstants.SAML_CONFIG_BUILDER_SUBJECT_CONFIRMATION_METHOD_SENDER_VOUCHES_SAML_10;
  579.             }
  580.         }
  581.         else{
  582.             // lascio il valore impostato dall'utente nel file di proprietà. Deve inserire un formato valido
  583.             // Cosi' supporto anche eventuali formati futuri.
  584.         }
  585.         return tmp;
  586.     }
  587.    
  588.     private boolean isHolderOfKeySubjectConfirmationMethod(String confirmationMethod){
  589.        
  590.         return SAMLBuilderConfigConstants.SAML_CONFIG_BUILDER_SUBJECT_CONFIRMATION_METHOD_HOLDER_OF_KEY_SAML_20.equals(confirmationMethod)
  591.                 ||
  592.                 SAMLBuilderConfigConstants.SAML_CONFIG_BUILDER_SUBJECT_CONFIRMATION_METHOD_HOLDER_OF_KEY_SAML_10.equals(confirmationMethod);
  593.        
  594.     }
  595.    
  596.     private String getAuthStatementMethod(String tmpParam, boolean saml2){
  597.         String tmp = tmpParam.trim();
  598.         if(SAMLBuilderConfigConstants.SAML_CONFIG_BUILDER_AUTHN_VALUE_UNSPECIFIED.equals(tmp)){
  599.             if(saml2){
  600.                 tmp = SAMLBuilderConfigConstants.SAML_CONFIG_BUILDER_AUTHN_UNSPECIFIED_SAML20;
  601.             }else{
  602.                 tmp = SAMLBuilderConfigConstants.SAML_CONFIG_BUILDER_AUTHN_UNSPECIFIED_SAML10;
  603.             }
  604.         }
  605.         else if(SAMLBuilderConfigConstants.SAML_CONFIG_BUILDER_AUTHN_VALUE_PASSWORD.equals(tmp)){
  606.             if(saml2){
  607.                 tmp = SAMLBuilderConfigConstants.SAML_CONFIG_BUILDER_AUTHN_PASSWORD_SAML20;
  608.             }else{
  609.                 tmp = SAMLBuilderConfigConstants.SAML_CONFIG_BUILDER_AUTHN_PASSWORD_SAML10;
  610.             }
  611.         }
  612.         else if(SAMLBuilderConfigConstants.SAML_CONFIG_BUILDER_AUTHN_VALUE_KERBEROS.equals(tmp)){
  613.             if(saml2){
  614.                 tmp = SAMLBuilderConfigConstants.SAML_CONFIG_BUILDER_AUTHN_KERBEROS_SAML20;
  615.             }else{
  616.                 tmp = SAMLBuilderConfigConstants.SAML_CONFIG_BUILDER_AUTHN_KERBEROS_SAML10;
  617.             }
  618.         }
  619.         else if(SAMLBuilderConfigConstants.SAML_CONFIG_BUILDER_AUTHN_VALUE_TLS.equals(tmp)){
  620.             if(saml2){
  621.                 tmp = SAMLBuilderConfigConstants.SAML_CONFIG_BUILDER_AUTHN_TLS_SAML20;
  622.             }else{
  623.                 tmp = SAMLBuilderConfigConstants.SAML_CONFIG_BUILDER_AUTHN_TLS_SAML10;
  624.             }
  625.         }
  626.         else if(SAMLBuilderConfigConstants.SAML_CONFIG_BUILDER_AUTHN_VALUE_X509.equals(tmp)){
  627.             if(saml2){
  628.                 tmp = SAMLBuilderConfigConstants.SAML_CONFIG_BUILDER_AUTHN_X509_SAML20;
  629.             }else{
  630.                 tmp = SAMLBuilderConfigConstants.SAML_CONFIG_BUILDER_AUTHN_X509_SAML10;
  631.             }
  632.         }
  633.         else if(SAMLBuilderConfigConstants.SAML_CONFIG_BUILDER_AUTHN_VALUE_PGP.equals(tmp)){
  634.             if(saml2){
  635.                 tmp = SAMLBuilderConfigConstants.SAML_CONFIG_BUILDER_AUTHN_PGP_SAML20;
  636.             }else{
  637.                 tmp = SAMLBuilderConfigConstants.SAML_CONFIG_BUILDER_AUTHN_PGP_SAML10;
  638.             }
  639.         }
  640.         else if(SAMLBuilderConfigConstants.SAML_CONFIG_BUILDER_AUTHN_VALUE_SRP.equals(tmp)){
  641.             if(saml2){
  642.                 tmp = SAMLBuilderConfigConstants.SAML_CONFIG_BUILDER_AUTHN_SRP_SAML20;
  643.             }else{
  644.                 tmp = SAMLBuilderConfigConstants.SAML_CONFIG_BUILDER_AUTHN_SRP_SAML10;
  645.             }
  646.         }
  647.         else if(SAMLBuilderConfigConstants.SAML_CONFIG_BUILDER_AUTHN_VALUE_SPKI.equals(tmp)){
  648.             if(saml2){
  649.                 tmp = SAMLBuilderConfigConstants.SAML_CONFIG_BUILDER_AUTHN_SPKI_SAML20;
  650.             }else{
  651.                 tmp = SAMLBuilderConfigConstants.SAML_CONFIG_BUILDER_AUTHN_SPKI_SAML10;
  652.             }
  653.         }
  654.         else if(SAMLBuilderConfigConstants.SAML_CONFIG_BUILDER_AUTHN_VALUE_DSIG.equals(tmp)){
  655.             if(saml2){
  656.                 tmp = SAMLBuilderConfigConstants.SAML_CONFIG_BUILDER_AUTHN_DSIG_SAML20;
  657.             }else{
  658.                 tmp = SAMLBuilderConfigConstants.SAML_CONFIG_BUILDER_AUTHN_DSIG_SAML10;
  659.             }
  660.         }
  661.         else if(SAMLBuilderConfigConstants.SAML_CONFIG_BUILDER_AUTHN_VALUE_HARDWARE.equals(tmp)){
  662.             if(!saml2){
  663.                 tmp = SAMLBuilderConfigConstants.SAML_CONFIG_BUILDER_AUTHN_HARDWARE_SAML10;
  664.             }
  665.         }
  666.         else if(SAMLBuilderConfigConstants.SAML_CONFIG_BUILDER_AUTHN_VALUE_XKMS.equals(tmp)){
  667.             if(!saml2){
  668.                 tmp = SAMLBuilderConfigConstants.SAML_CONFIG_BUILDER_AUTHN_XKMS_SAML10;
  669.             }
  670.         }
  671.         else if(SAMLBuilderConfigConstants.SAML_CONFIG_BUILDER_AUTHN_VALUE_INTERNET_PROTOCOL.equals(tmp)){
  672.             if(saml2){
  673.                 tmp = SAMLBuilderConfigConstants.SAML_CONFIG_BUILDER_AUTHN_INTERNET_PROTOCOL_SAML20;
  674.             }
  675.         }
  676.         else if(SAMLBuilderConfigConstants.SAML_CONFIG_BUILDER_AUTHN_VALUE_INTERNET_PROTOCOL_PASSWORD.equals(tmp)){
  677.             if(saml2){
  678.                 tmp = SAMLBuilderConfigConstants.SAML_CONFIG_BUILDER_AUTHN_INTERNET_PROTOCOL_PASSWORD_SAML20;
  679.             }
  680.         }
  681.         else if(SAMLBuilderConfigConstants.SAML_CONFIG_BUILDER_AUTHN_VALUE_MOBILE_ONE_FACTOR_UNREGISTERED.equals(tmp)){
  682.             if(saml2){
  683.                 tmp = SAMLBuilderConfigConstants.SAML_CONFIG_BUILDER_AUTHN_MOBILE_ONE_FACTOR_UNREGISTERED_SAML20;
  684.             }
  685.         }
  686.         else if(SAMLBuilderConfigConstants.SAML_CONFIG_BUILDER_AUTHN_VALUE_MOBILE_TWO_FACTOR_UNREGISTERED.equals(tmp)){
  687.             if(saml2){
  688.                 tmp = SAMLBuilderConfigConstants.SAML_CONFIG_BUILDER_AUTHN_MOBILE_TWO_FACTOR_UNREGISTERED_SAML20;
  689.             }
  690.         }
  691.         else if(SAMLBuilderConfigConstants.SAML_CONFIG_BUILDER_AUTHN_VALUE_MOBILE_ONE_FACTOR_CONTRACT.equals(tmp)){
  692.             if(saml2){
  693.                 tmp = SAMLBuilderConfigConstants.SAML_CONFIG_BUILDER_AUTHN_MOBILE_ONE_FACTOR_CONTRACT_SAML20;
  694.             }
  695.         }
  696.         else if(SAMLBuilderConfigConstants.SAML_CONFIG_BUILDER_AUTHN_VALUE_MOBILE_TWO_FACTOR_CONTRACT.equals(tmp)){
  697.             if(saml2){
  698.                 tmp = SAMLBuilderConfigConstants.SAML_CONFIG_BUILDER_AUTHN_MOBILE_TWO_FACTOR_CONTRACT_SAML20;
  699.             }
  700.         }
  701.         else if(SAMLBuilderConfigConstants.SAML_CONFIG_BUILDER_AUTHN_VALUE_PASSWORD_PROTECTED_TRANSPORT.equals(tmp)){
  702.             if(saml2){
  703.                 tmp = SAMLBuilderConfigConstants.SAML_CONFIG_BUILDER_AUTHN_PASSWORD_PROTECTED_TRANSPORT_SAML20;
  704.             }
  705.         }
  706.         else if(SAMLBuilderConfigConstants.SAML_CONFIG_BUILDER_AUTHN_VALUE_PREVIOUS_SESSION.equals(tmp)){
  707.             if(saml2){
  708.                 tmp = SAMLBuilderConfigConstants.SAML_CONFIG_BUILDER_AUTHN_PREVIOUS_SESSION_SAML20;
  709.             }
  710.         }
  711.         else if(SAMLBuilderConfigConstants.SAML_CONFIG_BUILDER_AUTHN_VALUE_SMARTCARD.equals(tmp)){
  712.             if(saml2){
  713.                 tmp = SAMLBuilderConfigConstants.SAML_CONFIG_BUILDER_AUTHN_SMARTCARD_SAML20;
  714.             }
  715.         }
  716.         else if(SAMLBuilderConfigConstants.SAML_CONFIG_BUILDER_AUTHN_VALUE_SMARTCARD_PKI.equals(tmp)){
  717.             if(saml2){
  718.                 tmp = SAMLBuilderConfigConstants.SAML_CONFIG_BUILDER_AUTHN_SMARTCARD_PKI_SAML20;
  719.             }
  720.         }
  721.         else if(SAMLBuilderConfigConstants.SAML_CONFIG_BUILDER_AUTHN_VALUE_SOFTWARE_PKI.equals(tmp)){
  722.             if(saml2){
  723.                 tmp = SAMLBuilderConfigConstants.SAML_CONFIG_BUILDER_AUTHN_SOFTWARE_PKI_SAML20;
  724.             }
  725.         }
  726.         else if(SAMLBuilderConfigConstants.SAML_CONFIG_BUILDER_AUTHN_VALUE_TELEPHONY.equals(tmp)){
  727.             if(saml2){
  728.                 tmp = SAMLBuilderConfigConstants.SAML_CONFIG_BUILDER_AUTHN_TELEPHONY_SAML20;
  729.             }
  730.         }
  731.         else if(SAMLBuilderConfigConstants.SAML_CONFIG_BUILDER_AUTHN_VALUE_NOMAD_TELEPHONY.equals(tmp)){
  732.             if(saml2){
  733.                 tmp = SAMLBuilderConfigConstants.SAML_CONFIG_BUILDER_AUTHN_NOMAD_TELEPHONY_SAML20;
  734.             }
  735.         }
  736.         else if(SAMLBuilderConfigConstants.SAML_CONFIG_BUILDER_AUTHN_VALUE_PERSONAL_TELEPHONY.equals(tmp)){
  737.             if(saml2){
  738.                 tmp = SAMLBuilderConfigConstants.SAML_CONFIG_BUILDER_AUTHN_PERSONAL_TELEPHONY_SAML20;
  739.             }
  740.         }
  741.         else if(SAMLBuilderConfigConstants.SAML_CONFIG_BUILDER_AUTHN_VALUE_AUTHENTICATED_TELEPHONY.equals(tmp)){
  742.             if(saml2){
  743.                 tmp = SAMLBuilderConfigConstants.SAML_CONFIG_BUILDER_AUTHN_AUTHENTICATED_TELEPHONY_SAML20;
  744.             }
  745.         }
  746.         else if(SAMLBuilderConfigConstants.SAML_CONFIG_BUILDER_AUTHN_VALUE_TIME_SYNC.equals(tmp)){
  747.             if(saml2){
  748.                 tmp = SAMLBuilderConfigConstants.SAML_CONFIG_BUILDER_AUTHN_TIME_SYNC_SAML20;
  749.             }
  750.         }
  751.         else{
  752.             // lascio il valore impostato dall'utente nel file di proprietà. Deve inserire un formato valido
  753.             // Cosi' supporto anche eventuali formati futuri.
  754.         }
  755.         return tmp;
  756.     }
  757.    
  758.     private String getAttributeFormat(String tmpParam){
  759.         String tmp = tmpParam.trim();
  760.         if(SAMLBuilderConfigConstants.SAML_CONFIG_BUILDER_ATTRIBUTE_SUFFIX_FORMAT_NAME_VALUE_UNSPECIFIED.equals(tmp)){
  761.             tmp = SAMLBuilderConfigConstants.SAML_CONFIG_BUILDER_ATTRIBUTE_SUFFIX_FORMAT_NAME_UNSPECIFIED_SAML20;
  762.         }
  763.         else if(SAMLBuilderConfigConstants.SAML_CONFIG_BUILDER_ATTRIBUTE_SUFFIX_FORMAT_NAME_VALUE_URI.equals(tmp)){
  764.             tmp = SAMLBuilderConfigConstants.SAML_CONFIG_BUILDER_ATTRIBUTE_SUFFIX_FORMAT_NAME_URI_SAML20;
  765.         }
  766.         else if(SAMLBuilderConfigConstants.SAML_CONFIG_BUILDER_ATTRIBUTE_SUFFIX_FORMAT_NAME_VALUE_BASIC.equals(tmp)){
  767.             tmp = SAMLBuilderConfigConstants.SAML_CONFIG_BUILDER_ATTRIBUTE_SUFFIX_FORMAT_NAME_BASIC_SAML20;
  768.         }
  769.         else{
  770.             // lascio il valore impostato dall'utente nel file di proprietà. Deve inserire un formato valido
  771.             // Cosi' supporto anche eventuali formati futuri.
  772.         }
  773.         return tmp;
  774.     }
  775.    

  776.    
  777.     // Usage keystore caching
  778.    
  779.     public boolean isUseKeystoreCache() {
  780.         return this.useKeystoreCache;
  781.     }  
  782.    
  783.     // Version
  784.    
  785.     public Version getVersion() {
  786.         return this.version;
  787.     }
  788.    
  789.     // Issuer

  790.     public String getIssuerValue() {
  791.         return this.issuerValue;
  792.     }
  793.     public String getIssuerQualifier() {
  794.         return this.issuerQualifier;
  795.     }
  796.     public String getIssuerFormat() {
  797.         return this.issuerFormat;
  798.     }

  799.     // Signature

  800.     public boolean isSignAssertion() {
  801.         return this.signAssertion;
  802.     }
  803.     public Crypto getSignAssertionCrypto() throws Exception {
  804.         if(this.signAssertionCrypto==null){
  805.             initSignAssertionCrypto();
  806.         }
  807.         return this.signAssertionCrypto;
  808.     }
  809.     private synchronized void initSignAssertionCrypto() throws Exception{
  810.         if(this.signAssertionCrypto==null){
  811.             if(this.signAssertionCryptoPropFile!=null) {
  812.                 this.signAssertionCrypto =
  813.                     CryptoFactory.getInstance(this.signAssertionCryptoPropFile);
  814.             }
  815.             else if(this.signAssertionCryptoPropCustomKeystoreFile!=null) {
  816.                 Properties pMerlin = SAMLUtilities.convertToMerlinProperties(this.signAssertionCryptoPropCustomKeystoreType,
  817.                         this.signAssertionCryptoPropCustomKeystoreFile, this.signAssertionCryptoPropCustomKeystorePassword,
  818.                         this.useKeystoreCache,
  819.                         this.signAssertionCryptoPropCustomKeystoreBYOKPolicy);
  820.                 if(this.requestInfo!=null) {
  821.                     pMerlin.put(KeystoreConstants.PROPERTY_REQUEST_INFO, this.requestInfo);
  822.                 }
  823.                 this.signAssertionCrypto = CryptoFactory.getInstance(pMerlin);
  824.             }
  825.             else {
  826.                 this.signAssertionCrypto =
  827.                         CryptoFactory.getInstance(this.p);
  828.             }
  829.         }
  830.     }
  831.     public String getSignAssertionIssuerKeyPassword() {
  832.         return this.signAssertionIssuerKeyPassword;
  833.     }
  834.     public String getSignAssertionIssuerKeyName() {
  835.         return this.signAssertionIssuerKeyName;
  836.     }
  837.     public boolean isSignAssertionSendKeyValue() {
  838.         return this.signAssertionSendKeyValue;
  839.     }
  840.     public String getSignAssertionSignatureAlgorithm() {
  841.         return this.signAssertionSignatureAlgorithm;
  842.     }
  843.     public String getSignAssertionSignatureDigestAlgorithm() {
  844.         return this.signAssertionSignatureDigestAlgorithm;
  845.     }
  846.     public String getSignAssertionCanonicalizationAlgorithm() {
  847.         return this.signAssertionCanonicalizationAlgorithm;
  848.     }
  849.    
  850.     // Subject
  851.    
  852.     public boolean isSubjectEnabled() {
  853.         return this.subjectEnabled;
  854.     }
  855.     public String getSubjectNameIDValue() {
  856.         return this.subjectNameIDValue;
  857.     }
  858.     public String getSubjectNameIDQualifier() {
  859.         return this.subjectNameIDQualifier;
  860.     }
  861.     public String getSubjectNameIDFormat() {
  862.         return this.subjectNameIDFormat;
  863.     }
  864.     public String getSubjectConfirmationMethod() {
  865.         return this.subjectConfirmationMethod;
  866.     }
  867.     public int getSubjectConfirmationDataNotBefore() {
  868.         return this.subjectConfirmationDataNotBefore;
  869.     }
  870.     public int getSubjectConfirmationDataNotOnOrAfter() {
  871.         return this.subjectConfirmationDataNotOnOrAfter;
  872.     }
  873.     public String getSubjectConfirmationDataAddress() {
  874.         return this.subjectConfirmationDataAddress;
  875.     }
  876.     public String getSubjectConfirmationDataInResponseTo() {
  877.         return this.subjectConfirmationDataInResponseTo;
  878.     }
  879.     public String getSubjectConfirmationDataRecipient() {
  880.         return this.subjectConfirmationDataRecipient;
  881.     }
  882.     public Crypto getSubjectConfirmationMethodHolderOfKeyCrypto() throws Exception {
  883.         if(this.subjectConfirmationMethodHolderOfKeyCrypto==null){
  884.             initSubjectConfirmationMethodHolderOfKeyCrypto();
  885.         }
  886.         return this.subjectConfirmationMethodHolderOfKeyCrypto;
  887.     }
  888.     private synchronized void initSubjectConfirmationMethodHolderOfKeyCrypto() throws Exception{
  889.         if(this.subjectConfirmationMethodHolderOfKeyCrypto==null){
  890.             if(this.subjectConfirmationMethodHolderOfKeyCryptoPropertiesFile!=null) {
  891.                 this.subjectConfirmationMethodHolderOfKeyCrypto =
  892.                     CryptoFactory.getInstance(this.subjectConfirmationMethodHolderOfKeyCryptoPropertiesFile);  
  893.             }
  894.             else if(this.subjectConfirmationMethodHolderOfKeyCryptoPropertiesCustomKeystoreFile!=null) {
  895.                 Properties pMerlin = SAMLUtilities.convertToMerlinProperties(this.subjectConfirmationMethodHolderOfKeyCryptoPropertiesCustomKeystoreType,
  896.                         this.subjectConfirmationMethodHolderOfKeyCryptoPropertiesCustomKeystoreFile, this.subjectConfirmationMethodHolderOfKeyCryptoPropertiesCustomKeystorePassword,
  897.                         this.useKeystoreCache,
  898.                         this.subjectConfirmationMethodHolderOfKeyCryptoPropertiesCustomKeystoreBYOKPolicy);
  899.                 if(this.requestInfo!=null) {
  900.                     pMerlin.put(KeystoreConstants.PROPERTY_REQUEST_INFO, this.requestInfo);
  901.                 }
  902.                 this.subjectConfirmationMethodHolderOfKeyCrypto = CryptoFactory.getInstance(pMerlin);
  903.             }
  904.             else {
  905.                 this.subjectConfirmationMethodHolderOfKeyCrypto =
  906.                         CryptoFactory.getInstance(this.p);
  907.             }
  908.         }
  909.     }
  910.     public String getSubjectConfirmationMethodHolderOfKeyCryptoCertificateAlias() {
  911.         return this.subjectConfirmationMethodHolderOfKeyCryptoCertificateAlias;
  912.     }
  913.    
  914.     // Conditions
  915.    
  916.     public boolean isConditionsEnabled() {
  917.         return this.conditionsEnabled;
  918.     }
  919.     public int getConditionsDataNotBefore() {
  920.         return this.conditionsDataNotBefore;
  921.     }
  922.     public int getConditionsDataNotOnOrAfter() {
  923.         return this.conditionsDataNotOnOrAfter;
  924.     }
  925.     public String getConditionsAudienceURI() {
  926.         return this.conditionsAudienceURI;
  927.     }
  928.    
  929.     // Authn
  930.    
  931.     public boolean isAuthnStatementEnabled() {
  932.         return this.authnStatementEnabled;
  933.     }
  934.     public int getAuthnStatementDataInstant() {
  935.         return this.authnStatementDataInstant;
  936.     }
  937.     public Date getAuthnStatementDataInstantDate() {
  938.         return this.authnStatementDataInstantDate;
  939.     }
  940.     public int getAuthnStatementDataNotOnOrAfter() {
  941.         return this.authnStatementDataNotOnOrAfter;
  942.     }
  943.     public Date getAuthnStatementDataNotOnOrAfterDate() {
  944.         return this.authnStatementDataNotOnOrAfterDate;
  945.     }
  946.     public String getAuthnStatementClassRef() {
  947.         return this.authnStatementClassRef;
  948.     }
  949.     public String getAuthnSubjectLocalityIpAddress() {
  950.         return this.authnSubjectLocalityIpAddress;
  951.     }
  952.     public String getAuthnSubjectLocalityDnsAddress() {
  953.         return this.authnSubjectLocalityDnsAddress;
  954.     }
  955.    
  956.     // Attribute
  957.    
  958.     public List<SAMLBuilderConfigAttribute> getAttributes() {
  959.         return this.attributes;
  960.     }
  961. }