1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109
|
/*******************************************************************************
* Copyright (c) 2003, 2010 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* IBM Corporation - initial API and implementation
*******************************************************************************/
package org.eclipse.osgi.internal.permadmin;
import java.io.IOException;
import java.security.*;
import org.eclipse.osgi.framework.adaptor.PermissionStorage;
/**
* PermissionStorage privileged action class. This class is not thread safe. Callers
* must ensure multiple threads do not call methods on this class at the same time.
*/
public class SecurePermissionStorage implements PermissionStorage, PrivilegedExceptionAction<String[]> {
private final PermissionStorage storage;
private String location;
private String[] data;
private String[] infos;
private int action;
private static final int GET = 1;
private static final int SET = 2;
private static final int LOCATION = 3;
private static final int GET_INFOS = 4;
private static final int SAVE_INFOS = 5;
public SecurePermissionStorage(PermissionStorage storage) {
this.storage = storage;
}
public String[] run() throws IOException {
switch (action) {
case GET :
return storage.getPermissionData(location);
case SET :
storage.setPermissionData(location, data);
return null;
case LOCATION :
return storage.getLocations();
case SAVE_INFOS :
storage.saveConditionalPermissionInfos(infos);
return null;
case GET_INFOS :
return storage.getConditionalPermissionInfos();
}
throw new UnsupportedOperationException();
}
public String[] getPermissionData(String loc) throws IOException {
this.location = loc;
this.action = GET;
try {
return AccessController.doPrivileged(this);
} catch (PrivilegedActionException e) {
throw (IOException) e.getException();
}
}
public String[] getLocations() throws IOException {
this.action = LOCATION;
try {
return AccessController.doPrivileged(this);
} catch (PrivilegedActionException e) {
throw (IOException) e.getException();
}
}
public void setPermissionData(String location, String[] data) throws IOException {
this.location = location;
this.data = data;
this.action = SET;
try {
AccessController.doPrivileged(this);
} catch (PrivilegedActionException e) {
throw (IOException) e.getException();
}
}
public void saveConditionalPermissionInfos(String[] updatedInfos) throws IOException {
this.action = SAVE_INFOS;
this.infos = updatedInfos;
try {
AccessController.doPrivileged(this);
} catch (PrivilegedActionException e) {
throw (IOException) e.getException();
}
}
public String[] getConditionalPermissionInfos() throws IOException {
this.action = GET_INFOS;
try {
return AccessController.doPrivileged(this);
} catch (PrivilegedActionException e) {
throw (IOException) e.getException();
}
}
}
|