00001 /* 00002 * Copyright (c) 2003-2006, KNOPFLERFISH project 00003 * All rights reserved. 00004 * 00005 * Redistribution and use in source and binary forms, with or without 00006 * modification, are permitted provided that the following 00007 * conditions are met: 00008 * 00009 * - Redistributions of source code must retain the above copyright 00010 * notice, this list of conditions and the following disclaimer. 00011 * 00012 * - Redistributions in binary form must reproduce the above 00013 * copyright notice, this list of conditions and the following 00014 * disclaimer in the documentation and/or other materials 00015 * provided with the distribution. 00016 * 00017 * - Neither the name of the KNOPFLERFISH project nor the names of its 00018 * contributors may be used to endorse or promote products derived 00019 * from this software without specific prior written permission. 00020 * 00021 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 00022 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 00023 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 00024 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 00025 * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 00026 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 00027 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 00028 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 00029 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 00030 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 00031 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED 00032 * OF THE POSSIBILITY OF SUCH DAMAGE. 00033 */ 00034 00035 package org.knopflerfish.framework.permissions; 00036 00037 import java.net.*; 00038 import java.security.*; 00039 00040 import org.knopflerfish.framework.BundleURLStreamHandler; 00041 00042 00043 00051 class FrameworkPolicy extends Policy { 00052 00053 //must not cache 00054 //private Hashtable /* Long -> PermissionCollection */ permissions = new Hashtable(); 00055 00056 private PermissionsHandle ph; 00057 00058 FrameworkPolicy(PermissionsHandle ph) { 00059 this.ph = ph; 00060 } 00061 00062 // 00063 // Policy methods 00064 // 00065 00066 public PermissionCollection getPermissions(CodeSource cs) { 00067 // The following line causes a loop when running on 1.4 00068 // System.getSecurityManager().checkPermission(new SecurityPermission("getPermissions")); 00069 // Also note that there's no "getPermissions" target for SercurityPermission 00070 00071 URL u = cs.getLocation(); 00072 if (u != null && BundleURLStreamHandler.PROTOCOL.equals(u.getProtocol())) { 00073 try { 00074 Long id = new Long(u.getHost()); 00075 //return getPermissions(id); 00076 return ph.getPermissionCollection(id); 00077 } catch (NumberFormatException ignore) { 00078 return null; 00079 } 00080 } else { 00081 PermissionCollection pc = new Permissions(); 00082 pc.add(new AllPermission()); 00083 return pc; 00084 } 00085 } 00086 00087 public void refresh() { 00088 // Nothing todo since we are always updated 00089 } 00090 00091 // 00092 // Package methods 00093 // 00094 00095 /* no, must always refresh from admin! 00096 PermissionCollection getPermissions(Long id) { 00097 00098 PermissionCollection pc = (PermissionCollection)permissions.get(id); 00099 if (pc == null) { 00100 pc = permissionAdmin.getPermissionCollection(id); 00101 if (pc != null) { 00102 permissions.put(id, pc); 00103 } 00104 } 00105 return pc; 00106 } 00107 */ 00108 /* 00109 void invalidate(long id) { 00110 permissions.remove(new Long(id)); 00111 } 00112 */ 00113 }