1 11 12 package org.eclipse.osgi.framework.internal.core; 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 String [] infos; 27 private int action; 28 private static final int GET = 1; 29 private static final int SET = 2; 30 private static final int LOCATION = 3; 31 private static final int GET_INFOS = 4; 32 private static final int SAVE_INFOS = 5; 33 34 public SecurePermissionStorage(PermissionStorage storage) { 35 this.storage = storage; 36 } 37 38 public Object run() throws IOException { 39 switch (action) { 40 case GET : 41 return storage.getPermissionData(location); 42 case SET : 43 storage.setPermissionData(location, data); 44 return null; 45 case LOCATION : 46 return storage.getLocations(); 47 case SAVE_INFOS : 48 storage.saveConditionalPermissionInfos(infos); 49 return null; 50 case GET_INFOS : 51 return storage.getConditionalPermissionInfos(); 52 } 53 54 throw new UnsupportedOperationException (); 55 } 56 57 public String [] getPermissionData(String location) throws IOException { 58 this.location = location; 59 this.action = GET; 60 61 try { 62 return (String []) AccessController.doPrivileged(this); 63 } catch (PrivilegedActionException e) { 64 throw (IOException ) e.getException(); 65 } 66 } 67 68 public String [] getLocations() throws IOException { 69 this.action = LOCATION; 70 71 try { 72 return (String []) AccessController.doPrivileged(this); 73 } catch (PrivilegedActionException e) { 74 throw (IOException ) e.getException(); 75 } 76 } 77 78 public void setPermissionData(String location, String [] data) throws IOException { 79 this.location = location; 80 this.data = data; 81 this.action = SET; 82 83 try { 84 AccessController.doPrivileged(this); 85 } catch (PrivilegedActionException e) { 86 throw (IOException ) e.getException(); 87 } 88 } 89 90 public void saveConditionalPermissionInfos(String [] infos) throws IOException { 91 this.action = SAVE_INFOS; 92 this.infos = infos; 93 try { 94 AccessController.doPrivileged(this); 95 } catch (PrivilegedActionException e) { 96 throw (IOException ) e.getException(); 97 } 98 99 } 100 101 public String [] getConditionalPermissionInfos() throws IOException { 102 this.action = GET_INFOS; 103 try { 104 return (String []) AccessController.doPrivileged(this); 105 } catch (PrivilegedActionException e) { 106 throw (IOException ) e.getException(); 107 } 108 } 109 } 110 | Popular Tags |