home *** CD-ROM | disk | FTP | other *** search
- package sun.applet;
-
- import java.io.File;
- import java.io.FileDescriptor;
- import java.net.InetAddress;
- import java.net.URL;
- import java.net.UnknownHostException;
- import java.util.StringTokenizer;
- import java.util.Vector;
-
- public class AppletSecurity extends SecurityManager {
- private static boolean debug;
- boolean initACL;
- String[] readACL;
- String[] writeACL;
- int networkMode;
- static final int NETWORK_NONE = 1;
- static final int NETWORK_HOST = 2;
- static final int NETWORK_UNRESTRICTED = 3;
-
- public void checkRead(String var1, Object var2) {
- this.checkRead(var1);
- if (var2 != null) {
- this.checkRead(var1, (URL)var2);
- }
-
- }
-
- public void checkDelete(String var1) {
- if (this.inApplet()) {
- throw new AppletSecurityException("file.delete", var1);
- }
- }
-
- public synchronized void checkExec(String var1) {
- if (this.inApplet()) {
- throw new AppletSecurityException("exec", var1);
- }
- }
-
- public AppletSecurity() {
- this.reset();
- }
-
- public synchronized void checkAccept(String var1, int var2) {
- if (this.inApplet()) {
- throw new AppletSecurityException("socket.accept", var1 + ":" + var2);
- }
- }
-
- public synchronized void checkSetFactory() {
- throw new SecurityException();
- }
-
- public synchronized void checkPackageDefinition(String var1) {
- for(int var2 = var1.indexOf(46); var2 > 0; var2 = var1.indexOf(46, var2 + 1)) {
- String var3 = var1.substring(0, var2);
- if (Boolean.getBoolean("package.restrict.definition." + var3)) {
- throw new SecurityException();
- }
- }
-
- if (Boolean.getBoolean("package.restrict.definition." + var1)) {
- throw new SecurityException();
- }
- }
-
- public synchronized void checkLink(String var1) {
- switch (((SecurityManager)this).classLoaderDepth()) {
- case 2:
- case 3:
- throw new AppletSecurityException("link", var1);
- default:
- }
- }
-
- public synchronized void checkCreateClassLoader() {
- if (((SecurityManager)this).classLoaderDepth() == 2) {
- throw new AppletSecurityException("classloader");
- }
- }
-
- public synchronized void checkAccess(Thread var1) {
- if (((SecurityManager)this).classLoaderDepth() == 2 && !(var1.getThreadGroup() instanceof AppletThreadGroup)) {
- throw new AppletSecurityException("thread");
- }
- }
-
- public synchronized void checkAccess(ThreadGroup var1) {
- if (((SecurityManager)this).classLoaderDepth() == 4 && !(var1 instanceof AppletThreadGroup)) {
- throw new AppletSecurityException("threadgroup", var1.toString());
- }
- }
-
- public synchronized void checkPropertiesAccess() {
- if (((SecurityManager)this).classLoaderDepth() == 2) {
- throw new AppletSecurityException("properties");
- }
- }
-
- public synchronized void checkWrite(String var1) {
- if (this.inApplet()) {
- if (!this.initACL) {
- this.initializeACLs();
- }
-
- if (this.writeACL != null) {
- int var2 = this.writeACL.length;
-
- while(var2-- > 0) {
- if (var1.startsWith(this.writeACL[var2])) {
- return;
- }
- }
-
- throw new AppletSecurityException("file.write", var1);
- }
- }
- }
-
- public synchronized void checkWrite(FileDescriptor var1) {
- if (this.inApplet() && !((SecurityManager)this).inClass("java.net.SocketOutputStream") || !var1.valid()) {
- throw new AppletSecurityException("fd.write");
- }
- }
-
- public synchronized void checkListen(int var1) {
- if (this.inApplet()) {
- throw new AppletSecurityException("socket.listen", String.valueOf(var1));
- }
- }
-
- boolean inApplet() {
- return ((SecurityManager)this).inClassLoader();
- }
-
- public synchronized void checkExit(int var1) {
- if (this.inApplet()) {
- throw new AppletSecurityException("exit", String.valueOf(var1));
- }
- }
-
- boolean fromApplet() {
- return ((SecurityManager)this).classLoaderDepth() == 1;
- }
-
- public synchronized void checkConnect(String var1, int var2) {
- AppletClassLoader var3 = (AppletClassLoader)((SecurityManager)this).currentClassLoader();
- if (var3 != null) {
- int var4 = ((SecurityManager)this).classDepth("sun.net.www.http.HttpClient");
- if (var4 <= 1) {
- this.checkConnect(var3.base.getHost(), var1);
- }
- }
- }
-
- public void checkConnect(String var1, int var2, Object var3) {
- this.checkConnect(var1, var2);
- if (var3 != null) {
- this.checkConnect(((URL)var3).getHost(), var1);
- }
-
- }
-
- public synchronized void checkConnect(String var1, String var2, boolean var3) {
- if (var1 != null) {
- switch (this.networkMode) {
- case 1:
- throw new AppletSecurityException("socket.connect", var1 + "->" + var2);
- case 2:
- try {
- super.inCheck = true;
- if (var1.equals(var2)) {
- try {
- InetAddress var14 = InetAddress.getByName(var2);
- return;
- } catch (UnknownHostException var12) {
- if (!var3) {
- throw new AppletSecurityException("Could not resolve IP for host " + var2 + ". See the trustProxy property.");
- }
-
- return;
- }
- }
-
- try {
- InetAddress var4 = InetAddress.getByName(var2);
- InetAddress var5 = InetAddress.getByName(var1);
- if (!var5.equals(var4)) {
- throw new AppletSecurityException("Couldn't connect to " + var2 + " with origin from " + var1);
- }
- } catch (UnknownHostException var11) {
- throw new AppletSecurityException("Couldn't resolve IP for host " + var2 + " or for " + var1 + ".");
- }
- } finally {
- super.inCheck = false;
- }
-
- return;
- case 3:
- return;
- default:
- throw new AppletSecurityException("connect", var1 + "->" + var2);
- }
- }
- }
-
- public synchronized void checkConnect(String var1, String var2) {
- this.checkConnect(var1, var2, Boolean.getBoolean("trustProxy"));
- }
-
- public synchronized void checkPackageAccess(String var1) {
- for(int var2 = var1.indexOf(46); var2 > 0; var2 = var1.indexOf(46, var2 + 1)) {
- String var3 = var1.substring(0, var2);
- if (((SecurityManager)this).inClassLoader() && Boolean.getBoolean("package.restrict.access." + var3)) {
- throw new SecurityException();
- }
- }
-
- if (((SecurityManager)this).inClassLoader() && Boolean.getBoolean("package.restrict.access." + var1)) {
- throw new SecurityException();
- }
- }
-
- public synchronized void checkFileDialog() {
- if (this.inApplet()) {
- throw new AppletSecurityException("filedialog");
- }
- }
-
- void initializeACLs() {
- this.readACL = this.parseACL(System.getProperty("acl.read"), System.getProperty("acl.read.default"));
- this.writeACL = this.parseACL(System.getProperty("acl.write"), System.getProperty("acl.write.default"));
- this.initACL = true;
- }
-
- void parseACL(Vector var1, String var2, String var3) {
- StringTokenizer var4 = new StringTokenizer(var2, System.getProperty("path.separator"));
-
- while(var4.hasMoreTokens()) {
- String var5 = var4.nextToken();
- if (var5.startsWith("~")) {
- var1.addElement(System.getProperty("user.home") + var5.substring(1));
- } else if (var5.equals("+")) {
- if (var3 != null) {
- this.parseACL(var1, var3, (String)null);
- }
- } else {
- var1.addElement(var5);
- }
- }
-
- }
-
- String[] parseACL(String var1, String var2) {
- if (var1 == null) {
- return new String[0];
- } else if (var1.equals("*")) {
- return null;
- } else {
- Vector var3 = new Vector();
- this.parseACL(var3, var1, var2);
- String[] var4 = new String[var3.size()];
- var3.copyInto(var4);
- return var4;
- }
- }
-
- public Object getSecurityContext() {
- AppletClassLoader var1 = (AppletClassLoader)((SecurityManager)this).currentClassLoader();
- return var1 == null ? null : var1.base;
- }
-
- public void debug(String var1) {
- if (debug) {
- System.err.println(var1);
- }
-
- }
-
- public synchronized void checkPropertyAccess(String var1) {
- if (((SecurityManager)this).classLoaderDepth() == 2 && !"true".equalsIgnoreCase(System.getProperty(var1 + ".applet"))) {
- throw new AppletSecurityException("properties");
- }
- }
-
- public synchronized boolean checkTopLevelWindow(Object var1) {
- return !((SecurityManager)this).inClassLoader();
- }
-
- public synchronized void checkRead(FileDescriptor var1) {
- if (this.inApplet() && !((SecurityManager)this).inClass("java.net.SocketInputStream") || !var1.valid()) {
- throw new AppletSecurityException("fd.read");
- }
- }
-
- public void reset() {
- String var1 = System.getProperty("appletviewer.security.mode");
- if (var1 == null) {
- var1 = "host";
- }
-
- if (var1.equals("unrestricted")) {
- this.networkMode = 3;
- } else if (var1.equals("none")) {
- this.networkMode = 1;
- } else {
- this.networkMode = 2;
- }
-
- }
-
- public synchronized void checkRead(String var1) {
- AppletClassLoader var2 = (AppletClassLoader)((SecurityManager)this).currentClassLoader();
- if (var2 != null) {
- this.checkRead(var1, var2.base);
- }
-
- }
-
- public synchronized void checkRead(String var1, URL var2) {
- if (var2 != null) {
- if (!this.initACL) {
- this.initializeACLs();
- }
-
- if (this.readACL != null) {
- int var3 = this.readACL.length;
-
- while(var3-- > 0) {
- if (var1.startsWith(this.readACL[var3])) {
- return;
- }
- }
-
- if (var2.getProtocol().equals("file")) {
- String var5 = var2.getFile().replace('/', File.separatorChar);
- if (var1.replace('/', File.separatorChar).startsWith(var5)) {
- return;
- }
- }
-
- throw new AppletSecurityException("file.read", var1);
- }
- }
- }
- }
-