use of java.net.SocketPermission in project rt.equinox.framework by eclipse.
the class SecurityAdminUnitTests method testLocationPermission03.
public void testLocationPermission03() {
Bundle test = installTestBundle(TEST_BUNDLE);
AccessControlContext acc = test.adapt(AccessControlContext.class);
pa.setDefaultPermissions(READONLY_INFOS);
pa.setPermissions(test.getLocation(), READWRITE_INFOS);
ConditionalPermissionInfo condPermInfo = cpa.addConditionalPermissionInfo(ALLLOCATION_CONDS, SOCKET_INFOS);
// $NON-NLS-1$ //$NON-NLS-2$
testPermission(acc, new FilePermission("test", "write"), true);
// $NON-NLS-1$ //$NON-NLS-2$
testPermission(acc, new FilePermission("test", "read"), true);
testPermission(acc, new AllPermission(), false);
// $NON-NLS-1$ //$NON-NLS-2$
testPermission(acc, new SocketPermission("localhost", "accept"), false);
pa.setPermissions(test.getLocation(), null);
// $NON-NLS-1$ //$NON-NLS-2$
testPermission(acc, new FilePermission("test", "write"), false);
// $NON-NLS-1$ //$NON-NLS-2$
testPermission(acc, new FilePermission("test", "read"), false);
testPermission(acc, new AllPermission(), false);
// $NON-NLS-1$ //$NON-NLS-2$
testPermission(acc, new SocketPermission("localhost", "accept"), true);
condPermInfo.delete();
// $NON-NLS-1$ //$NON-NLS-2$
testPermission(acc, new FilePermission("test", "write"), false);
// $NON-NLS-1$ //$NON-NLS-2$
testPermission(acc, new FilePermission("test", "read"), true);
testPermission(acc, new AllPermission(), false);
// $NON-NLS-1$ //$NON-NLS-2$
testPermission(acc, new SocketPermission("localhost", "accept"), false);
pa.setDefaultPermissions(null);
// $NON-NLS-1$ //$NON-NLS-2$
testPermission(acc, new FilePermission("test", "write"), true);
// $NON-NLS-1$ //$NON-NLS-2$
testPermission(acc, new FilePermission("test", "read"), true);
testPermission(acc, new AllPermission(), true);
// $NON-NLS-1$ //$NON-NLS-2$
testPermission(acc, new SocketPermission("localhost", "accept"), true);
}
use of java.net.SocketPermission in project rt.equinox.framework by eclipse.
the class SecurityAdminUnitTests method testDefaultPermissions02.
public void testDefaultPermissions02() {
Bundle test = installTestBundle(TEST_BUNDLE);
AccessControlContext acc = test.adapt(AccessControlContext.class);
pa.setDefaultPermissions(READONLY_INFOS);
pa.setPermissions(test.getLocation(), SOCKET_INFOS);
// $NON-NLS-1$ //$NON-NLS-2$
testPermission(acc, new FilePermission("test", "write"), false);
// $NON-NLS-1$ //$NON-NLS-2$
testPermission(acc, new FilePermission("test", "read"), false);
testPermission(acc, new AllPermission(), false);
// $NON-NLS-1$ //$NON-NLS-2$
testPermission(acc, new SocketPermission("localhost", "accept"), true);
pa.setPermissions(test.getLocation(), null);
// $NON-NLS-1$ //$NON-NLS-2$
testPermission(acc, new FilePermission("test", "write"), false);
// $NON-NLS-1$ //$NON-NLS-2$
testPermission(acc, new FilePermission("test", "read"), true);
testPermission(acc, new AllPermission(), false);
// $NON-NLS-1$ //$NON-NLS-2$
testPermission(acc, new SocketPermission("localhost", "accept"), false);
pa.setDefaultPermissions(null);
// $NON-NLS-1$ //$NON-NLS-2$
testPermission(acc, new FilePermission("test", "write"), true);
// $NON-NLS-1$ //$NON-NLS-2$
testPermission(acc, new FilePermission("test", "read"), true);
testPermission(acc, new AllPermission(), true);
}
use of java.net.SocketPermission in project rt.equinox.framework by eclipse.
the class SecurityAdminUnitTests method testMultipleLocationConditions01.
public void testMultipleLocationConditions01() {
Bundle test = installTestBundle(TEST_BUNDLE);
AccessControlContext acc = test.adapt(AccessControlContext.class);
// $NON-NLS-1$
ConditionalPermissionInfo condPermInfo1 = cpa.addConditionalPermissionInfo(getLocationConditions("xxx", false), SOCKET_INFOS);
ConditionalPermissionInfo condPermInfo2 = cpa.addConditionalPermissionInfo(ALLLOCATION_CONDS, READONLY_INFOS);
// $NON-NLS-1$ //$NON-NLS-2$
testPermission(acc, new SocketPermission("localhost", "accept"), false);
// $NON-NLS-1$ //$NON-NLS-2$
testPermission(acc, new FilePermission("test", "write"), false);
// $NON-NLS-1$ //$NON-NLS-2$
testPermission(acc, new FilePermission("test", "read"), true);
condPermInfo1.delete();
// $NON-NLS-1$ //$NON-NLS-2$
testPermission(acc, new SocketPermission("localhost", "accept"), false);
// $NON-NLS-1$ //$NON-NLS-2$
testPermission(acc, new FilePermission("test", "write"), false);
// $NON-NLS-1$ //$NON-NLS-2$
testPermission(acc, new FilePermission("test", "read"), true);
condPermInfo2.delete();
// $NON-NLS-1$ //$NON-NLS-2$
testPermission(acc, new SocketPermission("localhost", "accept"), true);
// $NON-NLS-1$ //$NON-NLS-2$
testPermission(acc, new FilePermission("test", "write"), true);
// $NON-NLS-1$ //$NON-NLS-2$
testPermission(acc, new FilePermission("test", "read"), true);
}
use of java.net.SocketPermission in project Bytecoder by mirkosertic.
the class EmptyInputStream method URLtoSocketPermission.
/**
* if the caller has a URLPermission for connecting to the
* given URL, then return a SocketPermission which permits
* access to that destination. Return null otherwise. The permission
* is cached in a field (which can only be changed by redirects)
*/
SocketPermission URLtoSocketPermission(URL url) throws IOException {
if (socketPermission != null) {
return socketPermission;
}
SecurityManager sm = System.getSecurityManager();
if (sm == null) {
return null;
}
// the permission, which we might grant
SocketPermission newPerm = new SocketPermission(getHostAndPort(url), "connect");
String actions = getRequestMethod() + ":" + getUserSetHeaders().getHeaderNamesInList();
String urlstring = url.getProtocol() + "://" + url.getAuthority() + url.getPath();
URLPermission p = new URLPermission(urlstring, actions);
try {
sm.checkPermission(p);
socketPermission = newPerm;
return socketPermission;
} catch (SecurityException e) {
// fall thru
}
return null;
}
use of java.net.SocketPermission in project Bytecoder by mirkosertic.
the class FtpURLConnection method getPermission.
/**
* Gets the {@code Permission} associated with the host and port.
*
* @return The {@code Permission} object.
*/
@Override
public Permission getPermission() {
if (permission == null) {
int urlport = url.getPort();
urlport = urlport < 0 ? FtpClient.defaultPort() : urlport;
String urlhost = this.host + ":" + urlport;
permission = new SocketPermission(urlhost, "connect");
}
return permission;
}
Aggregations