Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  /*
   * =============================================================================
   * 
   *   Copyright (c) 2007, The JASYPT team (http://www.jasypt.org)
   * 
   *   Licensed under the Apache License, Version 2.0 (the "License");
   *   you may not use this file except in compliance with the License.
   *   You may obtain a copy of the License at
   * 
  *       http://www.apache.org/licenses/LICENSE-2.0
  * 
  *   Unless required by applicable law or agreed to in writing, software
  *   distributed under the License is distributed on an "AS IS" BASIS,
  *   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  *   See the License for the specific language governing permissions and
  *   limitations under the License.
  * 
  * =============================================================================
  */
 package org.jasypt.encryption.pbe.config;
 
 

Implementation for PBEConfig which can retrieve configuration values from environment variables or system properties.

The name of the environment variable or system property (JVM property) to query for each parameter can be set with its corresponding setXEnvName or setXSysProperty method.

As this class extends SimplePBEConfig, parameter values can be also set with the usual setX methods.

For any of the configuration parameters, if its value is not configured in any way, a null value will be returned by the corresponding getX method.

Author(s):
Daniel Fernández Garrido
Since:
1.1
 
 public class EnvironmentPBEConfig extends SimplePBEConfig {
     
     private String algorithmEnvName = null;
     private String keyObtentionIterationsEnvName = null;
     private String passwordEnvName = null;
     private String saltGeneratorClassNameEnvName = null;
     private String providerNameEnvName = null;
     private String providerClassNameEnvName = null;
 
     private String algorithmSysPropertyName = null;
     private String keyObtentionIterationsSysPropertyName = null;
     private String passwordSysPropertyName = null;
     private String saltGeneratorClassNameSysPropertyName = null;
     private String providerNameSysPropertyName = null;
     private String providerClassNameSysPropertyName = null;
    

    

Creates a new EnvironmentPBEConfig instance.

 
     public EnvironmentPBEConfig() {
         super();
     }



    
Retrieve the name of the environment variable which value has been loaded as the algorithm.

Returns:
the name of the variable
 
     public String getAlgorithmEnvName() {
         return ;
     }


    
Set the config object to use the specified environment variable to load the value for the algorithm.

Parameters:
algorithmEnvName the name of the environment variable
 
     public void setAlgorithmEnvName(String algorithmEnvName) {
         this. = algorithmEnvName;
         if (algorithmEnvName == null) {
            super.setAlgorithm(null);
        } else {
            this. = null;
            super.setAlgorithm(System.getenv(algorithmEnvName));
        }
    }


    
Retrieve the name of the JVM system property which value has been loaded as the algorithm.

Returns:
the name of the property
        return ;
    }


    
Set the config object to use the specified JVM system property to load the value for the algorithm.

Parameters:
algorithmSysPropertyName the name of the property
    public void setAlgorithmSysPropertyName(String algorithmSysPropertyName) {
        this. = algorithmSysPropertyName;
        if (algorithmSysPropertyName == null) {
            super.setAlgorithm(null);
        } else {
            this. = null;
            super.setAlgorithm(System.getProperty(algorithmSysPropertyName));
        }
    }


    
Retrieve the name of the environment variable which value has been loaded as the key obtention iteration count.

Returns:
the name of the variable
        return ;
    }


    
Set the config object to use the specified environment variable to load the value for the key obtention iteration count.

Parameters:
keyObtentionIterationsEnvName the name of the environment variable
    public void setKeyObtentionIterationsEnvName(String keyObtentionIterationsEnvName) {
        this. = keyObtentionIterationsEnvName;
        if (keyObtentionIterationsEnvName == null) {
            super.setKeyObtentionIterations(null);
        } else {
            this. = null;
            String iterationsStr = System.getenv(keyObtentionIterationsEnvName);
            if (iterationsStr != null) {
                try {
                    super.setKeyObtentionIterations(new Integer(iterationsStr));
                } catch (NumberFormatException e) {
                    throw new EncryptionInitializationException(e);
                }
            }
        }
    }


    
Retrieve the name of the JVM system property which value has been loaded as the key obtention iteration count.

Returns:
the name of the property
    }


    
