Author: sgoeschl
Date: Mon Jul 21 09:38:21 2008
New Revision: 678467
URL: http://svn.apache.org/viewvc?rev=678467&view=rev
Log:
Refactored the transparent decryption of configuration files into
seperate/optional project because most people don't need that functionality.
Added:
turbine/fulcrum/trunk/yaafi/src/java/org/apache/fulcrum/yaafi/framework/crypto/
turbine/fulcrum/trunk/yaafi/src/java/org/apache/fulcrum/yaafi/framework/crypto/CryptoStreamFactory.java
Removed:
turbine/fulcrum/trunk/yaafi/src/java/org/apache/fulcrum/jce/crypto/CryptoParameters.java
turbine/fulcrum/trunk/yaafi/src/java/org/apache/fulcrum/jce/crypto/CryptoStreamFactory.java
turbine/fulcrum/trunk/yaafi/src/java/org/apache/fulcrum/jce/crypto/CryptoStreamFactoryImpl.java
turbine/fulcrum/trunk/yaafi/src/java/org/apache/fulcrum/jce/crypto/CryptoUtil.java
turbine/fulcrum/trunk/yaafi/src/java/org/apache/fulcrum/jce/crypto/HexConverter.java
turbine/fulcrum/trunk/yaafi/src/java/org/apache/fulcrum/jce/crypto/Main.java
turbine/fulcrum/trunk/yaafi/src/java/org/apache/fulcrum/jce/crypto/PasswordFactory.java
turbine/fulcrum/trunk/yaafi/src/java/org/apache/fulcrum/jce/crypto/PasswordParameters.java
turbine/fulcrum/trunk/yaafi/src/java/org/apache/fulcrum/jce/crypto/SmartDecryptingInputStream.java
turbine/fulcrum/trunk/yaafi/src/test/org/apache/fulcrum/jce/crypto/CryptoUtilTest.java
turbine/fulcrum/trunk/yaafi/src/test/org/apache/fulcrum/jce/crypto/SmartDecryptingInputStreamTest.java
Modified:
turbine/fulcrum/trunk/yaafi/pom.xml
turbine/fulcrum/trunk/yaafi/src/java/org/apache/fulcrum/yaafi/framework/container/ServiceContainerImpl.java
turbine/fulcrum/trunk/yaafi/src/java/org/apache/fulcrum/yaafi/framework/factory/ServiceContainerConfiguration.java
Modified: turbine/fulcrum/trunk/yaafi/pom.xml
URL:
http://svn.apache.org/viewvc/turbine/fulcrum/trunk/yaafi/pom.xml?rev=678467&r1=678466&r2=678467&view=diff
==============================================================================
--- turbine/fulcrum/trunk/yaafi/pom.xml (original)
+++ turbine/fulcrum/trunk/yaafi/pom.xml Mon Jul 21 09:38:21 2008
@@ -60,12 +60,6 @@
</developers>
<dependencies>
- <dependency>
- <groupId>junit</groupId>
- <artifactId>junit</artifactId>
- <version>3.8.1</version>
- <scope>test</scope>
- </dependency>
<!-- Avalon depedencies -->
<dependency>
<groupId>avalon-framework</groupId>
@@ -121,6 +115,13 @@
</exclusion>
</exclusions>
</dependency>
+ <!-- Optional decrytpion of configuration files -->
+ <dependency>
+ <groupId>fulcrum</groupId>
+ <artifactId>fulcrum-yaafi-crypto</artifactId>
+ <version>1.0.6-SNAPSHOT</version>
+ <optional>true</optional>
+ </dependency>
<!-- Interceptor dependencies -->
<dependency>
<groupId>com.jamonapi</groupId>
@@ -128,6 +129,13 @@
<version>2.4</version>
<optional>true</optional>
</dependency>
+ <!-- Testing dependencies -->
+ <dependency>
+ <groupId>junit</groupId>
+ <artifactId>junit</artifactId>
+ <version>3.8.1</version>
+ <scope>test</scope>
+ </dependency>
</dependencies>
<build>
Modified:
turbine/fulcrum/trunk/yaafi/src/java/org/apache/fulcrum/yaafi/framework/container/ServiceContainerImpl.java
URL:
http://svn.apache.org/viewvc/turbine/fulcrum/trunk/yaafi/src/java/org/apache/fulcrum/yaafi/framework/container/ServiceContainerImpl.java?rev=678467&r1=678466&r2=678467&view=diff
==============================================================================
---
turbine/fulcrum/trunk/yaafi/src/java/org/apache/fulcrum/yaafi/framework/container/ServiceContainerImpl.java
(original)
+++
turbine/fulcrum/trunk/yaafi/src/java/org/apache/fulcrum/yaafi/framework/container/ServiceContainerImpl.java
Mon Jul 21 09:38:21 2008
@@ -20,9 +20,7 @@
*/
import java.io.File;
-import java.io.IOException;
import java.io.InputStream;
-import java.security.GeneralSecurityException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
@@ -41,7 +39,6 @@
import org.apache.avalon.framework.parameters.Parameters;
import org.apache.avalon.framework.service.ServiceException;
import org.apache.avalon.framework.service.ServiceManager;
-import org.apache.fulcrum.jce.crypto.CryptoStreamFactoryImpl;
import org.apache.fulcrum.yaafi.framework.component.AvalonServiceComponentImpl;
import org.apache.fulcrum.yaafi.framework.component.ServiceComponent;
import
org.apache.fulcrum.yaafi.framework.configuration.ComponentConfigurationPropertiesResolver;
@@ -58,6 +55,7 @@
import org.apache.fulcrum.yaafi.framework.util.StringUtils;
import org.apache.fulcrum.yaafi.framework.util.ToStringBuilder;
import org.apache.fulcrum.yaafi.framework.util.Validate;
+import org.apache.fulcrum.yaafi.framework.crypto.CryptoStreamFactory;
/**
* Yet another avalon framework implementation (YAAFI).
@@ -1330,13 +1328,8 @@
{
try
{
- if( isEncrypted.equalsIgnoreCase("false") == false)
- {
- is = this.getDecryptingInputStream( is, isEncrypted );
- }
-
+ is = this.getDecryptingInputStream( is, isEncrypted );
result = builder.build( is );
-
is.close();
is = null;
}
@@ -1405,17 +1398,12 @@
if( is != null )
{
- if( isEncrypted.equalsIgnoreCase("false") == false )
- {
- is = this.getDecryptingInputStream( is, isEncrypted );
- }
-
+ is = this.getDecryptingInputStream( is, isEncrypted );
Properties props = new Properties();
props.load( is );
- result = Parameters.fromProperties( props );
-
is.close();
is = null;
+ result = Parameters.fromProperties( props );
}
return result;
@@ -1550,27 +1538,12 @@
* @param is the input stream to be decrypted
* @param isEncrypted the encryption mode (true|false|auto)
* @return an decrypting input stream
- * @throws IOException reading the input stream failed
- * @throws GeneralSecurityException accessing the JCA indrastructure failed
+ * @throws Exception reading the input stream failed
*/
private InputStream getDecryptingInputStream( InputStream is, String
isEncrypted )
- throws IOException, GeneralSecurityException
+ throws Exception
{
- InputStream result = null;
-
- if( isEncrypted.equalsIgnoreCase("true") )
- {
- result = CryptoStreamFactoryImpl.getInstance().getInputStream(is);
- }
- else if( isEncrypted.equalsIgnoreCase("auto") )
- {
- result =
CryptoStreamFactoryImpl.getInstance().getSmartInputStream(is);
- }
- else
- {
- result = is;
- }
- return result;
+ return CryptoStreamFactory.getDecryptingInputStream(is, isEncrypted);
}
/**
Added:
turbine/fulcrum/trunk/yaafi/src/java/org/apache/fulcrum/yaafi/framework/crypto/CryptoStreamFactory.java
URL:
http://svn.apache.org/viewvc/turbine/fulcrum/trunk/yaafi/src/java/org/apache/fulcrum/yaafi/framework/crypto/CryptoStreamFactory.java?rev=678467&view=auto
==============================================================================
---
turbine/fulcrum/trunk/yaafi/src/java/org/apache/fulcrum/yaafi/framework/crypto/CryptoStreamFactory.java
(added)
+++
turbine/fulcrum/trunk/yaafi/src/java/org/apache/fulcrum/yaafi/framework/crypto/CryptoStreamFactory.java
Mon Jul 21 09:38:21 2008
@@ -0,0 +1,122 @@
+package org.apache.fulcrum.yaafi.framework.crypto;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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.
+ */
+
+import org.apache.fulcrum.yaafi.framework.reflection.Clazz;
+
+import java.io.InputStream;
+import java.io.IOException;
+import java.security.GeneralSecurityException;
+import java.lang.reflect.InvocationTargetException;
+
+/**
+ * Factory class to get a decrypting input stream for reading configuration
+ * files.
+ *
+ * @author <a href="mailto:[EMAIL PROTECTED]">Siegfried Goeschl </a>
+ */
+
+public class CryptoStreamFactory
+{
+ /** is the instance already initialized */
+ private static boolean isInitialized;
+
+ /** the factory to create encrypting input streams */
+ private static Object cryptoStreamFactory;
+
+ /** the name of the class to be loaded */
+ private static String className =
"org.apache.fulcrum.jce.crypto.CryptoStreamFactoryImpl";
+
+ /**
+ * Create a decrypting input stream using the default password.
+ *
+ * @param is the input stream to be decrypted
+ * @param isEncrypted the encryption mode (true|false|auto)
+ * @return an decrypting input stream
+ * @throws Exception reading the input stream failed
+ */
+ public static InputStream getDecryptingInputStream( InputStream is, String
isEncrypted )
+ throws Exception
+ {
+ InputStream result;
+
+ if( isEncrypted.equalsIgnoreCase("true") )
+ {
+ result = createDecryptingInputStream(is, "getInputStream");
+ }
+ else if( isEncrypted.equalsIgnoreCase("auto") )
+ {
+ result = createDecryptingInputStream(is, "getSmartInputStream");
+ }
+ else if( isEncrypted.equalsIgnoreCase("false") )
+ {
+ result = is;
+ }
+ else
+ {
+ throw new IllegalArgumentException("Unknown decryption mode : " +
isEncrypted);
+ }
+
+ return result;
+ }
+
+ /**
+ * Factory method to create a decrypting input stream.
+ */
+ private static InputStream createDecryptingInputStream( InputStream is,
String methodName )
+ throws Exception
+ {
+ Class[] signature = {InputStream.class};
+ Object[] args = {is};
+ Object cryptoStreamFactory = getCryptoStreamFactory();
+
+ if(cryptoStreamFactory == null)
+ {
+ throw new IllegalStateException("No CryptoStreamFactory available
- unable to create a decrypting input stream");
+ }
+ else
+ {
+ return (InputStream) Clazz.invoke(cryptoStreamFactory, methodName,
signature, args);
+ }
+ }
+
+ /**
+ * Factory method to create a CryptoStreamFactory.
+ */
+ private synchronized static Object getCryptoStreamFactory()
+ throws Exception
+ {
+ if(!isInitialized)
+ {
+ isInitialized = true;
+ ClassLoader clazzLoader =
CryptoStreamFactory.class.getClassLoader();
+
+ if(Clazz.hasClazz(clazzLoader, className))
+ {
+ Class[] signature = {};
+ Object[] args = {};
+ Class clazz = Clazz.getClazz(clazzLoader, className);
+ cryptoStreamFactory = Clazz.newInstance(clazz, signature,
args);
+ }
+ }
+
+ return cryptoStreamFactory;
+ }
+}
Modified:
turbine/fulcrum/trunk/yaafi/src/java/org/apache/fulcrum/yaafi/framework/factory/ServiceContainerConfiguration.java
URL:
http://svn.apache.org/viewvc/turbine/fulcrum/trunk/yaafi/src/java/org/apache/fulcrum/yaafi/framework/factory/ServiceContainerConfiguration.java?rev=678467&r1=678466&r2=678467&view=diff
==============================================================================
---
turbine/fulcrum/trunk/yaafi/src/java/org/apache/fulcrum/yaafi/framework/factory/ServiceContainerConfiguration.java
(original)
+++
turbine/fulcrum/trunk/yaafi/src/java/org/apache/fulcrum/yaafi/framework/factory/ServiceContainerConfiguration.java
Mon Jul 21 09:38:21 2008
@@ -33,11 +33,11 @@
import org.apache.avalon.framework.logger.ConsoleLogger;
import org.apache.avalon.framework.logger.Logger;
import org.apache.avalon.framework.service.ServiceManager;
-import org.apache.fulcrum.jce.crypto.CryptoStreamFactoryImpl;
import org.apache.fulcrum.yaafi.framework.constant.AvalonMerlinConstants;
import org.apache.fulcrum.yaafi.framework.container.ServiceConstants;
import org.apache.fulcrum.yaafi.framework.util.InputStreamLocator;
import org.apache.fulcrum.yaafi.framework.util.Validate;
+import org.apache.fulcrum.yaafi.framework.crypto.CryptoStreamFactory;
/**
* Helper class to capture configuration related stuff. The are two ways
@@ -709,30 +709,13 @@
DefaultConfigurationBuilder builder = new
DefaultConfigurationBuilder();
InputStream is = locator.locate( location );
- InputStream cis = is;
if( is != null )
{
try
{
- if( isEncrypted.equalsIgnoreCase("true") )
- {
- cis =
CryptoStreamFactoryImpl.getInstance().getInputStream(is);
- result = builder.build( cis );
- cis.close();
- }
- if( isEncrypted.equalsIgnoreCase("auto") )
- {
- cis =
CryptoStreamFactoryImpl.getInstance().getSmartInputStream(is);
- result = builder.build( cis );
- cis.close();
- }
- else
- {
- result = builder.build( is );
- is.close();
- }
-
+ is = CryptoStreamFactory.getDecryptingInputStream(is
,isEncrypted);
+ result = builder.build( is );
this.setContainerConfiguration( result );
}
catch ( Exception e )