PermissionsHandle.java

00001 /*
00002  * Copyright (c) 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.io.*;
00038 import java.net.URL;
00039 import java.security.*;
00040 import java.security.cert.Certificate;
00041 import java.util.ArrayList;
00042 import java.util.Enumeration;
00043 import java.util.HashMap;
00044 import java.util.Hashtable;
00045 import java.util.Vector;
00046 
00047 import org.osgi.framework.AdminPermission;
00048 import org.osgi.framework.Bundle;
00049 import org.osgi.service.permissionadmin.PermissionInfo;
00050 import org.knopflerfish.framework.Framework;
00051 import org.knopflerfish.framework.Util;
00052 
00053 
00054 public class PermissionsHandle {
00055 
00056   Framework framework;
00057 
00058   private PermissionInfoStorage pinfos;
00059   private Hashtable /* Long -> PermissionCollection */ pcCache = new Hashtable();
00060   private PermissionAdminImpl pa;
00061 
00062 
00063   public PermissionsHandle(Framework fw) {
00064     framework = fw;
00065     pinfos = new PermissionInfoStorage();
00066     pa = new PermissionAdminImpl(pinfos);     
00067     Policy.setPolicy(new FrameworkPolicy(this));
00068   }
00069 
00070 
00076   public PermissionAdminImpl getPermissionAdminService() {
00077     return pa;
00078   }
00079 
00080 
00092   public PermissionCollection getPermissionCollection(Long bid) {
00093     return (PermissionCollection)pcCache.get(bid);
00094   }
00095 
00096   
00108   public  PermissionCollection createPermissionCollection(String loc,
00109                                                           Bundle b,
00110                                                           InputStream localPerms) {
00111     Long bid = new Long(b.getBundleId());
00112     PermissionCollection pc = new PermissionsWrapper(framework, pinfos, loc, b, localPerms);
00113     pcCache.put(bid, pc);
00114     return pc;
00115   }
00116 
00117 
00126   public boolean purgePermissionCollection(Long bid, PermissionCollection pc) {
00127     pinfos.purgeCallback(pc);
00128     if (pcCache.get(bid) == pc) {
00129       pcCache.remove(bid);
00130       return true;
00131     }
00132     return false;
00133   }
00134 
00135 }

Generated on Mon Jan 11 21:19:16 2010 for OpenMobileIS by  doxygen 1.5.4