Set the config object to use the specified JVM system property to load the value for the key obtention iteration count.

Parameters:
keyObtentionIterationsSysPropertyName the name of the property
    public void setKeyObtentionIterationsSysPropertyName(String keyObtentionIterationsSysPropertyName) {
        this. = keyObtentionIterationsSysPropertyName;
        if (keyObtentionIterationsSysPropertyName == null) {
            super.setKeyObtentionIterations(null);
        } else {
            this. = null;
            String iterationsStr = System.getProperty(keyObtentionIterationsSysPropertyName);
            if (iterationsStr != null) {
                try {
                    super.setKeyObtentionIterations(new Integer(iterationsStr));
                } catch (NumberFormatException e) {
                    throw new EncryptionInitializationException(e);
                }
            }
        }
    }


    
Retrieve the name of the environment variable which value has been loaded as the password.

Returns:
the name of the variable
    public String getPasswordEnvName() {
        return ;
    }


    
Set the config object to use the specified environment variable to load the value for the password.

Parameters:
passwordEnvName the name of the environment variable
    public void setPasswordEnvName(String passwordEnvName) {
        this. = passwordEnvName;
        if (passwordEnvName == null) {
            super.setPassword(null);
        } else {
            this. = null;
            super.setPassword(System.getenv(passwordEnvName));
        }
    }


    
Retrieve the name of the JVM system property which value has been loaded as the password.

Returns:
the name of the property
        return ;
    }


    
Set the config object to use the specified JVM system property to load the value for the password.

Parameters:
passwordSysPropertyName the name of the property
    public void setPasswordSysPropertyName(String passwordSysPropertyName) {
        this. = passwordSysPropertyName;
        if (passwordSysPropertyName == null) {
            super.setPassword(null);
        } else {
            this. = null;
            super.setPassword(System.getProperty(passwordSysPropertyName));
        }
    }


    
Retrieve the name of the environment variable which value has been loaded as the salt generator class name.

Returns:
the name of the variable
Since:
1.3
        return ;
    }

   
    

Set the config object to use the specified environment variable to load the value for the salt generator class name.

The salt generator class name which is set here must have a no-argument constructor, so that it can be instantiated and passed to the encryptor.

Parameters:
saltGeneratorClassNameEnvName the name of the environment variable
Since:
1.3
    public void setSaltGeneratorClassNameEnvName(String saltGeneratorClassNameEnvName) {
        this. = saltGeneratorClassNameEnvName;
        if (saltGeneratorClassNameEnvName == null) {
            super.setSaltGenerator(null);
        } else {
            this. = null;
            String saltGeneratorClassName = System.getenv(saltGeneratorClassNameEnvName);
            try {
                Class saltGeneratorClass = Class.forName(saltGeneratorClassName);
                SaltGenerator saltGenerator = (SaltGeneratorsaltGeneratorClass.newInstance();
                super.setSaltGenerator(saltGenerator);
            } catch (Exception e) {
                throw new EncryptionInitializationException(e);
            }
        }
    }


    
Retrieve the name of the JVM system property which value has been loaded as the salt generator class name.

Returns:
the name of the property
Since:
1.3
    }


    

Set the config object to use the specified JVM system property to load the value for the salt generator class name.

The salt generator class name which is set here must have a no-argument constructor, so that it can be instantiated and passed to the encryptor.

