Added PlugletPolicy class.
Granted AllPermissions for each pluglet git-svn-id: svn://10.0.0.236/trunk@48958 18797224-902f-48f8-a5cc-f745e15eee43
This commit is contained in:
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user