[jboss-cvs] JBossAS SVN: r95970 - in projects/demos/microcontainer/trunk/classloader/src/main/java/org/jboss/demos/classloader: crypt and 2 other directories.
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Tue Nov 3 12:19:37 EST 2009
Author: alesj
Date: 2009-11-03 12:19:36 -0500 (Tue, 03 Nov 2009)
New Revision: 95970
Added:
projects/demos/microcontainer/trunk/classloader/src/main/java/org/jboss/demos/classloader/policy/
projects/demos/microcontainer/trunk/classloader/src/main/java/org/jboss/demos/classloader/policy/CipherClassLoaderPolicy.java
projects/demos/microcontainer/trunk/classloader/src/main/java/org/jboss/demos/classloader/policy/CipherURLStreamHandler.java
Modified:
projects/demos/microcontainer/trunk/classloader/src/main/java/org/jboss/demos/classloader/crypt/CipherCrypter.java
projects/demos/microcontainer/trunk/classloader/src/main/java/org/jboss/demos/classloader/deployers/DecrypterClassLoaderPolicyModule.java
Log:
Decrypt via cl policy.
Modified: projects/demos/microcontainer/trunk/classloader/src/main/java/org/jboss/demos/classloader/crypt/CipherCrypter.java
===================================================================
--- projects/demos/microcontainer/trunk/classloader/src/main/java/org/jboss/demos/classloader/crypt/CipherCrypter.java 2009-11-03 16:44:39 UTC (rev 95969)
+++ projects/demos/microcontainer/trunk/classloader/src/main/java/org/jboss/demos/classloader/crypt/CipherCrypter.java 2009-11-03 17:19:36 UTC (rev 95970)
@@ -69,6 +69,11 @@
cipher.init(mode, key);
}
+ public Cipher getCipher()
+ {
+ return cipher;
+ }
+
public static Encrypter getEncrypter(Key key) throws Exception
{
return new CipherCrypter(null, Cipher.ENCRYPT_MODE, key);
Modified: projects/demos/microcontainer/trunk/classloader/src/main/java/org/jboss/demos/classloader/deployers/DecrypterClassLoaderPolicyModule.java
===================================================================
--- projects/demos/microcontainer/trunk/classloader/src/main/java/org/jboss/demos/classloader/deployers/DecrypterClassLoaderPolicyModule.java 2009-11-03 16:44:39 UTC (rev 95969)
+++ projects/demos/microcontainer/trunk/classloader/src/main/java/org/jboss/demos/classloader/deployers/DecrypterClassLoaderPolicyModule.java 2009-11-03 17:19:36 UTC (rev 95970)
@@ -21,11 +21,19 @@
*/
package org.jboss.demos.classloader.deployers;
+import java.util.List;
+import java.util.Set;
+
+import javax.crypto.Cipher;
+
import org.jboss.classloading.spi.vfs.policy.VFSClassLoaderPolicy;
+import org.jboss.demos.classloader.crypt.CipherCrypter;
import org.jboss.demos.classloader.crypt.Decrypter;
-import org.jboss.demos.classloader.crypt.DecrypterTranslator;
+import org.jboss.demos.classloader.policy.CipherClassLoaderPolicy;
import org.jboss.deployers.structure.spi.DeploymentUnit;
+import org.jboss.deployers.vfs.plugins.classloader.VFSClassLoaderClassPathDeployer;
import org.jboss.deployers.vfs.plugins.classloader.VFSDeploymentClassLoaderPolicyModule;
+import org.jboss.virtual.VirtualFile;
/**
* @author <a href="mailto:ales.justin at jboss.org">Ales Justin</a>
@@ -34,17 +42,51 @@
{
private Decrypter decrypter;
+ /** No roots */
+ private static final VirtualFile[] NO_ROOTS = new VirtualFile[0];
+
+ /** The cached roots */
+ private VirtualFile[] vfsRoots;
+
+ /** The excluded roots */
+ private VirtualFile[] excludedRoots;
+
+ @SuppressWarnings("unchecked")
public DecrypterClassLoaderPolicyModule(DeploymentUnit unit, Decrypter decrypter)
{
super(unit);
+
this.decrypter = decrypter;
+
+ List<VirtualFile> vfsClassPath = unit.getAttachment(VFSClassLoaderClassPathDeployer.VFS_CLASS_PATH, List.class);
+ if (vfsClassPath == null)
+ vfsRoots = NO_ROOTS;
+ else
+ vfsRoots = vfsClassPath.toArray(new VirtualFile[vfsClassPath.size()]);
+ Set<VirtualFile> vfsExcludes = unit.getAttachment(VFSClassLoaderClassPathDeployer.VFS_EXCLUDES, Set.class);
+ if (vfsExcludes != null)
+ excludedRoots = vfsExcludes.toArray(new VirtualFile[vfsExcludes.size()]);
}
-
+
@Override
protected VFSClassLoaderPolicy determinePolicy()
{
- VFSClassLoaderPolicy policy = super.determinePolicy();
- policy.addTranslator(new DecrypterTranslator(decrypter));
+ Cipher cipher = CipherCrypter.class.cast(decrypter).getCipher(); // hack to get cipher
+
+ CipherClassLoaderPolicy policy = new CipherClassLoaderPolicy(getContextName(), vfsRoots, excludedRoots, cipher);
+ String[] packageNames = getPackageNames();
+ policy.setExportedPackages(packageNames);
+ policy.setIncluded(getIncluded());
+ policy.setExcluded(getExcluded());
+ policy.setExcludedExport(getExcludedExport());
+ policy.setExportAll(getExportAll());
+ policy.setImportAll(isImportAll());
+ policy.setCacheable(isCacheable());
+ policy.setBlackListable(isBlackListable());
+ policy.setDelegates(getDelegates());
+
+ //policy.addTranslator(new DecrypterTranslator(decrypter));
+
return policy;
}
}
\ No newline at end of file
Added: projects/demos/microcontainer/trunk/classloader/src/main/java/org/jboss/demos/classloader/policy/CipherClassLoaderPolicy.java
===================================================================
--- projects/demos/microcontainer/trunk/classloader/src/main/java/org/jboss/demos/classloader/policy/CipherClassLoaderPolicy.java (rev 0)
+++ projects/demos/microcontainer/trunk/classloader/src/main/java/org/jboss/demos/classloader/policy/CipherClassLoaderPolicy.java 2009-11-03 17:19:36 UTC (rev 95970)
@@ -0,0 +1,87 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2008, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.demos.classloader.policy;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.net.URL;
+import java.util.HashSet;
+import java.util.Set;
+
+import javax.crypto.Cipher;
+import javax.crypto.CipherInputStream;
+
+import org.jboss.classloading.spi.vfs.policy.VFSClassLoaderPolicy;
+import org.jboss.virtual.VirtualFile;
+
+/**
+ * @author <a href="mailto:ales.justin at jboss.org">Ales Justin</a>
+ */
+public class CipherClassLoaderPolicy extends VFSClassLoaderPolicy
+{
+ private Cipher cipher;
+
+ public CipherClassLoaderPolicy(String name, VirtualFile[] roots, VirtualFile[] excludedRoots, Cipher cipher)
+ {
+ super(name, roots, excludedRoots);
+ this.cipher = cipher;
+ }
+
+ @Override
+ public URL getResource(String path)
+ {
+ try
+ {
+ URL resource = super.getResource(path);
+ return wrap(resource);
+ }
+ catch (IOException e)
+ {
+ throw new RuntimeException(e);
+ }
+ }
+
+ @Override
+ public InputStream getResourceAsStream(String path)
+ {
+ InputStream stream = super.getResourceAsStream(path);
+ return new CipherInputStream(stream, cipher);
+ }
+
+ @Override
+ public void getResources(String name, Set<URL> urls) throws IOException
+ {
+ super.getResources(name, urls);
+ Set<URL> temp = new HashSet<URL>(urls.size());
+ for (URL url : urls)
+ {
+ temp.add(wrap(url));
+ }
+ urls.clear();
+ urls.addAll(temp);
+ }
+
+ protected URL wrap(URL url) throws IOException
+ {
+ return new URL(url.getProtocol(), url.getHost(), url.getPort(), url.getFile(), new CipherURLStreamHandler(cipher));
+ }
+}
Added: projects/demos/microcontainer/trunk/classloader/src/main/java/org/jboss/demos/classloader/policy/CipherURLStreamHandler.java
===================================================================
--- projects/demos/microcontainer/trunk/classloader/src/main/java/org/jboss/demos/classloader/policy/CipherURLStreamHandler.java (rev 0)
+++ projects/demos/microcontainer/trunk/classloader/src/main/java/org/jboss/demos/classloader/policy/CipherURLStreamHandler.java 2009-11-03 17:19:36 UTC (rev 95970)
@@ -0,0 +1,66 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2008, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.demos.classloader.policy;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.net.URL;
+import java.net.URLConnection;
+import java.net.URLStreamHandler;
+
+import javax.crypto.Cipher;
+import javax.crypto.CipherInputStream;
+
+import org.jboss.net.protocol.DelegatingURLConnection;
+
+/**
+ * @author <a href="mailto:ales.justin at jboss.org">Ales Justin</a>
+ */
+public class CipherURLStreamHandler extends URLStreamHandler
+{
+ private Cipher cipher;
+
+ public CipherURLStreamHandler(Cipher cipher)
+ {
+ this.cipher = cipher;
+ }
+
+ protected URLConnection openConnection(URL url) throws IOException
+ {
+ return new CipherURLConnection(url);
+ }
+
+ private class CipherURLConnection extends DelegatingURLConnection
+ {
+ private CipherURLConnection(URL url) throws IOException
+ {
+ super(url);
+ }
+
+ @Override
+ public InputStream getInputStream() throws IOException
+ {
+ InputStream inputStream = super.getInputStream();
+ return new CipherInputStream(inputStream, cipher);
+ }
+ }
+}
\ No newline at end of file
More information about the jboss-cvs-commits
mailing list