PermissionAdminImpl.java

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.security.AccessController;
00038 import java.security.AllPermission;
00039 
00040 import org.osgi.service.permissionadmin.*;
00041 
00042 
00043 
00052 public class PermissionAdminImpl implements PermissionAdmin {
00053 
00054   public final static String SPEC_VERSION = "1.2";
00055 
00059   final private AllPermission ALL_PERMISSION = new AllPermission();
00060   
00061   final private PermissionInfoStorage pinfos;
00062   
00063 
00064   public PermissionAdminImpl(PermissionInfoStorage pis) {
00065     pinfos = pis;
00066   }
00067   
00068   
00069   //
00070   // Interface PermissionAdmin
00071   //
00072 
00084   public PermissionInfo[] getPermissions(String location) {
00085     PermissionInfo[] res = pinfos.get(location, null);
00086     return res != null ? (PermissionInfo[])res.clone() : null;
00087   }
00088 
00089 
00101   public synchronized void setPermissions(String location, PermissionInfo[] perms) {
00102     AccessController.checkPermission(ALL_PERMISSION);
00103     if (perms != null) {
00104       pinfos.put(location, (PermissionInfo[])perms.clone());
00105     } else {
00106       pinfos.remove(location);
00107     }
00108   }
00109 
00110 
00118   public String[] getLocations() {
00119     return pinfos.getKeys();
00120   }
00121 
00122   
00132   public synchronized PermissionInfo[] getDefaultPermissions() {
00133     PermissionInfo[] res = pinfos.getDefault(null);
00134     return res != null ? (PermissionInfo[])res.clone() : null;
00135   }
00136 
00137 
00150   public synchronized void setDefaultPermissions(PermissionInfo[] perms) {
00151     AccessController.checkPermission(ALL_PERMISSION);
00152     if (perms != null) {
00153       perms = (PermissionInfo[])perms.clone();
00154     }
00155     pinfos.putDefault(perms);
00156   }
00157 
00158 }

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