Parameters:
saltGeneratorClassNameSysPropertyName the name of the property
Since:
1.3
    public void setSaltGeneratorClassNameSysPropertyName(String saltGeneratorClassNameSysPropertyName) {
        this. = saltGeneratorClassNameSysPropertyName;
        if (saltGeneratorClassNameSysPropertyName == null) {
            super.setSaltGenerator(null);
        } else {
            this. = null;
            String saltGeneratorClassName = System.getProperty(saltGeneratorClassNameSysPropertyName);
            try {
                Class saltGeneratorClass = Class.forName(saltGeneratorClassName);
                SaltGenerator saltGenerator = (SaltGeneratorsaltGeneratorClass.newInstance();
                super.setSaltGenerator(saltGenerator);
            } catch (Exception e) {
                throw new EncryptionInitializationException(e);
            }
        }
    }


    
Retrieve the name of the environment variable which value has been loaded as the provider name.

Returns:
the name of the variable
Since:
1.3
    public String getProviderNameEnvName() {
        return ;
    }


    

Set the config object to use the specified environment variable to load the value for the provider name.

Parameters:
providerNameEnvName the name of the environment variable
Since:
1.3
    public void setProviderNameEnvName(String providerNameEnvName) {
        this. = providerNameEnvName;
        if (providerNameEnvName == null) {
            super.setProviderName(null);
        } else {
            this. = null;
            super.setProviderName(System.getenv(providerNameEnvName));
        }
    }


    
Retrieve the name of the JVM system property which value has been loaded as the provider name.

Returns:
the name of the property
Since:
1.3
        return ;
    }


    
Set the config object to use the specified JVM system property to load the value for the provider name.

Parameters:
providerNameSysPropertyName the name of the property
Since:
1.3
    public void setProviderNameSysPropertyName(String providerNameSysPropertyName) {
        this. = providerNameSysPropertyName;
        if (providerNameSysPropertyName == null) {
            super.setProviderName(null);
        } else {
            this. = null;
            super.setProviderName(System.getProperty(providerNameSysPropertyName));
        }
    }


    
Retrieve the name of the environment variable which value has been loaded as the provider class name.

Returns:
the name of the variable
Since:
1.3
        return ;
    }


    

Set the config object to use the specified environment variable to load the value for the provider class name.

The provider class name which is set here must have a no-argument constructor, so that it can be instantiated and passed to the encryptor.

Parameters:
providerClassNameEnvName the name of the environment variable
Since:
1.3
    public void setProviderClassNameEnvName(String providerClassNameEnvName) {
        this. = providerClassNameEnvName;
        if (providerClassNameEnvName == null) {
            super.setProvider(null);
        } else {
            this. = null;
            String providerClassName = System.getenv(providerClassNameEnvName);
            try {
                Class providerClass = Class.forName(providerClassName);
                Provider provider = (ProviderproviderClass.newInstance();
                super.setProvider(provider);
            } catch (Exception e) {
                throw new EncryptionInitializationException(e);
            }
        }
    }


    
Retrieve the name of the JVM system property which value has been loaded as the provider class name.

Returns:
the name of the property
Since:
1.3
        return ;
    }


    

Set the config object to use the specified JVM system property to load the value for the provider class name.

The provider class name which is set here must have a no-argument constructor, so that it can be instantiated and passed to the encryptor.

Parameters:
providerClassNameSysPropertyName the name of the property
Since:
1.3
    public void setProviderClassNameSysPropertyName(String providerClassNameSysPropertyName) {
        this. = providerClassNameSysPropertyName;
        if (providerClassNameSysPropertyName == null) {
            super.setProvider(null);
        } else {
            this. = null;
            String providerClassName = System.getProperty(providerClassNameSysPropertyName);
            try {
                Class providerClass = Class.forName(providerClassName);
                Provider provider = (ProviderproviderClass.newInstance();
                super.setProvider(provider);
            } catch (Exception e) {
                throw new EncryptionInitializationException(e);
            }
        }
    }
    
    
    
    
    
    public void setAlgorithm(String algorithm) {
        this. = null;
        this. = null;
        super.setAlgorithm(algorithm);
    }
    public void setKeyObtentionIterations(Integer keyObtentionIterations) {
        this. = null;
        this. = null;
        super.setKeyObtentionIterations(keyObtentionIterations);
    }
    public void setPassword(String password) {
        this. = null;
        this. = null;
        super.setPassword(password);
    }
    
    
    public void setSaltGenerator(SaltGenerator saltGenerator) {
        this. = null;
        this. = null;
        super.setSaltGenerator(saltGenerator);
    }
    public void setProviderName(String providerName) {
        this. = null;
        this. = null;
        super.setProviderName(providerName);
    }
    
    
    public void setProvider(Provider provider) {
        this. = null;
        this. = null;
        super.setProvider(provider);
    }
    
New to GrepCode? Check out our FAQ X