diff --git a/mozilla/java/plugins/classes/org/mozilla/pluglet/PlugletLoader.java b/mozilla/java/plugins/classes/org/mozilla/pluglet/PlugletLoader.java index 3469606bc3c..6b40129fa1e 100644 --- a/mozilla/java/plugins/classes/org/mozilla/pluglet/PlugletLoader.java +++ b/mozilla/java/plugins/classes/org/mozilla/pluglet/PlugletLoader.java @@ -21,6 +21,7 @@ import java.util.jar.Manifest; import java.util.jar.Attributes; import java.io.InputStream; import org.mozilla.pluglet.mozilla.*; +import java.security.*; public class PlugletLoader { // path to jar file. Name of main class sould to be in MANIFEST. @@ -40,6 +41,17 @@ public class PlugletLoader { //nb return null; } + if (policy == null) { + policy = new PlugletPolicy(Policy.getPolicy()); + } + if (policy != Policy.getPolicy()) { + Policy.setPolicy(policy); + } + CodeSource codesource = new CodeSource(url,null); + Permission perm = new AllPermission(); + PermissionCollection collection = perm.newPermissionCollection(); + collection.add(perm); + policy.grantPermission(codesource,collection); Object pluglet = loader.loadClass(plugletClassName).newInstance(); if (pluglet instanceof Pluglet) { return (Pluglet) pluglet; @@ -69,6 +81,7 @@ public class PlugletLoader { return null; } } + private static PlugletPolicy policy = null; } diff --git a/mozilla/java/plugins/classes/org/mozilla/pluglet/PlugletPolicy.java b/mozilla/java/plugins/classes/org/mozilla/pluglet/PlugletPolicy.java new file mode 100644 index 00000000000..15d7779e803 --- /dev/null +++ b/mozilla/java/plugins/classes/org/mozilla/pluglet/PlugletPolicy.java @@ -0,0 +1,56 @@ +/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- + * The contents of this file are subject to the Mozilla Public License + * Version 1.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.mozilla.org/MPL/ + * + * Software distributed under the License is distributed on an "AS IS" + * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See + * the License for the specific language governing rights and limitations + * under the License. + * + * The Initial Developer of the Original Code is Sun Microsystems, + * Inc. Portions created by Sun are Copyright (C) 1999 Sun Microsystems, + * Inc. All Rights Reserved. + */ +package org.mozilla.pluglet; + +import java.security.*; +import java.util.*; + +class PlugletPolicy extends Policy { + PlugletPolicy(Policy peer) { + this.peer = peer; + permissions = null; + } + void grantPermission(CodeSource codesource, PermissionCollection per) { + if (permissions == null) { + permissions = new Vector(10); + } + Object pair[] = new Object[2]; + pair[0] = codesource; pair[1] = per; + permissions.add(pair); + } + public PermissionCollection getPermissions(CodeSource codesource) { + PermissionCollection collection = peer.getPermissions(codesource); + if (collection == null) { + collection = new Permissions(); + } + for (int i = 0; i < permissions.size();i++) { + Object[] pair = (Object[])permissions.elementAt(i); + CodeSource code = (CodeSource) pair[0]; + if (code.implies(codesource)) { + for (Enumeration e = ((PermissionCollection)pair[1]).elements(); e.hasMoreElements() ;) { + collection.add((Permission)e.nextElement()); + } + } + } + return collection; + } + public void refresh() { + peer.refresh(); + } + private Policy peer; + private Vector permissions; +} +