[jboss-cvs] JBossAS SVN: r80704 - projects/jboss-cl/trunk/classloading-vfs/src/main/java/org/jboss/classloading/spi/vfs/policy.
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Sat Nov 8 02:23:01 EST 2008
Author: anil.saldhana at jboss.com
Date: 2008-11-08 02:23:00 -0500 (Sat, 08 Nov 2008)
New Revision: 80704
Added:
projects/jboss-cl/trunk/classloading-vfs/src/main/java/org/jboss/classloading/spi/vfs/policy/CodeSourceGenerator.java
projects/jboss-cl/trunk/classloading-vfs/src/main/java/org/jboss/classloading/spi/vfs/policy/FileProtocolCodeSourceGenerator.java
Modified:
projects/jboss-cl/trunk/classloading-vfs/src/main/java/org/jboss/classloading/spi/vfs/policy/VFSClassLoaderPolicy.java
Log:
JBCL-64: file based codesource generator
Added: projects/jboss-cl/trunk/classloading-vfs/src/main/java/org/jboss/classloading/spi/vfs/policy/CodeSourceGenerator.java
===================================================================
--- projects/jboss-cl/trunk/classloading-vfs/src/main/java/org/jboss/classloading/spi/vfs/policy/CodeSourceGenerator.java (rev 0)
+++ projects/jboss-cl/trunk/classloading-vfs/src/main/java/org/jboss/classloading/spi/vfs/policy/CodeSourceGenerator.java 2008-11-08 07:23:00 UTC (rev 80704)
@@ -0,0 +1,44 @@
+/*
+ * 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.classloading.spi.vfs.policy;
+
+import java.net.MalformedURLException;
+import java.net.URL;
+import java.security.CodeSource;
+import java.security.cert.Certificate;
+
+/**
+ * Generates a CodeSource for a VFS URL
+ * @author Anil.Saldhana at redhat.com
+ * @since Nov 8, 2008
+ */
+public interface CodeSourceGenerator
+{
+ /**
+ * Generate a CodeSource for the vfs url
+ * @param vfsURL
+ * @param certs
+ * @return
+ * @throws MalformedURLException
+ */
+ CodeSource getCodeSource(URL vfsURL, Certificate[] certs) throws MalformedURLException;
+}
\ No newline at end of file
Added: projects/jboss-cl/trunk/classloading-vfs/src/main/java/org/jboss/classloading/spi/vfs/policy/FileProtocolCodeSourceGenerator.java
===================================================================
--- projects/jboss-cl/trunk/classloading-vfs/src/main/java/org/jboss/classloading/spi/vfs/policy/FileProtocolCodeSourceGenerator.java (rev 0)
+++ projects/jboss-cl/trunk/classloading-vfs/src/main/java/org/jboss/classloading/spi/vfs/policy/FileProtocolCodeSourceGenerator.java 2008-11-08 07:23:00 UTC (rev 80704)
@@ -0,0 +1,54 @@
+/*
+ * 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.classloading.spi.vfs.policy;
+
+import java.net.MalformedURLException;
+import java.net.URL;
+import java.security.CodeSource;
+import java.security.cert.Certificate;
+
+/**
+ * JBCL-64: Generates a CodeSource from a vfs URL
+ * with the substitution of file as protocol
+ * @author Anil.Saldhana at redhat.com
+ * @since Nov 8, 2008
+ */
+public class FileProtocolCodeSourceGenerator implements CodeSourceGenerator
+{
+ /**
+ * Constant representing the URL file protocol
+ */
+ private static final String FILE_PROTOCOL = "file";
+
+ /**
+ * @see CodeSourceGenerator#getCodeSource(URL, Certificate[])s
+ */
+ public CodeSource getCodeSource(URL vfsURL, Certificate[] certs)
+ throws MalformedURLException
+ {
+ URL codesourceURL = new URL(FILE_PROTOCOL,
+ vfsURL.getHost(), vfsURL.getPort(),
+ vfsURL.getFile());
+
+ return new CodeSource(codesourceURL, certs);
+ }
+}
Modified: projects/jboss-cl/trunk/classloading-vfs/src/main/java/org/jboss/classloading/spi/vfs/policy/VFSClassLoaderPolicy.java
===================================================================
--- projects/jboss-cl/trunk/classloading-vfs/src/main/java/org/jboss/classloading/spi/vfs/policy/VFSClassLoaderPolicy.java 2008-11-08 07:20:39 UTC (rev 80703)
+++ projects/jboss-cl/trunk/classloading-vfs/src/main/java/org/jboss/classloading/spi/vfs/policy/VFSClassLoaderPolicy.java 2008-11-08 07:23:00 UTC (rev 80704)
@@ -108,10 +108,8 @@
@SuppressWarnings("unchecked")
private Map<String, VirtualFileInfo> vfsCache = Collections.synchronizedMap(new SoftValueHashMap());
- /**
- * Constant representing the URL file protocol
- */
- private static final String FILE_PROTOCOL = "file";
+ /** A generator that is capable of providing Java Security Manager friendly CodeSource */
+ private CodeSourceGenerator codeSourceGenerator = new FileProtocolCodeSourceGenerator();
/**
* Determine a name from the roots
@@ -186,6 +184,7 @@
{
return new VFSClassLoaderPolicy(name, roots, excludedRoots);
}
+
/**
* Create a new VFSClassLoaderPolicy.
@@ -513,6 +512,21 @@
}
/**
+ * Set a CodeSource Generator
+ * @param csg
+ */
+ public void setCodeSourceGenerator(final CodeSourceGenerator csg)
+ {
+ String perm = "org.jboss.classloading.spi.vfs.policy.VFSClassLoaderPolicy.setCodeSourceGenerator";
+ RuntimePermission rtp = new RuntimePermission(perm);
+ SecurityManager sm = System.getSecurityManager();
+ if(sm != null)
+ sm.checkPermission(rtp);
+
+ codeSourceGenerator = csg;
+ }
+
+ /**
* Find a child from a path
*
* @param path the path
@@ -626,18 +640,10 @@
try
{
VirtualFile root = findRoot(path);
- URL codeSourceURL = root.toURL();
+ URL codeSourceURL = root.toURL();
- /**
- * JBCL-64:Currently we are just dealing with the root
- * So we will use the file equivalent of the root
- */
- URL modifiedURL = new URL(FILE_PROTOCOL,
- codeSourceURL.getHost(), codeSourceURL.getPort(),
- codeSourceURL.getFile());
-
Certificate[] certs = null; // TODO JBMICROCONT-182 determine certificates
- CodeSource cs = new CodeSource(modifiedURL, certs);
+ CodeSource cs = codeSourceGenerator.getCodeSource(codeSourceURL, certs);
PermissionCollection permissions = Policy.getPolicy().getPermissions(cs);
return new ProtectionDomain(cs, permissions);
}
More information about the jboss-cvs-commits
mailing list