1 11 12 package org.eclipse.osgi.framework.util; 13 14 import java.io.IOException ; 15 import java.security.*; 16 import org.eclipse.osgi.framework.adaptor.PermissionStorage; 17 18 21 22 public class SecurePermissionStorage implements PermissionStorage, PrivilegedExceptionAction { 23 private PermissionStorage storage; 24 private String location; 25 private String [] data; 26 private int action; 27 private static final int GET = 1; 28 private static final int SET = 2; 29 private static final int LOCATION = 3; 30 31 public SecurePermissionStorage(PermissionStorage storage) { 32 this.storage = storage; 33 } 34 35 public Object run() throws IOException { 36 switch (action) { 37 case GET : 38 return storage.getPermissionData(location); 39 case SET : 40 storage.setPermissionData(location, data); 41 return null; 42 case LOCATION : 43 return storage.getLocations(); 44 } 45 46 throw new UnsupportedOperationException (); 47 } 48 49 public String [] getPermissionData(String location) throws IOException { 50 this.location = location; 51 this.action = GET; 52 53 try { 54 return (String []) AccessController.doPrivileged(this); 55 } catch (PrivilegedActionException e) { 56 throw (IOException ) e.getException(); 57 } 58 } 59 60 public String [] getLocations() throws IOException { 61 this.action = LOCATION; 62 63 try { 64 return (String []) AccessController.doPrivileged(this); 65 } catch (PrivilegedActionException e) { 66 throw (IOException ) e.getException(); 67 } 68 } 69 70 public void setPermissionData(String location, String [] data) throws IOException { 71 this.location = location; 72 this.data = data; 73 this.action = SET; 74 75 try { 76 AccessController.doPrivileged(this); 77 } catch (PrivilegedActionException e) { 78 throw (IOException ) e.getException(); 79 } 80 } 81 } | Popular Tags |