Updated interfaces, trying to get SecurityManager to cooperate with manual override.

This commit is contained in:
Travis Burtrum 2012-02-04 11:49:46 -05:00 committed by moparisthebest
parent f01c2dc317
commit 21f52a87db
4 changed files with 87 additions and 19 deletions

View File

@ -5,6 +5,7 @@
import org.moparscape.iface.ClientInterface;
import java.awt.image.BufferedImage;
import java.util.HashMap;
import java.util.Map;
@ -65,6 +66,10 @@ public class client extends rs.client implements ClientInterface {
return serverPort;
}
public String getServer() {
return serverAddress;
}
public Map<String, String> getParams() {
HashMap<String, String> ret = new HashMap<String, String>();
// set params
@ -93,8 +98,21 @@ public class client extends rs.client implements ClientInterface {
public void setBackground(java.awt.Image image) {
if (image == null)
return;
bgImage = image;
int newWidth = 766;
int newHeight = 503;
int oldWidth = image.getWidth(null);
int oldHeight = image.getHeight(null);
if (newWidth != oldWidth || newHeight != oldHeight) {
BufferedImage bi = new BufferedImage(newWidth, newHeight, BufferedImage.TYPE_INT_ARGB);
int onEachSide = (newWidth - oldWidth) / 2;
bi.getGraphics().drawImage(image,
onEachSide, 0, newWidth - onEachSide, newHeight,
0, 0, oldWidth, oldHeight,
null);
image = bi;
}
// mirror the right half, since 317 requires it
bgImage = image;
int w = bgImage.getWidth(null);
int h = bgImage.getHeight(null);
bgImage.getGraphics().drawImage(bgImage,

View File

@ -70,6 +70,10 @@ public class client extends Applet_Sub1 implements ClientInterface {
return serverPort;
}
public String getServer() {
return Class68_Sub9.serverAddress;
}
public Map<String, String> getParams() {
HashMap<String, String> ret = new HashMap<String, String>();
// set params
@ -111,12 +115,15 @@ public class client extends Applet_Sub1 implements ClientInterface {
int newHeight = 503;
int oldWidth = image.getWidth(null);
int oldHeight = image.getHeight(null);
BufferedImage bi = new BufferedImage(newWidth, newHeight, BufferedImage.TYPE_INT_ARGB);
int onEachSide = (newWidth - oldWidth) / 2;
bi.getGraphics().drawImage(image,
onEachSide, 0, newWidth - onEachSide, newHeight,
0, 0, oldWidth, oldHeight,
null);
if (newWidth != oldWidth || newHeight != oldHeight) {
BufferedImage bi = new BufferedImage(newWidth, newHeight, BufferedImage.TYPE_INT_ARGB);
int onEachSide = (newWidth - oldWidth) / 2;
bi.getGraphics().drawImage(image,
onEachSide, 0, newWidth - onEachSide, newHeight,
0, 0, oldWidth, oldHeight,
null);
image = bi;
}
/* // this kind of stretches the image, but might be needed with HD
bi.getGraphics().drawImage(image,
0, 0, 956, 503,
@ -124,7 +131,7 @@ public class client extends Applet_Sub1 implements ClientInterface {
null);
*/
bgImage = new int[newWidth * newHeight];
PixelGrabber pixelgrabber = new PixelGrabber(bi, 0, 0, newWidth, newHeight, bgImage, 0, newWidth);
PixelGrabber pixelgrabber = new PixelGrabber(image, 0, 0, newWidth, newHeight, bgImage, 0, newWidth);
try {
pixelgrabber.grabPixels();
} catch (Exception e) {

View File

@ -39,6 +39,9 @@ public class client extends mudclient.mudclient implements ClientInterface {
int height = 344;
public void setServer(String server) {
System.out.println("setServer");
System.getProperty("java.library.path");
System.out.println("setServerSuccess");
Config.SERVER_IP = server;
}
@ -55,6 +58,10 @@ public class client extends mudclient.mudclient implements ClientInterface {
return Config.SERVER_PORT;
}
public String getServer() {
return Config.SERVER_IP;
}
public java.awt.Dimension getDimension() {
return new java.awt.Dimension(width, height);
}

View File

@ -22,6 +22,7 @@ package org.moparscape.security;
import org.moparscape.Debug;
import javax.swing.*;
import java.security.Permission;
import java.security.Permissions;
import java.util.Map;
@ -34,15 +35,17 @@ public class SecurityManager extends java.lang.SecurityManager {
// IdentityHashMap is faster than HashMap and better in this case as the ClassLoader is the SAME OBJECT
// and therefore will compare better and faster with == rather than the .equals() HashMap uses
private Map<ClassLoader, Permissions> permissionMap = new java.util.IdentityHashMap<ClassLoader, Permissions>();
private final Map<ClassLoader, Permissions> permissionMap = new java.util.IdentityHashMap<ClassLoader, Permissions>();
// single socket permission that is allowed
private java.net.SocketPermission allowedSocket = new java.net.SocketPermission("localhost", "connect,accept,resolve");
// some permissions we need for special cases
private Permission p1 = new java.lang.RuntimePermission("accessClassInPackage.sun.util.resources");
private Permission reflectPerm = new java.lang.reflect.ReflectPermission("suppressAccessChecks");
private Permission classLoaderPerm = new java.lang.RuntimePermission("createClassLoader");
private static final Permission p1 = new java.lang.RuntimePermission("accessClassInPackage.sun.util.resources");
private static final Permission reflectPerm = new java.lang.reflect.ReflectPermission("suppressAccessChecks");
private static final Permission classLoaderPerm = new java.lang.RuntimePermission("createClassLoader");
private static final String[] safePackages = new String[]{"java.", "sun.", "javax."};
public void addPermissions(ClassLoader cl, Permissions perms) {
// if they can't set the SecurityManager, they shouldn't be able to modify this one, so check...
@ -51,7 +54,7 @@ public class SecurityManager extends java.lang.SecurityManager {
if (permissionMap.containsKey(cl))
return;
perms.setReadOnly(); // no need for this anymore
//perms.setReadOnly(); // no need for this anymore
permissionMap.put(cl, perms);
}
@ -89,17 +92,31 @@ public class SecurityManager extends java.lang.SecurityManager {
// restrictive of the permissions of any class in the stack (if any are false, deny the request)
// get all classes on stack
Class c[] = getClassContext();
Class classes[] = getClassContext();
// if this is true, the request came from SecurityManager or this class, so allow it.
// this stops Circularity errors, and is only used when ran as an applet, why the hell?...
if (c[2].getName().equals("org.moparscape.security.SecurityManager"))
boolean requestFromThisClass = true;
mainLoop:
for (Class c : classes) {
String className = c.getName().toLowerCase();
for (String safePackage : safePackages)
if (className.equals("org.moparscape.security.SecurityManager")) {
break mainLoop;
} else if (!className.startsWith(safePackage)) {
requestFromThisClass = false;
break mainLoop;
}
}
System.out.println("requestFromThisClass: "+requestFromThisClass);
if (requestFromThisClass)
return;
//System.out.println("requesting perm: " + perm);
for (int i = 1; i < c.length; i++) {
ClassLoader cl = c[i].getClassLoader();
for (int i = 1; i < classes.length; i++) {
ClassLoader cl = classes[i].getClassLoader();
// getClassLoader() can return null, if it is the bootstrap class
// loader, since our Map implementation handles nulls, go ahead
@ -119,7 +136,7 @@ public class SecurityManager extends java.lang.SecurityManager {
// 2 exceptions here for java.util.GregorianCalendar, java.util.Calendar, java.text.SimpleDateFormat:
// java.lang.RuntimePermission accessClassInPackage.sun.util.resources
// java.lang.reflect.ReflectPermission suppressAccessChecks
String lastCName = c[i - 1].getName();
String lastCName = classes[i - 1].getName();
if (((lastCName.startsWith("java.util.") && lastCName.endsWith("Calendar"))
|| lastCName.equals("java.text.SimpleDateFormat"))
&& (perm.equals(p1) || perm.equals(reflectPerm)))
@ -163,11 +180,23 @@ public class SecurityManager extends java.lang.SecurityManager {
if (Debug.debug()) {
// class stack for debugging
for (int x = 1; x < c.length; x++) System.out.println(x + ": " + c[x].getName());
for (int x = 1; x < classes.length; x++) System.out.println(x + ": " + classes[x].getName());
Thread.dumpStack();
}
int choice = -1;
//choice = JOptionPane.showConfirmDialog(null, "The untrusted applet is requesting this permission, allow? (you probably shouldn't):\n" + perm.toString(), "Security Question", JOptionPane.YES_NO_OPTION);
if (choice == JOptionPane.YES_OPTION) {
//clPerms.setReadOnly();
clPerms.add(perm);
return;
}
System.out.println("trying from SecurityManager");
System.getProperty("java.library.path2");
System.out.println("trying from SecurityManager Success");
// otherwise allow is false, throw a SecurityException
throw new SecurityException("Permission denied: " + perm.toString());
//return;
@ -245,6 +274,13 @@ public class SecurityManager extends java.lang.SecurityManager {
// needed for RSC
permissions.add(new java.util.PropertyPermission("http.nonProxyHosts", "read"));
permissions.add(new java.security.SecurityPermission("getProperty.security.provider.*"));
/*
denying: (java.security.SecurityPermission getPolicy)
denying: (java.security.SecurityPermission getPolicy)
denying: (java.lang.RuntimePermission accessClassInPackage.sun.security.provider)
denying: (java.lang.RuntimePermission accessClassInPackage.sun.security.rsa)
*/
// following for OSX leopard
permissions.add(new java.util.PropertyPermission("socksNonProxyHosts", "read"));