diff options
author | Jens-Heiner Rechtien <hr@openoffice.org> | 2000-09-18 16:24:28 +0000 |
---|---|---|
committer | Jens-Heiner Rechtien <hr@openoffice.org> | 2000-09-18 16:24:28 +0000 |
commit | 483889728b5b821195da00b280df837de0f0e27c (patch) | |
tree | 4032490ddd4cb07b58d02f041a3034a23835ebdf /sandbox/com/sun/star | |
parent | fd069bee7e57ad529c3c0974559fd2d84ec3151a (diff) |
initial import
Diffstat (limited to 'sandbox/com/sun/star')
28 files changed, 4650 insertions, 0 deletions
diff --git a/sandbox/com/sun/star/lib/sandbox/AudioProxy.java b/sandbox/com/sun/star/lib/sandbox/AudioProxy.java new file mode 100644 index 000000000000..341de07143ad --- /dev/null +++ b/sandbox/com/sun/star/lib/sandbox/AudioProxy.java @@ -0,0 +1,105 @@ +/************************************************************************* + * + * $RCSfile: AudioProxy.java,v $ + * + * $Revision: 1.1.1.1 $ + * + * last change: $Author: hr $ $Date: 2000-09-18 17:24:28 $ + * + * The Contents of this file are made available subject to the terms of + * either of the following licenses + * + * - GNU Lesser General Public License Version 2.1 + * - Sun Industry Standards Source License Version 1.1 + * + * Sun Microsystems Inc., October, 2000 + * + * GNU Lesser General Public License Version 2.1 + * ============================================= + * Copyright 2000 by Sun Microsystems, Inc. + * 901 San Antonio Road, Palo Alto, CA 94303, USA + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software Foundation. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, + * MA 02111-1307 USA + * + * + * Sun Industry Standards Source License Version 1.1 + * ================================================= + * The contents of this file are subject to the Sun Industry Standards + * Source License Version 1.1 (the "License"); You may not use this file + * except in compliance with the License. You may obtain a copy of the + * License at http://www.openoffice.org/license.html. + * + * Software provided under this License is provided on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, + * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS, + * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. + * See the License for the specific provisions governing your rights and + * obligations concerning the Software. + * + * The Initial Developer of the Original Code is: Sun Microsystems, Inc. + * + * Copyright: 2000 by Sun Microsystems, Inc. + * + * All Rights Reserved. + * + * Contributor(s): _______________________________________ + * + * + ************************************************************************/ + +package com.sun.star.lib.sandbox; + +import java.applet.AudioClip; + +import java.util.Vector; + +class AudioProxy implements AudioClip, Holder { + private static final boolean DEBUG = false; + private static int instances; + + private AudioClip audioClip; + private Vector cargo = new Vector(); + + AudioProxy(AudioClip audioClip) { + this.audioClip = audioClip; + instances ++; + } + + public void play() { + audioClip.play(); + } + + public void loop() { + audioClip.loop(); + } + + public void stop() { + audioClip.stop(); + } + + public void addCargo(Object object) { + cargo.addElement(object); + } + + public void removeCargo(Object object) { + cargo.removeElement(object); + } + + public void finalize() { + if(DEBUG) System.err.println("#### AudioProxy.finalize"); + instances --; + } +} + diff --git a/sandbox/com/sun/star/lib/sandbox/Cachable.java b/sandbox/com/sun/star/lib/sandbox/Cachable.java new file mode 100644 index 000000000000..89c2035f0dda --- /dev/null +++ b/sandbox/com/sun/star/lib/sandbox/Cachable.java @@ -0,0 +1,68 @@ +/************************************************************************* + * + * $RCSfile: Cachable.java,v $ + * + * $Revision: 1.1.1.1 $ + * + * last change: $Author: hr $ $Date: 2000-09-18 17:24:28 $ + * + * The Contents of this file are made available subject to the terms of + * either of the following licenses + * + * - GNU Lesser General Public License Version 2.1 + * - Sun Industry Standards Source License Version 1.1 + * + * Sun Microsystems Inc., October, 2000 + * + * GNU Lesser General Public License Version 2.1 + * ============================================= + * Copyright 2000 by Sun Microsystems, Inc. + * 901 San Antonio Road, Palo Alto, CA 94303, USA + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software Foundation. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, + * MA 02111-1307 USA + * + * + * Sun Industry Standards Source License Version 1.1 + * ================================================= + * The contents of this file are subject to the Sun Industry Standards + * Source License Version 1.1 (the "License"); You may not use this file + * except in compliance with the License. You may obtain a copy of the + * License at http://www.openoffice.org/license.html. + * + * Software provided under this License is provided on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, + * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS, + * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. + * See the License for the specific provisions governing your rights and + * obligations concerning the Software. + * + * The Initial Developer of the Original Code is: Sun Microsystems, Inc. + * + * Copyright: 2000 by Sun Microsystems, Inc. + * + * All Rights Reserved. + * + * Contributor(s): _______________________________________ + * + * + ************************************************************************/ + +package com.sun.star.lib.sandbox; + +public interface Cachable { + Object getHardObject(); + void setWeakRef(WeakRef weakRef); +} + diff --git a/sandbox/com/sun/star/lib/sandbox/ClassContext.java b/sandbox/com/sun/star/lib/sandbox/ClassContext.java new file mode 100644 index 000000000000..5791e9166546 --- /dev/null +++ b/sandbox/com/sun/star/lib/sandbox/ClassContext.java @@ -0,0 +1,87 @@ +/************************************************************************* + * + * $RCSfile: ClassContext.java,v $ + * + * $Revision: 1.1.1.1 $ + * + * last change: $Author: hr $ $Date: 2000-09-18 17:24:28 $ + * + * The Contents of this file are made available subject to the terms of + * either of the following licenses + * + * - GNU Lesser General Public License Version 2.1 + * - Sun Industry Standards Source License Version 1.1 + * + * Sun Microsystems Inc., October, 2000 + * + * GNU Lesser General Public License Version 2.1 + * ============================================= + * Copyright 2000 by Sun Microsystems, Inc. + * 901 San Antonio Road, Palo Alto, CA 94303, USA + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software Foundation. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, + * MA 02111-1307 USA + * + * + * Sun Industry Standards Source License Version 1.1 + * ================================================= + * The contents of this file are subject to the Sun Industry Standards + * Source License Version 1.1 (the "License"); You may not use this file + * except in compliance with the License. You may obtain a copy of the + * License at http://www.openoffice.org/license.html. + * + * Software provided under this License is provided on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, + * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS, + * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. + * See the License for the specific provisions governing your rights and + * obligations concerning the Software. + * + * The Initial Developer of the Original Code is: Sun Microsystems, Inc. + * + * Copyright: 2000 by Sun Microsystems, Inc. + * + * All Rights Reserved. + * + * Contributor(s): _______________________________________ + * + * + ************************************************************************/ + +package com.sun.star.lib.sandbox; + +import java.io.InputStream; + +import java.net.URL; + +public interface ClassContext { + public URL getBase(); + + public boolean hasThreadGroup(); + + public ThreadGroup getThreadGroup(); + + public InputStream getResourceAsStream(String name); + + public URL getResource(String name); + + public Class findClass(String className) throws ClassNotFoundException; + + public Class loadClass(String className) throws ClassNotFoundException; + + public void dispose(); + + public ClassLoader getClassLoader(); +} + diff --git a/sandbox/com/sun/star/lib/sandbox/ClassContextImpl.java b/sandbox/com/sun/star/lib/sandbox/ClassContextImpl.java new file mode 100644 index 000000000000..0674c0a0a1a8 --- /dev/null +++ b/sandbox/com/sun/star/lib/sandbox/ClassContextImpl.java @@ -0,0 +1,293 @@ +/************************************************************************* + * + * $RCSfile: ClassContextImpl.java,v $ + * + * $Revision: 1.1.1.1 $ + * + * last change: $Author: hr $ $Date: 2000-09-18 17:24:28 $ + * + * The Contents of this file are made available subject to the terms of + * either of the following licenses + * + * - GNU Lesser General Public License Version 2.1 + * - Sun Industry Standards Source License Version 1.1 + * + * Sun Microsystems Inc., October, 2000 + * + * GNU Lesser General Public License Version 2.1 + * ============================================= + * Copyright 2000 by Sun Microsystems, Inc. + * 901 San Antonio Road, Palo Alto, CA 94303, USA + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software Foundation. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, + * MA 02111-1307 USA + * + * + * Sun Industry Standards Source License Version 1.1 + * ================================================= + * The contents of this file are subject to the Sun Industry Standards + * Source License Version 1.1 (the "License"); You may not use this file + * except in compliance with the License. You may obtain a copy of the + * License at http://www.openoffice.org/license.html. + * + * Software provided under this License is provided on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, + * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS, + * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. + * See the License for the specific provisions governing your rights and + * obligations concerning the Software. + * + * The Initial Developer of the Original Code is: Sun Microsystems, Inc. + * + * Copyright: 2000 by Sun Microsystems, Inc. + * + * All Rights Reserved. + * + * Contributor(s): _______________________________________ + * + * + ************************************************************************/ + +package com.sun.star.lib.sandbox; + +import java.awt.Toolkit; +import java.awt.Image; + +import java.io.IOException; +import java.io.InputStream; +import java.io.BufferedInputStream; +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; + +import java.net.URL; +import java.net.URLConnection; +import java.net.MalformedURLException; + +import java.util.Hashtable; + +import java.util.zip.ZipEntry; + +import sun.tools.jar.JarVerifierStream; + +final class ClassContextImpl extends ClassLoader implements ClassContext { + private static int instances; + private static final boolean DEBUG = false; + + private URL codeBase; + private ProtectionDomain protectionDomain; + private boolean _bSecure; + + // HACKHACK!!!: java.lang.Thread fragt bei erzeugen eines Threads den + // HACKHACK!!!: SECURITYMANAGER nach der THREADGROUP + private ThreadGroup threadGroup; + + public ClassContextImpl(URL codeBase, ProtectionDomain protectionDomain, ThreadGroup threadGroup, boolean bSecure) { + this(codeBase, protectionDomain, threadGroup); + + _bSecure = bSecure; + } + + public ClassContextImpl(URL codeBase, ProtectionDomain protectionDomain, ThreadGroup threadGroup) { + if(DEBUG)System.err.println("#### ClassContextImpl.<init>:" + codeBase + " " + protectionDomain + " " + threadGroup); + + instances ++; + + this.codeBase = codeBase; + this.protectionDomain = protectionDomain; + this.threadGroup = threadGroup; + } + + public void finalize() { + instances --; + } + + public URL getBase() { + return codeBase; + } + + public boolean hasThreadGroup() { + return threadGroup != null && !threadGroup.isDestroyed(); + } + + public synchronized ThreadGroup getThreadGroup() { + if(threadGroup == null || threadGroup.isDestroyed()) { + threadGroup = new ThreadGroup(codeBase.toString()); + threadGroup.setDaemon(true); + } + + return threadGroup; + } + + boolean checkSecurity() { + return !_bSecure; + } + + public InputStream getResourceAsStream(String name) { + if(DEBUG) System.err.println("#### ClassContext.getResourceAsStream:" + name); + + InputStream inputStream = getSystemResourceAsStream(name); + if(inputStream == null) { + try { + URL url = new URL(codeBase, name); + if(ResourceProxy.isResource(url)) { // VALID URL? + ResourceProxy resourceProxy = ResourceProxy.load(url, protectionDomain); + inputStream = resourceProxy.getInputStream(); + } + } + catch(MalformedURLException me) { + } + catch(IOException ioe) { + } + } + + return inputStream; + } + + public URL getResource(String name) { + if(DEBUG) System.err.println("#### ClassContext.getResource:" + name); + + URL url = getSystemResource(name); + if(url == null) { + try { + url = new URL(codeBase, name); + if(!ResourceProxy.isResource(url)) // VALID URL? + url = null; + else + url = new URL("appletresource:" + codeBase + "/+/" + name); + } + catch(MalformedURLException malformedURLException) { + if(DEBUG) System.err.println("#### ClassContext.getResource - exception: " + malformedURLException); + } + } + + return url; + } + + public Class findClass(String className) throws ClassNotFoundException { + Class xClass = findLoadedClass(className); + if(xClass == null) + xClass = findSystemClass(className); + + return xClass; + } + + public Class loadClass(String className) throws ClassNotFoundException { + return loadClass(className, true); + } + + synchronized protected Class loadClass(String className, boolean resolve) throws ClassNotFoundException { + if(DEBUG) System.err.println("#### ClassContext.loadClass:" + className + " " + resolve); + + // ???SECURITY???? + SecurityManager security = System.getSecurityManager(); + if(security != null) { + int i = className.lastIndexOf('.'); + if(i >= 0) + security.checkPackageAccess(className.substring(0, i)); + } + + + Class xClass = null; + + try { + xClass = findClass(className); + } + catch(ClassNotFoundException e) { + try { + ResourceProxy resourceProxy = + ResourceProxy.load(new URL(codeBase, className.replace('.', '/') + ".class"), protectionDomain); + + byte bytes[] = resourceProxy.getBytes(); + // if(DEBUG) printHeader(bytes); + + xClass = defineClass(className, bytes, 0, bytes.length); + // xClass = defineClass(className, bytes, 0, bytes.length, protectionDomain); + + Object objects[] = new Object[2]; + objects[0] = resourceProxy.getProtectionDomain(); + setSigners(xClass, objects); + } + catch(MalformedURLException malformedURLException) { + if(DEBUG) System.err.println("#### ClassContext.loadClasss - URL exception:" + malformedURLException); + throw new ClassNotFoundException("ClassContext.loadClass - MalformedURLException:" + + " " + malformedURLException + + " " + className + + " " + codeBase); + } + catch(IOException iOException) { + if(DEBUG) System.err.println("#### ClassContext.loadClasss - IO exception:" + iOException); + throw new ClassNotFoundException("ClassContext.loadClass - IOException:" + + " " + iOException + + " " + className + + " " + codeBase); + } + catch(ClassFormatError classFormatError) { + if(DEBUG) System.err.println("#### ClassContext.loadClass - ClassFormat exception:" + classFormatError); + throw new ClassNotFoundException("ClassContext.loadClass - ClassFormatError:" + + " " + classFormatError + + " " + className + + " " + codeBase); + } + } + if (xClass != null && resolve) + resolveClass(xClass); + + return xClass; + } + + static class ThreadGroupKiller implements Runnable { + ThreadGroup threadGroup = null; + + ThreadGroupKiller(ThreadGroup threadGroup) { + this.threadGroup = threadGroup; + } + + public void run() { + try { + System.err.println("#### ClassContext - killerThread start"); + threadGroup.stop(); + threadGroup.destroy(); + System.err.println("#### ClassContext - killerThread succeeded"); + } + catch(Exception exception) { + System.err.println("ClassContext.dispose:" + exception); + } + } + }; + + synchronized public void dispose() { + if(DEBUG)System.err.println("#### ClassContext.dispose:" + threadGroup); + + if(threadGroup != null) { + threadGroup.list(); + + new Thread(new ThreadGroupKiller(threadGroup), codeBase.toString() + " killer thread").start(); + + threadGroup = null; + } + } + + private void printHeader(byte bytes[]) { + System.err.print("#### ClassContext.loadClass - bytes header:"); + for(int x =0 ; x < 4; x++) { + System.err.print(" " + Integer.toHexString(((int)bytes[x]) & 0xff)); + } + System.err.println(); + } + + public ClassLoader getClassLoader() { + return this; + } +} + diff --git a/sandbox/com/sun/star/lib/sandbox/ClassContextProxy.java b/sandbox/com/sun/star/lib/sandbox/ClassContextProxy.java new file mode 100644 index 000000000000..dcfa03e04cba --- /dev/null +++ b/sandbox/com/sun/star/lib/sandbox/ClassContextProxy.java @@ -0,0 +1,182 @@ +/************************************************************************* + * + * $RCSfile: ClassContextProxy.java,v $ + * + * $Revision: 1.1.1.1 $ + * + * last change: $Author: hr $ $Date: 2000-09-18 17:24:28 $ + * + * The Contents of this file are made available subject to the terms of + * either of the following licenses + * + * - GNU Lesser General Public License Version 2.1 + * - Sun Industry Standards Source License Version 1.1 + * + * Sun Microsystems Inc., October, 2000 + * + * GNU Lesser General Public License Version 2.1 + * ============================================= + * Copyright 2000 by Sun Microsystems, Inc. + * 901 San Antonio Road, Palo Alto, CA 94303, USA + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software Foundation. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, + * MA 02111-1307 USA + * + * + * Sun Industry Standards Source License Version 1.1 + * ================================================= + * The contents of this file are subject to the Sun Industry Standards + * Source License Version 1.1 (the "License"); You may not use this file + * except in compliance with the License. You may obtain a copy of the + * License at http://www.openoffice.org/license.html. + * + * Software provided under this License is provided on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, + * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS, + * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. + * See the License for the specific provisions governing your rights and + * obligations concerning the Software. + * + * The Initial Developer of the Original Code is: Sun Microsystems, Inc. + * + * Copyright: 2000 by Sun Microsystems, Inc. + * + * All Rights Reserved. + * + * Contributor(s): _______________________________________ + * + * + ************************************************************************/ + +package com.sun.star.lib.sandbox; + +import java.awt.Toolkit; +import java.awt.Image; + +import java.io.IOException; +import java.io.InputStream; +import java.io.BufferedInputStream; +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; + +import java.net.URL; +import java.net.URLConnection; +import java.net.MalformedURLException; + +import java.util.Hashtable; +import java.util.zip.ZipEntry; + +import sun.tools.jar.JarVerifierStream; + + +public final class ClassContextProxy implements ClassContext, Cachable { + private static int instances; + private static final boolean DEBUG = false; + + /* + ** interface cachable methods + */ + private ClassContext classContext; + private WeakRef weakRef; + + public ClassContextProxy() { + instances ++; + } + + public Object getHardObject() { + return classContext; + } + + public void setWeakRef(WeakRef weakRef) { + classContext = (ClassContext)weakRef.getRef(); + base = classContext.getBase(); + + this.weakRef = weakRef; + weakRef.incRefCnt(); + } + + public void finalize() { + weakRef.decRefCnt(); + + instances --; + } + + /* + ** ClassContext methods + */ + private URL base; + + + public static ClassContext create(URL base, ProtectionDomain protectionDomain, ThreadGroup threadGroup) { + return create(base, protectionDomain, threadGroup, false); + } + + public static ClassContext create(URL base, ProtectionDomain protectionDomain, ThreadGroup threadGroup, boolean bSecure) { + Object object = WeakTable.get("ClassContxt: " + base); + if(DEBUG) System.err.println("#### ClassContextProxy.create:" + object); + ClassContextProxy classContextProxy = (ClassContextProxy)object; + + if(classContextProxy == null) { + classContextProxy = new ClassContextProxy(base, protectionDomain, threadGroup, bSecure); + WeakTable.put("ClassContxt: " + base, classContextProxy); + } + + return classContextProxy; + } + + private ClassContextProxy(URL base, ProtectionDomain protectionDomain, ThreadGroup threadGroup, boolean bSecure) { + this(); + + this.base = base; + + classContext = new ClassContextImpl(base, protectionDomain, threadGroup, bSecure); + } + + public ClassLoader getClassLoader() { + return classContext.getClassLoader(); + } + + public boolean hasThreadGroup() { + return classContext.hasThreadGroup(); + } + + public ThreadGroup getThreadGroup() { + return classContext.getThreadGroup(); + } + + public URL getBase() { + return classContext.getBase(); + } + + public InputStream getResourceAsStream(String name) { + return classContext.getResourceAsStream(name); + } + + public URL getResource(String name) { + return classContext.getResource(name); + } + + public void dispose() { // HIER SOLLTE VIELLEICHT NOCH MEHR GETAN WERDEN? + classContext.dispose(); + } + + public synchronized Class findClass(String className) throws ClassNotFoundException { + return classContext.findClass(className); + } + + public synchronized Class loadClass(String className) throws ClassNotFoundException { + return classContext.loadClass(className); + } +} + diff --git a/sandbox/com/sun/star/lib/sandbox/CodeSource.java b/sandbox/com/sun/star/lib/sandbox/CodeSource.java new file mode 100644 index 000000000000..681bc341a4f4 --- /dev/null +++ b/sandbox/com/sun/star/lib/sandbox/CodeSource.java @@ -0,0 +1,83 @@ +/************************************************************************* + * + * $RCSfile: CodeSource.java,v $ + * + * $Revision: 1.1.1.1 $ + * + * last change: $Author: hr $ $Date: 2000-09-18 17:24:28 $ + * + * The Contents of this file are made available subject to the terms of + * either of the following licenses + * + * - GNU Lesser General Public License Version 2.1 + * - Sun Industry Standards Source License Version 1.1 + * + * Sun Microsystems Inc., October, 2000 + * + * GNU Lesser General Public License Version 2.1 + * ============================================= + * Copyright 2000 by Sun Microsystems, Inc. + * 901 San Antonio Road, Palo Alto, CA 94303, USA + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software Foundation. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, + * MA 02111-1307 USA + * + * + * Sun Industry Standards Source License Version 1.1 + * ================================================= + * The contents of this file are subject to the Sun Industry Standards + * Source License Version 1.1 (the "License"); You may not use this file + * except in compliance with the License. You may obtain a copy of the + * License at http://www.openoffice.org/license.html. + * + * Software provided under this License is provided on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, + * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS, + * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. + * See the License for the specific provisions governing your rights and + * obligations concerning the Software. + * + * The Initial Developer of the Original Code is: Sun Microsystems, Inc. + * + * Copyright: 2000 by Sun Microsystems, Inc. + * + * All Rights Reserved. + * + * Contributor(s): _______________________________________ + * + * + ************************************************************************/ + +package com.sun.star.lib.sandbox; + +import java.net.URL; + +import java.util.Vector; + +public final class CodeSource { + URL url; + java.security.Identity identities[]; + + public CodeSource(URL url) { + this(url, new java.security.Identity[0]); + } + + public CodeSource(URL url, java.security.Identity identities[]) { + SecurityManager security = System.getSecurityManager(); +// if(security != null) security.checkSecurityAccess("CodeSource"); + + this.url = url; + } +} + diff --git a/sandbox/com/sun/star/lib/sandbox/Disposable.java b/sandbox/com/sun/star/lib/sandbox/Disposable.java new file mode 100644 index 000000000000..97291305882a --- /dev/null +++ b/sandbox/com/sun/star/lib/sandbox/Disposable.java @@ -0,0 +1,67 @@ +/************************************************************************* + * + * $RCSfile: Disposable.java,v $ + * + * $Revision: 1.1.1.1 $ + * + * last change: $Author: hr $ $Date: 2000-09-18 17:24:28 $ + * + * The Contents of this file are made available subject to the terms of + * either of the following licenses + * + * - GNU Lesser General Public License Version 2.1 + * - Sun Industry Standards Source License Version 1.1 + * + * Sun Microsystems Inc., October, 2000 + * + * GNU Lesser General Public License Version 2.1 + * ============================================= + * Copyright 2000 by Sun Microsystems, Inc. + * 901 San Antonio Road, Palo Alto, CA 94303, USA + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software Foundation. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, + * MA 02111-1307 USA + * + * + * Sun Industry Standards Source License Version 1.1 + * ================================================= + * The contents of this file are subject to the Sun Industry Standards + * Source License Version 1.1 (the "License"); You may not use this file + * except in compliance with the License. You may obtain a copy of the + * License at http://www.openoffice.org/license.html. + * + * Software provided under this License is provided on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, + * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS, + * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. + * See the License for the specific provisions governing your rights and + * obligations concerning the Software. + * + * The Initial Developer of the Original Code is: Sun Microsystems, Inc. + * + * Copyright: 2000 by Sun Microsystems, Inc. + * + * All Rights Reserved. + * + * Contributor(s): _______________________________________ + * + * + ************************************************************************/ + +package com.sun.star.lib.sandbox; + +public interface Disposable { + void dispose(); +} + diff --git a/sandbox/com/sun/star/lib/sandbox/ExecutionContext.java b/sandbox/com/sun/star/lib/sandbox/ExecutionContext.java new file mode 100644 index 000000000000..8336bf04ddaa --- /dev/null +++ b/sandbox/com/sun/star/lib/sandbox/ExecutionContext.java @@ -0,0 +1,460 @@ +/************************************************************************* + * + * $RCSfile: ExecutionContext.java,v $ + * + * $Revision: 1.1.1.1 $ + * + * last change: $Author: hr $ $Date: 2000-09-18 17:24:28 $ + * + * The Contents of this file are made available subject to the terms of + * either of the following licenses + * + * - GNU Lesser General Public License Version 2.1 + * - Sun Industry Standards Source License Version 1.1 + * + * Sun Microsystems Inc., October, 2000 + * + * GNU Lesser General Public License Version 2.1 + * ============================================= + * Copyright 2000 by Sun Microsystems, Inc. + * 901 San Antonio Road, Palo Alto, CA 94303, USA + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software Foundation. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, + * MA 02111-1307 USA + * + * + * Sun Industry Standards Source License Version 1.1 + * ================================================= + * The contents of this file are subject to the Sun Industry Standards + * Source License Version 1.1 (the "License"); You may not use this file + * except in compliance with the License. You may obtain a copy of the + * License at http://www.openoffice.org/license.html. + * + * Software provided under this License is provided on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, + * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS, + * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. + * See the License for the specific provisions governing your rights and + * obligations concerning the Software. + * + * The Initial Developer of the Original Code is: Sun Microsystems, Inc. + * + * Copyright: 2000 by Sun Microsystems, Inc. + * + * All Rights Reserved. + * + * Contributor(s): _______________________________________ + * + * + ************************************************************************/ + +package com.sun.star.lib.sandbox; + +import java.awt.Image; +import java.awt.Dimension; +import java.awt.Container; +import java.awt.BorderLayout; + +import java.applet.Applet; +import java.applet.AppletStub; +import java.applet.AppletContext; +import java.applet.AudioClip; + +import java.io.IOException; +import java.io.InputStream; +import java.io.ByteArrayOutputStream; + +import java.net.URL; +import java.net.MalformedURLException; + +import java.text.MessageFormat; + +import java.util.Hashtable; +import java.util.Observable; +import java.util.MissingResourceException; +import java.util.ResourceBundle; + +public abstract class ExecutionContext extends Observable { + private static final boolean DEBUG = false; + + private static int instances; + + /* message ids */ + protected final static int CMD_LOAD = 1; + protected final static int CMD_INIT = 2; + protected final static int CMD_START = 3; + protected final static int CMD_STOP = 4; + protected final static int CMD_DESTROY = 5; + protected final static int CMD_DISPOSE = 6; + + protected final static int LOADED = 1; + protected final static int INITED = 2; + protected final static int STARTED = 3; + protected final static int STOPPED = 4; + protected final static int DESTROYED = 5; + protected final static int DISPOSED = 6; + + private int status = DISPOSED; + + protected ClassContext classContext; + + private Thread dispatchThread = null; + private SandboxThreadGroup threadGroup = null; + + private String name; + + protected ResourceBundle resourceBundle; + + private Object synObj = new Object(); + private Message head; + private Message tail; + private boolean loop = true; + + protected ExecutionContext() { + instances ++; + } + + public void finalize() { + instances --; + } + + public int getStatus() { + return status; + } + + Object getSynObject() { + return synObj; + } + + class Message { + Message next; + int id; + + Message(int id) { + this.id = id; + } + } + + public void init(String name, ClassContext classContext) throws MissingResourceException { + this.name = name; + + resourceBundle = ResourceBundle.getBundle("sun.applet.resources.MsgAppletViewer"); + + this.classContext = classContext; + + threadGroup = new SandboxThreadGroup(classContext.getThreadGroup(), name, classContext.getClassLoader()); + threadGroup.setDaemon(true); + + dispatchThread = new Thread( threadGroup, new Runnable() { + public void run() { + while( loop ) { + synchronized( getSynObject() ) { + if (head == null) { + try { + getSynObject().wait(); + } + catch (InterruptedException e ) { + if (DEBUG) System.err.println("#### ExecutionContext - dispatchThread " + dispatchThread.toString() + " -interrupted"); + break; + } + } + } + if (DEBUG) System.err.println("#### ExecutionContext dispatchThread " + dispatchThread.toString() + " -dispatching: " + head.id); + dispatch( head.id ); + if (DEBUG) System.err.println("#### ExecutionContext dispatchThread " + dispatchThread.toString() + " get next head - current state is " +head.id ); + synchronized( getSynObject() ) { + head = head.next; + getSynObject().notify(); + } + } + if(DEBUG) System.err.println("#### ExecutionContext - dispatchThread -terminating"); + } + }); + + dispatchThread.start(); + } + public void sendEvent(int id) { + sendEvent(id, 0); + } + + public void sendEvent(int id, int timeout) { + synchronized( getSynObject() ) { + try { + Message message = new Message(id); + if(tail != null) + tail.next = message; + + tail = message; + + if(head == null) + head = tail; + + getSynObject().notify(); + + if ( timeout != 0 ) + getSynObject().wait( timeout ); + } + catch( InterruptedException e ) { + } + } + } + + public void dispose() { + //if(DEBUG) System.err.println("#### ExecutionContext.disposing"); + dispose(1000); + } + + public void dispose( long timeout ) { + if(DEBUG) System.err.println("#### ExecutionContext "+ dispatchThread.toString() +"disposing:" + timeout); + try { + try { + synchronized( getSynObject() ) { + while( head != null ) + getSynObject().wait( timeout ); // wait at most one second for each queued command + } + } + catch(InterruptedException ee) { + if(DEBUG) System.err.println("#### ExecutionContext " + dispatchThread.toString() + " - dispose 1:" + ee); + } + + loop = false; + + getSynObject().notifyAll(); + // dispatchThread.interrupt(); + dispatchThread.join(timeout); + + if(DEBUG) threadGroup.list(); + +// threadGroup.stop(); + + if ( !threadGroup.isDestroyed() ) + threadGroup.destroy(); + } + catch (Exception ie) { + if(DEBUG) System.err.println("#### ExecutionContext "+ threadGroup.toString() + " - destroyThreadGroup:" + ie); + try { + threadGroup.stop(); + } catch (Exception se) { + if(DEBUG) System.err.println("#### ExecutionContext "+ threadGroup.toString() + " - stop ThreadGroup:" + se); + } + } + + classContext = null; + + dispatchThread = null; + threadGroup.dispose(); + threadGroup = null; + + name = null; + + resourceBundle = null; + + synObj = null; + head = null; + tail = null; + } + + + protected void showStatus(String status) { + if (DEBUG) System.err.println("#### ExecutionContext.showStatus:" + status); + setChanged(); + notifyObservers(resourceBundle.getString("appletpanel." + status)); + } + + protected void showStatus(String status, String arg1) { + if(DEBUG) System.err.println("#### ExecutionContext.showStatus" + status + " " + arg1); + try { + Object args[] = new Object[1]; + args[0] = arg1; + setChanged(); + try { + notifyObservers(MessageFormat.format(resourceBundle.getString("appletpanel." + status), args)); + } + catch(MissingResourceException me) {} + } + catch(Exception ee) { + if(DEBUG)System.err.println("#### ExecutionContext.showStatus:" + ee); + } + } + + + public ThreadGroup getThreadGroup() { + return threadGroup; + } + + /** + * Send an event. Queue it for execution by the handler thread. + */ + public void dispatch(int id) { + try { + switch(id) { + case CMD_LOAD: + if (status == DISPOSED) { + xload(); + status = LOADED; + showStatus("loaded"); + } + else + showStatus("notdisposed"); + break; + + case CMD_INIT: + if(status == LOADED || status == DESTROYED) { + xinit(); + status = INITED; + showStatus("inited"); + } + else + showStatus("notloaded"); + break; + + case CMD_START: + if (status == INITED || status == STOPPED) { + xstart(); + status = STARTED; + showStatus("started"); + } + else + showStatus("notinited"); + break; + + case CMD_STOP: + if (status == STARTED) { + xstop(); + status = STOPPED; + showStatus("stopped"); + } + else + showStatus("notstarted"); + break; + + case CMD_DESTROY: + if(status == INITED || status == STOPPED) { + xdestroy(); + status = DESTROYED; + showStatus("destroyed"); + } + else + showStatus("notstopped"); + break; + + case CMD_DISPOSE: + if (status == LOADED || status == DESTROYED) { + xdispose(); + // baseResourceLoader.flush(); + status = DISPOSED; + showStatus("disposed"); + } + else + showStatus("notdestroyed"); + break; + + default: + xExtended(id); + } + } + catch (ClassNotFoundException classNotFoundException) { + showStatus("notfound", name); + if(DEBUG) classNotFoundException.printStackTrace(); + } + catch (InstantiationException instantiationException) { + showStatus("nocreate", name); + if(DEBUG) instantiationException.printStackTrace(); + } + catch (IllegalAccessException illegalAccessException) { + showStatus("noconstruct", name); + if(DEBUG) illegalAccessException.printStackTrace(); + } + catch (Exception exception) { + showStatus("exception", exception.getMessage()); + if(DEBUG) exception.printStackTrace(); + } + catch (ThreadDeath threadDeath) { + showStatus("death"); + if(DEBUG) threadDeath.printStackTrace(); + + throw threadDeath; + } + catch (Error error) { + showStatus("error", error.getMessage()); + if(DEBUG) error.printStackTrace(); + } + } + + protected abstract void xload() throws ClassNotFoundException, InstantiationException, IllegalAccessException; + protected abstract void xinit(); + protected abstract void xstart(); + protected abstract void xstop(); + protected abstract void xdestroy(); + protected abstract void xdispose(); + + protected void xExtended(int id) { + } + + /* + ** + */ + public void sendLoad() { + sendEvent(CMD_LOAD); + } + + public void sendInit() { + sendEvent(CMD_INIT); + } + + public void sendStart() { + sendEvent(CMD_START); + } + + public void sendStop() { + sendEvent(CMD_STOP); + } + + public void sendDestroy() { + sendEvent(CMD_DESTROY); + } + + public void sendDispose() { + sendEvent(CMD_DISPOSE); + } + + public void startUp() { + sendLoad(); + sendInit(); + sendStart(); + } + + public void shutdown() { + sendStop(); + sendDestroy(); + sendDispose(); + } + + public void restart() { + sendStop(); + sendDestroy(); + sendInit(); + sendStart(); + } + + public void reload() { + sendStop(); + sendDestroy(); + sendDispose(); + sendLoad(); + sendInit(); + sendStart(); + } +} + diff --git a/sandbox/com/sun/star/lib/sandbox/Holder.java b/sandbox/com/sun/star/lib/sandbox/Holder.java new file mode 100644 index 000000000000..95e9e5dbd735 --- /dev/null +++ b/sandbox/com/sun/star/lib/sandbox/Holder.java @@ -0,0 +1,69 @@ +/************************************************************************* + * + * $RCSfile: Holder.java,v $ + * + * $Revision: 1.1.1.1 $ + * + * last change: $Author: hr $ $Date: 2000-09-18 17:24:28 $ + * + * The Contents of this file are made available subject to the terms of + * either of the following licenses + * + * - GNU Lesser General Public License Version 2.1 + * - Sun Industry Standards Source License Version 1.1 + * + * Sun Microsystems Inc., October, 2000 + * + * GNU Lesser General Public License Version 2.1 + * ============================================= + * Copyright 2000 by Sun Microsystems, Inc. + * 901 San Antonio Road, Palo Alto, CA 94303, USA + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software Foundation. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, + * MA 02111-1307 USA + * + * + * Sun Industry Standards Source License Version 1.1 + * ================================================= + * The contents of this file are subject to the Sun Industry Standards + * Source License Version 1.1 (the "License"); You may not use this file + * except in compliance with the License. You may obtain a copy of the + * License at http://www.openoffice.org/license.html. + * + * Software provided under this License is provided on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, + * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS, + * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. + * See the License for the specific provisions governing your rights and + * obligations concerning the Software. + * + * The Initial Developer of the Original Code is: Sun Microsystems, Inc. + * + * Copyright: 2000 by Sun Microsystems, Inc. + * + * All Rights Reserved. + * + * Contributor(s): _______________________________________ + * + * + ************************************************************************/ + +package com.sun.star.lib.sandbox; + + +public interface Holder { + void addCargo(Object object); + void removeCargo(Object object); +} + diff --git a/sandbox/com/sun/star/lib/sandbox/ImageProducerProxy.java b/sandbox/com/sun/star/lib/sandbox/ImageProducerProxy.java new file mode 100644 index 000000000000..d2ca81f10d18 --- /dev/null +++ b/sandbox/com/sun/star/lib/sandbox/ImageProducerProxy.java @@ -0,0 +1,108 @@ +/************************************************************************* + * + * $RCSfile: ImageProducerProxy.java,v $ + * + * $Revision: 1.1.1.1 $ + * + * last change: $Author: hr $ $Date: 2000-09-18 17:24:28 $ + * + * The Contents of this file are made available subject to the terms of + * either of the following licenses + * + * - GNU Lesser General Public License Version 2.1 + * - Sun Industry Standards Source License Version 1.1 + * + * Sun Microsystems Inc., October, 2000 + * + * GNU Lesser General Public License Version 2.1 + * ============================================= + * Copyright 2000 by Sun Microsystems, Inc. + * 901 San Antonio Road, Palo Alto, CA 94303, USA + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software Foundation. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, + * MA 02111-1307 USA + * + * + * Sun Industry Standards Source License Version 1.1 + * ================================================= + * The contents of this file are subject to the Sun Industry Standards + * Source License Version 1.1 (the "License"); You may not use this file + * except in compliance with the License. You may obtain a copy of the + * License at http://www.openoffice.org/license.html. + * + * Software provided under this License is provided on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, + * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS, + * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. + * See the License for the specific provisions governing your rights and + * obligations concerning the Software. + * + * The Initial Developer of the Original Code is: Sun Microsystems, Inc. + * + * Copyright: 2000 by Sun Microsystems, Inc. + * + * All Rights Reserved. + * + * Contributor(s): _______________________________________ + * + * + ************************************************************************/ + +package com.sun.star.lib.sandbox; + +import java.awt.image.ImageConsumer; +import java.awt.image.ImageProducer; + +import java.util.Vector; + +class ImageProducerProxy implements ImageProducer, Holder { + ImageProducer imageProducer; + + ImageProducerProxy(ImageProducer imageProducer) { + this.imageProducer = imageProducer; + } + + public void addConsumer(ImageConsumer imageConsumer) { + imageProducer.addConsumer(imageConsumer); + } + + public boolean isConsumer(ImageConsumer imageConsumer) { + return imageProducer.isConsumer(imageConsumer); + } + + public void removeConsumer(ImageConsumer imageConsumer) { + imageProducer.removeConsumer(imageConsumer); + } + + public void startProduction(ImageConsumer imageConsumer) { + imageProducer.startProduction(imageConsumer); + } + + public void requestTopDownLeftRightResend(ImageConsumer imageConsumer) { + imageProducer.requestTopDownLeftRightResend(imageConsumer); + } + + + /* Holder methods */ + private Vector cargo = new Vector(); + + public void addCargo(Object object) { + cargo.addElement(object); + } + + public void removeCargo(Object object) { + cargo.removeElement(object); + } +} + diff --git a/sandbox/com/sun/star/lib/sandbox/JarEntry.java b/sandbox/com/sun/star/lib/sandbox/JarEntry.java new file mode 100644 index 000000000000..05741e8c35cd --- /dev/null +++ b/sandbox/com/sun/star/lib/sandbox/JarEntry.java @@ -0,0 +1,126 @@ +/************************************************************************* + * + * $RCSfile: JarEntry.java,v $ + * + * $Revision: 1.1.1.1 $ + * + * last change: $Author: hr $ $Date: 2000-09-18 17:24:28 $ + * + * The Contents of this file are made available subject to the terms of + * either of the following licenses + * + * - GNU Lesser General Public License Version 2.1 + * - Sun Industry Standards Source License Version 1.1 + * + * Sun Microsystems Inc., October, 2000 + * + * GNU Lesser General Public License Version 2.1 + * ============================================= + * Copyright 2000 by Sun Microsystems, Inc. + * 901 San Antonio Road, Palo Alto, CA 94303, USA + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software Foundation. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, + * MA 02111-1307 USA + * + * + * Sun Industry Standards Source License Version 1.1 + * ================================================= + * The contents of this file are subject to the Sun Industry Standards + * Source License Version 1.1 (the "License"); You may not use this file + * except in compliance with the License. You may obtain a copy of the + * License at http://www.openoffice.org/license.html. + * + * Software provided under this License is provided on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, + * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS, + * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. + * See the License for the specific provisions governing your rights and + * obligations concerning the Software. + * + * The Initial Developer of the Original Code is: Sun Microsystems, Inc. + * + * Copyright: 2000 by Sun Microsystems, Inc. + * + * All Rights Reserved. + * + * Contributor(s): _______________________________________ + * + * + ************************************************************************/ + +package com.sun.star.lib.sandbox; + +import java.security.Identity; + +import java.util.zip.ZipEntry; + +import java.lang.reflect.Method; +import java.lang.reflect.InvocationTargetException; + +import sun.tools.jar.JarVerifierStream; + +public class JarEntry { + private static final boolean DEBUG = false; + + private ZipEntry zipEntry = null; + private JarVerifierStream jvs = null; + + public JarEntry(ZipEntry zipEntry, JarVerifierStream jvs) { + this.zipEntry = zipEntry; + this.jvs = jvs; + } + + public Identity[] getIdentities() { + Identity identities[] = null; + + if(jvs != null) { + Class classes[] = new Class[1]; + classes[0] = String.class; + + try { + Method method = JarVerifierStream.class.getMethod("getIdentities", classes); + + Object objects[] = new Object[1]; + objects[0] = zipEntry.getName(); + + identities = (Identity[])method.invoke(jvs, objects); + } + catch(IllegalAccessException illegalAccessException) { + if(DEBUG)System.err.println("#### JarEntry.getIdentities:" + illegalAccessException); + } + catch(IllegalArgumentException illegalArgumentException) { + if(DEBUG)System.err.println("#### JarEntry.getIdentities:" + illegalArgumentException); + } + catch(InvocationTargetException invocationTargetException ) { + if(DEBUG)System.err.println("#### JarEntry.getIdentities:" + invocationTargetException); + } + catch(NoSuchMethodException noSuchMethodException) { + if(DEBUG)System.err.println("#### JarEntry.getIdentities:" + noSuchMethodException); + } + catch(SecurityException securityException) { + if(DEBUG)System.err.println("#### JarEntry.getIdentities:" + securityException); + } + } + return identities; + } + + public String getName() { + return zipEntry.getName(); + } + + public long getSize() { + return zipEntry.getSize(); + } +} + diff --git a/sandbox/com/sun/star/lib/sandbox/JarInputStream.java b/sandbox/com/sun/star/lib/sandbox/JarInputStream.java new file mode 100644 index 000000000000..de4878ac9108 --- /dev/null +++ b/sandbox/com/sun/star/lib/sandbox/JarInputStream.java @@ -0,0 +1,140 @@ +/************************************************************************* + * + * $RCSfile: JarInputStream.java,v $ + * + * $Revision: 1.1.1.1 $ + * + * last change: $Author: hr $ $Date: 2000-09-18 17:24:28 $ + * + * The Contents of this file are made available subject to the terms of + * either of the following licenses + * + * - GNU Lesser General Public License Version 2.1 + * - Sun Industry Standards Source License Version 1.1 + * + * Sun Microsystems Inc., October, 2000 + * + * GNU Lesser General Public License Version 2.1 + * ============================================= + * Copyright 2000 by Sun Microsystems, Inc. + * 901 San Antonio Road, Palo Alto, CA 94303, USA + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software Foundation. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, + * MA 02111-1307 USA + * + * + * Sun Industry Standards Source License Version 1.1 + * ================================================= + * The contents of this file are subject to the Sun Industry Standards + * Source License Version 1.1 (the "License"); You may not use this file + * except in compliance with the License. You may obtain a copy of the + * License at http://www.openoffice.org/license.html. + * + * Software provided under this License is provided on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, + * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS, + * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. + * See the License for the specific provisions governing your rights and + * obligations concerning the Software. + * + * The Initial Developer of the Original Code is: Sun Microsystems, Inc. + * + * Copyright: 2000 by Sun Microsystems, Inc. + * + * All Rights Reserved. + * + * Contributor(s): _______________________________________ + * + * + ************************************************************************/ + +package com.sun.star.lib.sandbox; + +import java.io.InputStream; +import java.io.IOException; + +import java.util.Hashtable; + +import java.util.zip.ZipEntry; +import java.util.zip.ZipInputStream; + +import sun.tools.jar.JarVerifierStream; +import sun.tools.jar.JarException; + +class JarInputStream { +// JarVerifierStream jvs = null; + ZipInputStream jvs = null; + + ZipEntry ent = null; + + // mapping of names to objects that have been loaded from the jar + Hashtable nameToObject = new Hashtable(); + + public JarInputStream(InputStream inputStream) throws IOException { +// try { + jvs = new ZipInputStream(inputStream); +// jvs = new JarVerifierStream(inputStream); +// } +// catch(JarException e) { +// throw new IOException("JarInputStream"); +// } + } + + + public int available() throws IOException { + return jvs.available(); + } + + + public JarEntry getNextJarEntry() throws IOException { + ent = jvs.getNextEntry(); + +// if(ent != null && isManifest(ent.getName())) +// ent = jvs.getNextEntry(); + + return (ent != null) ? new JarEntry(ent, null/*jvs*/) : null; + } + + public int read(byte bytes[]) throws IOException { + return jvs.read(bytes,0, bytes.length); + } + + public void close() throws IOException { + jvs.close(); + } + + + static boolean isManifest(String name) { + boolean isManifest = false; + + name = name.toUpperCase(); + + /* ignore leading slash */ + if (name.startsWith("/")) + name = name.substring(1); + + /* a manifest file or signature file at all? */ + if (name.startsWith("META-INF/")) { + /* the manifest? */ + isManifest = name.equalsIgnoreCase("META-INF/MANIFEST.MF"); + isManifest = isManifest || name.endsWith("DSA"); + isManifest = isManifest || name.endsWith("PK7"); + isManifest = isManifest || name.endsWith("PGP"); + isManifest = isManifest || name.endsWith("SF"); + } + + return isManifest; + } +} + diff --git a/sandbox/com/sun/star/lib/sandbox/Permission.java b/sandbox/com/sun/star/lib/sandbox/Permission.java new file mode 100644 index 000000000000..395f314cbb9a --- /dev/null +++ b/sandbox/com/sun/star/lib/sandbox/Permission.java @@ -0,0 +1,67 @@ +/************************************************************************* + * + * $RCSfile: Permission.java,v $ + * + * $Revision: 1.1.1.1 $ + * + * last change: $Author: hr $ $Date: 2000-09-18 17:24:28 $ + * + * The Contents of this file are made available subject to the terms of + * either of the following licenses + * + * - GNU Lesser General Public License Version 2.1 + * - Sun Industry Standards Source License Version 1.1 + * + * Sun Microsystems Inc., October, 2000 + * + * GNU Lesser General Public License Version 2.1 + * ============================================= + * Copyright 2000 by Sun Microsystems, Inc. + * 901 San Antonio Road, Palo Alto, CA 94303, USA + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software Foundation. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, + * MA 02111-1307 USA + * + * + * Sun Industry Standards Source License Version 1.1 + * ================================================= + * The contents of this file are subject to the Sun Industry Standards + * Source License Version 1.1 (the "License"); You may not use this file + * except in compliance with the License. You may obtain a copy of the + * License at http://www.openoffice.org/license.html. + * + * Software provided under this License is provided on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, + * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS, + * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. + * See the License for the specific provisions governing your rights and + * obligations concerning the Software. + * + * The Initial Developer of the Original Code is: Sun Microsystems, Inc. + * + * Copyright: 2000 by Sun Microsystems, Inc. + * + * All Rights Reserved. + * + * Contributor(s): _______________________________________ + * + * + ************************************************************************/ + +package com.sun.star.lib.sandbox; + +interface Permission { + boolean implies(Permission permission); +} + diff --git a/sandbox/com/sun/star/lib/sandbox/PermissionCollection.java b/sandbox/com/sun/star/lib/sandbox/PermissionCollection.java new file mode 100644 index 000000000000..1fe989f2a20d --- /dev/null +++ b/sandbox/com/sun/star/lib/sandbox/PermissionCollection.java @@ -0,0 +1,117 @@ +/************************************************************************* + * + * $RCSfile: PermissionCollection.java,v $ + * + * $Revision: 1.1.1.1 $ + * + * last change: $Author: hr $ $Date: 2000-09-18 17:24:28 $ + * + * The Contents of this file are made available subject to the terms of + * either of the following licenses + * + * - GNU Lesser General Public License Version 2.1 + * - Sun Industry Standards Source License Version 1.1 + * + * Sun Microsystems Inc., October, 2000 + * + * GNU Lesser General Public License Version 2.1 + * ============================================= + * Copyright 2000 by Sun Microsystems, Inc. + * 901 San Antonio Road, Palo Alto, CA 94303, USA + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software Foundation. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, + * MA 02111-1307 USA + * + * + * Sun Industry Standards Source License Version 1.1 + * ================================================= + * The contents of this file are subject to the Sun Industry Standards + * Source License Version 1.1 (the "License"); You may not use this file + * except in compliance with the License. You may obtain a copy of the + * License at http://www.openoffice.org/license.html. + * + * Software provided under this License is provided on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, + * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS, + * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. + * See the License for the specific provisions governing your rights and + * obligations concerning the Software. + * + * The Initial Developer of the Original Code is: Sun Microsystems, Inc. + * + * Copyright: 2000 by Sun Microsystems, Inc. + * + * All Rights Reserved. + * + * Contributor(s): _______________________________________ + * + * + ************************************************************************/ + +package com.sun.star.lib.sandbox; + +import java.util.Vector; + +public final class PermissionCollection { + private Vector permissions = new Vector(); + + public PermissionCollection() { + SecurityManager security = System.getSecurityManager(); + if(security != null) security.checkSecurityAccess("PermissionCollection"); + } + + public PermissionCollection(PermissionCollection permissionCollection) { + SecurityManager security = System.getSecurityManager(); + if(security != null) security.checkSecurityAccess("PermissionCollection"); + + permissions = (Vector)permissionCollection.permissions.clone(); + } + +// public PermissionCollection(PermissionCollection p1, PermissionCollection p2) { +// SecurityManager security = System.getSecurityManager(); +// if(security != null) security.checkSecurityAccess("PermissionCollection"); + +// if(p1 != null) +// this.permissions = (Vector)p1.permissions.clone(); + +// if(p2 != null) +// for(int i = 0; i < p2.permissions.size(); i ++) +// this.permissions.addElement(p2.permissions.elementAt(i)); +// } + + public void reset() { + SecurityManager security = System.getSecurityManager(); + if(security != null) security.checkSecurityAccess("PermissionCollection"); + + permissions.removeAllElements(); + } + + public void add(Permission permission) { + SecurityManager security = System.getSecurityManager(); + if(security != null) security.checkSecurityAccess("PermissionCollection"); + + permissions.addElement(permission); + } + + public boolean implies(Permission permission) { + boolean granted = false; + + for(int i = 0; i < permissions.size() && !granted; i++) { + granted = ((Permission)permissions.elementAt(i)).implies(permission); + } + + return granted; + } +} + diff --git a/sandbox/com/sun/star/lib/sandbox/ProtectionDomain.java b/sandbox/com/sun/star/lib/sandbox/ProtectionDomain.java new file mode 100644 index 000000000000..d7d39c9335c9 --- /dev/null +++ b/sandbox/com/sun/star/lib/sandbox/ProtectionDomain.java @@ -0,0 +1,118 @@ +/************************************************************************* + * + * $RCSfile: ProtectionDomain.java,v $ + * + * $Revision: 1.1.1.1 $ + * + * last change: $Author: hr $ $Date: 2000-09-18 17:24:28 $ + * + * The Contents of this file are made available subject to the terms of + * either of the following licenses + * + * - GNU Lesser General Public License Version 2.1 + * - Sun Industry Standards Source License Version 1.1 + * + * Sun Microsystems Inc., October, 2000 + * + * GNU Lesser General Public License Version 2.1 + * ============================================= + * Copyright 2000 by Sun Microsystems, Inc. + * 901 San Antonio Road, Palo Alto, CA 94303, USA + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software Foundation. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, + * MA 02111-1307 USA + * + * + * Sun Industry Standards Source License Version 1.1 + * ================================================= + * The contents of this file are subject to the Sun Industry Standards + * Source License Version 1.1 (the "License"); You may not use this file + * except in compliance with the License. You may obtain a copy of the + * License at http://www.openoffice.org/license.html. + * + * Software provided under this License is provided on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, + * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS, + * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. + * See the License for the specific provisions governing your rights and + * obligations concerning the Software. + * + * The Initial Developer of the Original Code is: Sun Microsystems, Inc. + * + * Copyright: 2000 by Sun Microsystems, Inc. + * + * All Rights Reserved. + * + * Contributor(s): _______________________________________ + * + * + ************************************************************************/ + +package com.sun.star.lib.sandbox; + +import java.security.Identity; + +import sun.security.provider.SystemIdentity; +import sun.security.provider.SystemSigner; + +public final class ProtectionDomain { + private PermissionCollection permissionCollection; + private CodeSource codeSource; + + public ProtectionDomain(CodeSource codeSource, PermissionCollection permissionCollection) { +// this.permissionCollection = new PermissionCollection(codeSource.getPermissionCollection(), permissionCollection); + SecurityManager security = System.getSecurityManager(); + if(security != null) security.checkSecurityAccess("ProtectionDomain"); + + this.permissionCollection = permissionCollection; + this.codeSource = codeSource; + } + + public PermissionCollection getPermissions() { + SecurityManager security = System.getSecurityManager(); + if(security != null) security.checkSecurityAccess("ProtectionDomain"); + + return permissionCollection; + } + + boolean isTrusted() { + Identity identities[] = codeSource.identities; + + boolean trusted = false; + + if(identities != null) { + for(int i = 0; i < identities.length && !trusted; i++) + System.out.println("XXX:" + identities[i].toString(true)); + + for(int i = 0; i < identities.length; i ++) { + if(identities[i] instanceof SystemIdentity) { + SystemIdentity systemIdentity = (SystemIdentity)identities[i]; + + trusted = systemIdentity.isTrusted(); + } + else if(identities[i] instanceof SystemSigner) { + SystemSigner systemSigner = (SystemSigner)identities[i]; + + trusted = systemSigner.isTrusted(); + } + } + } + return trusted; + } + + boolean implies(Permission permission) { + return isTrusted() || permissionCollection.implies(permission); + } +} + diff --git a/sandbox/com/sun/star/lib/sandbox/Resource.java b/sandbox/com/sun/star/lib/sandbox/Resource.java new file mode 100644 index 000000000000..03cc864e4d22 --- /dev/null +++ b/sandbox/com/sun/star/lib/sandbox/Resource.java @@ -0,0 +1,84 @@ +/************************************************************************* + * + * $RCSfile: Resource.java,v $ + * + * $Revision: 1.1.1.1 $ + * + * last change: $Author: hr $ $Date: 2000-09-18 17:24:28 $ + * + * The Contents of this file are made available subject to the terms of + * either of the following licenses + * + * - GNU Lesser General Public License Version 2.1 + * - Sun Industry Standards Source License Version 1.1 + * + * Sun Microsystems Inc., October, 2000 + * + * GNU Lesser General Public License Version 2.1 + * ============================================= + * Copyright 2000 by Sun Microsystems, Inc. + * 901 San Antonio Road, Palo Alto, CA 94303, USA + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software Foundation. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, + * MA 02111-1307 USA + * + * + * Sun Industry Standards Source License Version 1.1 + * ================================================= + * The contents of this file are subject to the Sun Industry Standards + * Source License Version 1.1 (the "License"); You may not use this file + * except in compliance with the License. You may obtain a copy of the + * License at http://www.openoffice.org/license.html. + * + * Software provided under this License is provided on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, + * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS, + * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. + * See the License for the specific provisions governing your rights and + * obligations concerning the Software. + * + * The Initial Developer of the Original Code is: Sun Microsystems, Inc. + * + * Copyright: 2000 by Sun Microsystems, Inc. + * + * All Rights Reserved. + * + * Contributor(s): _______________________________________ + * + * + ************************************************************************/ + +package com.sun.star.lib.sandbox; + +import java.applet.AudioClip; + +import java.awt.image.ImageProducer; + +import java.io.InputStream; +import java.io.IOException; + +import java.net.URL; +import sun.applet.AppletAudioClip; + +public interface Resource { + public ProtectionDomain getProtectionDomain(); + public URL getURL(); + public InputStream getInputStream() throws IOException; + public byte[] getBytes() throws IOException; + public ImageProducer getImageProducer(); + public AudioClip getAudioClip(); + public Object getContent() throws IOException; + public void loadJar(URL baseURL) throws IOException; +} + diff --git a/sandbox/com/sun/star/lib/sandbox/ResourceImpl.java b/sandbox/com/sun/star/lib/sandbox/ResourceImpl.java new file mode 100644 index 000000000000..3266acf37f16 --- /dev/null +++ b/sandbox/com/sun/star/lib/sandbox/ResourceImpl.java @@ -0,0 +1,331 @@ +/************************************************************************* + * + * $RCSfile: ResourceImpl.java,v $ + * + * $Revision: 1.1.1.1 $ + * + * last change: $Author: hr $ $Date: 2000-09-18 17:24:28 $ + * + * The Contents of this file are made available subject to the terms of + * either of the following licenses + * + * - GNU Lesser General Public License Version 2.1 + * - Sun Industry Standards Source License Version 1.1 + * + * Sun Microsystems Inc., October, 2000 + * + * GNU Lesser General Public License Version 2.1 + * ============================================= + * Copyright 2000 by Sun Microsystems, Inc. + * 901 San Antonio Road, Palo Alto, CA 94303, USA + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software Foundation. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, + * MA 02111-1307 USA + * + * + * Sun Industry Standards Source License Version 1.1 + * ================================================= + * The contents of this file are subject to the Sun Industry Standards + * Source License Version 1.1 (the "License"); You may not use this file + * except in compliance with the License. You may obtain a copy of the + * License at http://www.openoffice.org/license.html. + * + * Software provided under this License is provided on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, + * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS, + * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. + * See the License for the specific provisions governing your rights and + * obligations concerning the Software. + * + * The Initial Developer of the Original Code is: Sun Microsystems, Inc. + * + * Copyright: 2000 by Sun Microsystems, Inc. + * + * All Rights Reserved. + * + * Contributor(s): _______________________________________ + * + * + ************************************************************************/ + +package com.sun.star.lib.sandbox; + +import java.applet.AudioClip; + +import java.awt.image.ImageProducer; + +import java.io.InputStream; +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; +import java.io.IOException; + +import java.net.URL; +import java.net.URLConnection; +import java.net.MalformedURLException; + +import java.util.Enumeration; +import java.util.Vector; + +import sun.awt.image.ByteArrayImageSource; +import sun.awt.image.URLImageSource; + +import sun.applet.AppletAudioClip; + +class ResourceImpl implements Resource { + private static int instances; + private static final boolean DEBUG = false; + + private Object object; + private byte bytes[]; + private URL url; + private String type; + private ProtectionDomain protectionDomain; + + public ResourceImpl(URL url, byte bytes[], ProtectionDomain protectionDomain) { + if(DEBUG)System.err.println("#### ResourceImpl.<init>:" + url + " " + bytes + " " + protectionDomain); + + instances ++; + + this.protectionDomain = protectionDomain; + this.url = url; + this.bytes = bytes; + } + + public void finalize() { + instances --; + } + + public ProtectionDomain getProtectionDomain() { + return protectionDomain; + } + + public URL getURL() { + return url; + } + + public synchronized InputStream getInputStream() throws IOException { + if(DEBUG) System.err.print("#### ResourceImpl.getInputStream:" + url); + InputStream inputStream = null; + + if(bytes == null) { + if(DEBUG)System.err.println(" - from url"); + URLConnection c = url.openConnection(); + c.setAllowUserInteraction(false); + inputStream = c.getInputStream(); + } + else { + if(DEBUG)System.err.println(" - from bytes"); + inputStream = new ByteArrayInputStream(bytes); + } + + return inputStream; + } + + public synchronized byte[] getBytes() throws IOException { + final int chunkSize = 4096; + + if(bytes == null) { + InputStream inputStream = getInputStream(); + + int read = 0; + int total = 0; + Vector chunks = new Vector(); + + byte chunk[] = new byte[chunkSize]; + read = inputStream.read(chunk, 0, chunkSize); + while(read != -1) { // until end of file + if(read < chunkSize) { + byte tmpChunk[] = new byte[read]; + System.arraycopy(chunk, 0, tmpChunk, 0, tmpChunk.length); + chunk = tmpChunk; + } + + chunks.addElement(chunk); + chunk = new byte[chunkSize]; + total += read; + + read = inputStream.read(chunk, 0, chunkSize); + } + + inputStream.close(); + + byte tmpBytes[] = new byte[total]; + int index = 0; + for(int i = 0; i < chunks.size(); i++) { + chunk = (byte [])chunks.elementAt(i); + + System.arraycopy(chunk, 0, tmpBytes, index, chunk.length); + index += chunk.length; + } + + bytes = tmpBytes; + } + return bytes; + } + + public synchronized ImageProducer getImageProducer() { + if(DEBUG) System.err.println("#### Resource.getImageProducer:"); + + ImageProducer imageProducer = null; + + if(object != null) + imageProducer = (ImageProducer)object; + else { + if(bytes != null) + imageProducer = new ByteArrayImageSource(bytes, 0, bytes.length); + else + imageProducer = new URLImageSource(url); + + object = imageProducer; + } + + return imageProducer; + } + + public synchronized AudioClip getAudioClip() { + AudioClip audioClip = null; + + if(object != null) + audioClip = (AudioClip)object; + else { + if(bytes != null) + audioClip = new AppletAudioClip(bytes); + else + audioClip = new AppletAudioClip(url); + + object = audioClip; + } + + return audioClip; + } + + public synchronized void loadJar(URL baseURL) throws IOException { + if(object == null) { + Vector jarResourceProxys = new Vector(); + JarInputStream jar = null; + byte[] rbuf = new byte[4096]; + + try { + jar = new JarInputStream(getInputStream()); + + JarEntry jarEntry = jar.getNextJarEntry(); + while(jarEntry != null) { + String extension = null; + String fileName = jarEntry.getName(); + int extensionIndex = fileName.lastIndexOf('.'); + + if(extensionIndex != -1) { + extension = jarEntry.getName().substring(extensionIndex); + fileName = fileName.substring(0, extensionIndex); + } + // System.out.println("AEC entry:" + fileName + " " + extension); + fileName = fileName.replace('.', '/'); + + if(extension != null) + fileName += extension; + + + // Workaround: available funktioniert nicht!!! + ByteArrayOutputStream baos = new ByteArrayOutputStream(); + + int nread; + while((nread = jar.read(rbuf)) > 0) + baos.write(rbuf, 0, nread); + + byte bytes[] = baos.toByteArray(); //new byte[jar.available()]; + // jar.read(bytes); + + ProtectionDomain tmpProtectionDomain = null; + + if(protectionDomain != null) { + PermissionCollection permissionCollection = protectionDomain.getPermissions(); + CodeSource codeSource = new CodeSource(baseURL, jarEntry.getIdentities()); + tmpProtectionDomain = new ProtectionDomain(codeSource, permissionCollection); + } + + jarResourceProxys.addElement(ResourceProxy.create(new URL(baseURL, fileName), bytes, tmpProtectionDomain)); + + jarEntry = jar.getNextJarEntry(); + } + } + finally { + if(jar != null) + jar.close(); + } + + object = jarResourceProxys; + } + } + + private void guessType() { + /* Parse entries which have special names, like the + manifest. We invent "mime types" local to this class */ +// if (type == null) { +// type = guessManifestType(name); +// } + + if (type == null) { + /* REMIND Get this from MANIFEST.MF. This should + be changed as soon as manifest support is + fixed. Because jvs must support mark, and it + isn't always obvious since it's a + FilterInputStream and whatever it used to + build it is what would give it mark. */ + try { + InputStream tmpStream = new ByteArrayInputStream(getBytes()); + type = URLConnection.guessContentTypeFromStream(tmpStream); + } + catch(IOException iOException) { + if(DEBUG) System.err.println("#### Resource.guessType - exception:" + iOException); + } + } + + if (type == null) { + // REMIND - this canbe cleaned up if we don't mind + // exporting access to MANIFEST data. - epll + type = "input-stream/input-stream"; + } + + if(DEBUG) System.err.println("#### Resource.guessType - guessed:" + type); + } + + + public Object getContent() throws IOException { + Object content = null; + + guessType(); + + if (type.startsWith("image")) { + content = getImageProducer(); + } + else if (type.startsWith("audio")) { + content = getAudioClip(); + } + else if (type.startsWith("application/java-vm") || type.startsWith("application/x-java-vm")) { + + } + else if (type.equals("manifest/manifest") || type.equals("manifest/signature-bin")) { + /* We know what it is. It is handled by JarVerifierStream */ + + } + else { + content = getInputStream(); + } + + if(DEBUG) System.err.println("#### Resource.getContent:" + content); + + return content; + } +} + diff --git a/sandbox/com/sun/star/lib/sandbox/ResourceProxy.java b/sandbox/com/sun/star/lib/sandbox/ResourceProxy.java new file mode 100644 index 000000000000..8f55479b0190 --- /dev/null +++ b/sandbox/com/sun/star/lib/sandbox/ResourceProxy.java @@ -0,0 +1,247 @@ +/************************************************************************* + * + * $RCSfile: ResourceProxy.java,v $ + * + * $Revision: 1.1.1.1 $ + * + * last change: $Author: hr $ $Date: 2000-09-18 17:24:28 $ + * + * The Contents of this file are made available subject to the terms of + * either of the following licenses + * + * - GNU Lesser General Public License Version 2.1 + * - Sun Industry Standards Source License Version 1.1 + * + * Sun Microsystems Inc., October, 2000 + * + * GNU Lesser General Public License Version 2.1 + * ============================================= + * Copyright 2000 by Sun Microsystems, Inc. + * 901 San Antonio Road, Palo Alto, CA 94303, USA + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software Foundation. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, + * MA 02111-1307 USA + * + * + * Sun Industry Standards Source License Version 1.1 + * ================================================= + * The contents of this file are subject to the Sun Industry Standards + * Source License Version 1.1 (the "License"); You may not use this file + * except in compliance with the License. You may obtain a copy of the + * License at http://www.openoffice.org/license.html. + * + * Software provided under this License is provided on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, + * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS, + * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. + * See the License for the specific provisions governing your rights and + * obligations concerning the Software. + * + * The Initial Developer of the Original Code is: Sun Microsystems, Inc. + * + * Copyright: 2000 by Sun Microsystems, Inc. + * + * All Rights Reserved. + * + * Contributor(s): _______________________________________ + * + * + ************************************************************************/ + +package com.sun.star.lib.sandbox; + +import java.applet.AudioClip; + +import java.awt.image.ImageProducer; + +import java.io.InputStream; +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; +import java.io.IOException; + +import java.net.URL; +import java.net.URLConnection; +import java.net.MalformedURLException; + +import java.util.Enumeration; +import java.util.Vector; + +import sun.awt.image.URLImageSource; +import sun.applet.AppletAudioClip; + +public class ResourceProxy implements Resource, Cachable { + private static final boolean DEBUG = false; + private static int instances; + + static boolean isResource(URL url) { + boolean exists = false; + + ResourceProxy resourceProxy = (ResourceProxy)WeakTable.get(url); + exists = resourceProxy != null; + + if(!exists) { // not cache + // Check if the resource exists. + // It almost works to just try to do an openConnection() but + // HttpURLConnection will return true on HTTP_BAD_REQUEST + // when the requested name ends in ".html", ".htm", and ".txt" + // and we want to be able to handle these + // + // Also, cannot just open a connection for things like FileURLConnection, + // because they suceed when connecting to a non-existant file. + // So, in those cases we open and close an input stream. + + + try { + URLConnection conn = url.openConnection(); + if (conn instanceof java.net.HttpURLConnection) { + java.net.HttpURLConnection hconn = (java.net.HttpURLConnection) conn; + int code = hconn.getResponseCode(); + + exists = (code == java.net.HttpURLConnection.HTTP_OK) || (code < java.net.HttpURLConnection.HTTP_BAD_REQUEST); + } + else { + // our best guess for the other cases + InputStream is = url.openStream(); + is.close(); + exists = true; + } + } + catch (Exception ex) { + } + } + + return exists; + } + + static public ResourceProxy load(URL url, ProtectionDomain protectionDomain) { + if(DEBUG) System.err.println("#### ResourceProxy.loadResource:" + url); + +// protectionDomain = (protectionDomain == null) +// ? new ProtectionDomain(new CodeSource(url), new PermissionCollection()) +// : protectionDomain; + + ResourceProxy resourceProxy = (ResourceProxy)WeakTable.get(url); + + if(resourceProxy == null) { + resourceProxy = new ResourceProxy(url, null, protectionDomain); + WeakTable.put(url, resourceProxy); + } + + return resourceProxy; + } + + static public ResourceProxy create(URL url, byte bytes[], ProtectionDomain protectionDomain) { + ResourceProxy resourceProxy = (ResourceProxy)WeakTable.get(url); + + if(resourceProxy == null) { + resourceProxy = new ResourceProxy(url, bytes, protectionDomain); + WeakTable.put(url, resourceProxy); + } + else + System.err.println("WARNING! ResourceProxy.create - resource already loaded:" + resourceProxy); + + return resourceProxy; + } + + /* + ** Members + */ + private Resource resource; + private WeakRef weakRef; + + /* + ** interface cachable methods + */ + public ResourceProxy() { + instances ++; + } + + public Object getHardObject() { + return resource; + } + + public void setWeakRef(WeakRef weakRef) { + this.resource = (Resource)weakRef.getRef(); + this.weakRef = weakRef; + + weakRef.incRefCnt(); + } + + public void finalize(){ + weakRef.decRefCnt(); + instances --; + } + + /* + ** resource methods + */ + private ResourceProxy(URL url, byte bytes[], ProtectionDomain protectionDomain) { + this(); + resource = new ResourceImpl(url, bytes, protectionDomain); + } + + public ProtectionDomain getProtectionDomain() { + return resource.getProtectionDomain(); + } + + public synchronized URL getURL() { + return resource.getURL(); + } + + public synchronized InputStream getInputStream() throws IOException { + return resource.getInputStream(); + } + + public synchronized byte[] getBytes() throws IOException { + return resource.getBytes(); + } + + public synchronized ImageProducer getImageProducer() { + ImageProducer imageProducer = resource.getImageProducer(); + + imageProducer = new ImageProducerProxy(imageProducer); + + Holder holder = (Holder)imageProducer; + holder.addCargo(this); + + return imageProducer; + } + + public synchronized AudioClip getAudioClip() { + AudioClip audioClip = resource.getAudioClip(); + + audioClip = new AudioProxy(audioClip); + + if(audioClip instanceof Holder) { + Holder holder = (Holder)audioClip; + holder.addCargo(this); + } + + return audioClip; + } + + public Object getContent() throws IOException { + Object content = resource.getContent(); + + if(content instanceof Holder) + ((Holder)content).addCargo(this); + + return content; + } + + public void loadJar(URL url) throws IOException { + resource.loadJar(url); + } +} + diff --git a/sandbox/com/sun/star/lib/sandbox/ResourceViewer.java b/sandbox/com/sun/star/lib/sandbox/ResourceViewer.java new file mode 100644 index 000000000000..ed33cb252474 --- /dev/null +++ b/sandbox/com/sun/star/lib/sandbox/ResourceViewer.java @@ -0,0 +1,132 @@ +/************************************************************************* + * + * $RCSfile: ResourceViewer.java,v $ + * + * $Revision: 1.1.1.1 $ + * + * last change: $Author: hr $ $Date: 2000-09-18 17:24:28 $ + * + * The Contents of this file are made available subject to the terms of + * either of the following licenses + * + * - GNU Lesser General Public License Version 2.1 + * - Sun Industry Standards Source License Version 1.1 + * + * Sun Microsystems Inc., October, 2000 + * + * GNU Lesser General Public License Version 2.1 + * ============================================= + * Copyright 2000 by Sun Microsystems, Inc. + * 901 San Antonio Road, Palo Alto, CA 94303, USA + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software Foundation. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, + * MA 02111-1307 USA + * + * + * Sun Industry Standards Source License Version 1.1 + * ================================================= + * The contents of this file are subject to the Sun Industry Standards + * Source License Version 1.1 (the "License"); You may not use this file + * except in compliance with the License. You may obtain a copy of the + * License at http://www.openoffice.org/license.html. + * + * Software provided under this License is provided on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, + * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS, + * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. + * See the License for the specific provisions governing your rights and + * obligations concerning the Software. + * + * The Initial Developer of the Original Code is: Sun Microsystems, Inc. + * + * Copyright: 2000 by Sun Microsystems, Inc. + * + * All Rights Reserved. + * + * Contributor(s): _______________________________________ + * + * + ************************************************************************/ + +package com.sun.star.lib.sandbox; + +import java.applet.Applet; + +import java.awt.BorderLayout; +import java.awt.Button; +import java.awt.Frame; +import java.awt.Graphics; +import java.awt.List; + +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; + +import java.util.Enumeration; + +import java.util.Observable; +import java.util.Observer; + +public class ResourceViewer extends Frame implements Observer { + List list; + boolean refill; + + public ResourceViewer() { + super("ResourceViewer"); + list = new List(); + + setLayout(new BorderLayout()); + add("Center", list); + + Button clearCashButton = new Button("clear the cache"); + clearCashButton.addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent actionEvent) { + WeakTable.clear(); + } + }); + add("South", clearCashButton); + + setSize(500, 200); + + refill = true; + + WeakTable.AddObserver(this); + + setVisible(true); + } + + void refresh() { + list.removeAll(); + + Enumeration elements = WeakTable.elements(); + while(elements.hasMoreElements()) { + WeakRef weakRef = ((WeakEntry)elements.nextElement()).weakRef; + list.add(weakRef.getRefCount() + " " + weakRef.getKey().toString()); + } + } + + public void update(Observable observable, Object arg) { + refill = true; + repaint(500); + } + + public void paint(Graphics g) { + if(refill) { + refill = false; + refresh(); + + } + super.paint(g); + } +} + diff --git a/sandbox/com/sun/star/lib/sandbox/SandboxMessageHandler.java b/sandbox/com/sun/star/lib/sandbox/SandboxMessageHandler.java new file mode 100644 index 000000000000..03e0edc5a7ab --- /dev/null +++ b/sandbox/com/sun/star/lib/sandbox/SandboxMessageHandler.java @@ -0,0 +1,150 @@ +/************************************************************************* + * + * $RCSfile: SandboxMessageHandler.java,v $ + * + * $Revision: 1.1.1.1 $ + * + * last change: $Author: hr $ $Date: 2000-09-18 17:24:28 $ + * + * The Contents of this file are made available subject to the terms of + * either of the following licenses + * + * - GNU Lesser General Public License Version 2.1 + * - Sun Industry Standards Source License Version 1.1 + * + * Sun Microsystems Inc., October, 2000 + * + * GNU Lesser General Public License Version 2.1 + * ============================================= + * Copyright 2000 by Sun Microsystems, Inc. + * 901 San Antonio Road, Palo Alto, CA 94303, USA + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software Foundation. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, + * MA 02111-1307 USA + * + * + * Sun Industry Standards Source License Version 1.1 + * ================================================= + * The contents of this file are subject to the Sun Industry Standards + * Source License Version 1.1 (the "License"); You may not use this file + * except in compliance with the License. You may obtain a copy of the + * License at http://www.openoffice.org/license.html. + * + * Software provided under this License is provided on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, + * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS, + * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. + * See the License for the specific provisions governing your rights and + * obligations concerning the Software. + * + * The Initial Developer of the Original Code is: Sun Microsystems, Inc. + * + * Copyright: 2000 by Sun Microsystems, Inc. + * + * All Rights Reserved. + * + * Contributor(s): _______________________________________ + * + * + ************************************************************************/ + +package com.sun.star.lib.sandbox; + +import java.util.ResourceBundle; +import java.util.MissingResourceException; +import java.text.MessageFormat; + +/** + * An hanlder of localized messages. + * + * @version 1.8, 03/03/97 + * @author Koji Uno + */ +class SandboxMessageHandler { + private static ResourceBundle rb; + private String baseKey = null; + + static { + try { + rb = ResourceBundle.getBundle("stardiv.security.resources.MsgAppletViewer"); + } catch (MissingResourceException e) + { + System.out.println(e.getMessage()); + } + }; + + SandboxMessageHandler(String baseKey) { + this.baseKey = baseKey; + } + + String getMessage(String key) { + return (String)rb.getString(getQualifiedKey(key)); + } + + String getMessage(String key, Object arg){ + String basemsgfmt = (String)rb.getString(getQualifiedKey(key)); + MessageFormat msgfmt = new MessageFormat(basemsgfmt); + Object msgobj[] = new Object[1]; + if (arg == null) { + arg = "null"; // mimic java.io.PrintStream.print(String) + } + msgobj[0] = arg; + return msgfmt.format(msgobj); + } + + String getMessage(String key, Object arg1, Object arg2) { + String basemsgfmt = (String)rb.getString(getQualifiedKey(key)); + MessageFormat msgfmt = new MessageFormat(basemsgfmt); + Object msgobj[] = new Object[2]; + if (arg1 == null) { + arg1 = "null"; + } + if (arg2 == null) { + arg2 = "null"; + } + msgobj[0] = arg1; + msgobj[1] = arg2; + return msgfmt.format(msgobj); + } + + String getMessage(String key, Object arg1, Object arg2, Object arg3) { + String basemsgfmt = (String)rb.getString(getQualifiedKey(key)); + MessageFormat msgfmt = new MessageFormat(basemsgfmt); + Object msgobj[] = new Object[3]; + if (arg1 == null) { + arg1 = "null"; + } + if (arg2 == null) { + arg2 = "null"; + } + if (arg3 == null) { + arg3 = "null"; + } + msgobj[0] = arg1; + msgobj[1] = arg2; + msgobj[2] = arg3; + return msgfmt.format(msgobj); + } + + String getMessage(String key, Object arg[]) { + String basemsgfmt = (String)rb.getString(getQualifiedKey(key)); + MessageFormat msgfmt = new MessageFormat(basemsgfmt); + return msgfmt.format(arg); + } + + String getQualifiedKey(String subKey) { + return baseKey + "." + subKey; + } +} + diff --git a/sandbox/com/sun/star/lib/sandbox/SandboxSecurity.java b/sandbox/com/sun/star/lib/sandbox/SandboxSecurity.java new file mode 100644 index 000000000000..f04788ca1010 --- /dev/null +++ b/sandbox/com/sun/star/lib/sandbox/SandboxSecurity.java @@ -0,0 +1,835 @@ +/************************************************************************* + * + * $RCSfile: SandboxSecurity.java,v $ + * + * $Revision: 1.1.1.1 $ + * + * last change: $Author: hr $ $Date: 2000-09-18 17:24:28 $ + * + * The Contents of this file are made available subject to the terms of + * either of the following licenses + * + * - GNU Lesser General Public License Version 2.1 + * - Sun Industry Standards Source License Version 1.1 + * + * Sun Microsystems Inc., October, 2000 + * + * GNU Lesser General Public License Version 2.1 + * ============================================= + * Copyright 2000 by Sun Microsystems, Inc. + * 901 San Antonio Road, Palo Alto, CA 94303, USA + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software Foundation. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, + * MA 02111-1307 USA + * + * + * Sun Industry Standards Source License Version 1.1 + * ================================================= + * The contents of this file are subject to the Sun Industry Standards + * Source License Version 1.1 (the "License"); You may not use this file + * except in compliance with the License. You may obtain a copy of the + * License at http://www.openoffice.org/license.html. + * + * Software provided under this License is provided on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, + * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS, + * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. + * See the License for the specific provisions governing your rights and + * obligations concerning the Software. + * + * The Initial Developer of the Original Code is: Sun Microsystems, Inc. + * + * Copyright: 2000 by Sun Microsystems, Inc. + * + * All Rights Reserved. + * + * Contributor(s): _______________________________________ + * + * + ************************************************************************/ + +package com.sun.star.lib.sandbox; + +import java.io.File; +import java.io.IOException; +import java.io.FileDescriptor; +import java.net.URL; +import java.net.InetAddress; +import java.net.UnknownHostException; +import java.util.StringTokenizer; +import java.util.Vector; +import java.util.Hashtable; +import java.security.*; + +import sun.security.provider.*; + +/** + * This class defines an applet security policy + * + * @version 1.68, 01/27/97 + */ +public class SandboxSecurity extends SecurityManager //implements SecurityManagerExtension +{ + + private static boolean debug = false; + + public final static int NETWORK_NONE = 1; + public final static int NETWORK_HOST = 2; + public final static int NETWORK_UNRESTRICTED = 3; + + private final static int PRIVELEGED_PORT = 1024; + + boolean bNoExit; + boolean initACL; + String readACL[]; + String writeACL[]; + int networkMode; + boolean bCheckSecurity; + + // where we look for identities + IdentityScope scope; + // local cache for network-loaded classes + Hashtable loadedClasses; + + public int getNetworkMode(){ return networkMode; } + + /** + * Construct and initialize. + */ + public SandboxSecurity() { + reset(); + } + + /** + * Construct and initialize. + */ + public SandboxSecurity( boolean bNoExit_ ) { + reset(); + bNoExit = bNoExit_; + } + + /** + * Reset from Properties + */ + public void reset() { + String str = System.getProperty("appletviewer.security.mode"); +// System.err.println("#### SandboxSecurity.reset:" + str); + if( str == null ) + networkMode = NETWORK_HOST; + else if( str.equals("unrestricted") ) + networkMode = NETWORK_UNRESTRICTED; + else if( str.equals("none") ) + networkMode = NETWORK_NONE; + else + networkMode = NETWORK_HOST; + +// bCheckSecurity = !Boolean.getBoolean( "stardiv.security.disableSecurity" ); + // see if security is disabled + String prop = System.getProperty("Security", "1" ); + bCheckSecurity = true; + if(prop.equals("0")) + bCheckSecurity = false; + + // see if the system scope is one we know. + IdentityScope scope = IdentityScope.getSystemScope(); + + if (scope instanceof IdentityDatabase) { + this.scope = (IdentityDatabase)scope; + debug("installing " + scope + " as the scope for signers."); + } else { + debug("no signer scope found."); + } + loadedClasses = new Hashtable(); + } + +// /** +// * True if called directly from an applet. +// */ +// boolean fromApplet() { +// return classLoaderDepth() == 1; +// } + +// /** +// * This method takes a set of signers and returns true if +// * this set of signers implies that a class is trusted. +// * In this implementation, it returns true if any of the +// * signers is a SystemIdentity which is trusted. +// */ +// protected boolean assessTrust(Object[] signers) { +// /* Remind: do we want to actually look into the scope here? */ + +// for (int i = 0; i < signers.length; i++) { + +// if (signers[i] instanceof SystemIdentity) { +// SystemIdentity sysid = (SystemIdentity)signers[i]; +// if (sysid.isTrusted()) { +// return true; +// } + +// } else if (signers[i] instanceof SystemSigner) { +// SystemSigner sysid = (SystemSigner)signers[i]; +// if (sysid.isTrusted()) { +// return true; +// } +// } +// } + +// return false; +// } + +// /** +// * True if called indirectly from an <it>untrusted</it> applet. +// */ + boolean inApplet() { + return inClassLoader(); + } + + /** + * The only variable that currently affects whether an applet can + * perform certain operations is the host it came from. + */ + public Object getSecurityContext() { + ClassLoader loader = currentClassLoader(); + + if (loader == null) { + return null; + } else + if (loader instanceof ClassContextImpl) { + ClassContext appletLoader = (ClassContextImpl)loader; + return appletLoader.getBase(); + } else { + throw(new SandboxSecurityException("getsecuritycontext.unknown")); +// return null; + } + } + + /** + * Applets are not allowed to create class loaders, or even execute any + * of ClassLoader's methods. The name of this method should be changed to + * checkClassLoaderOperation or somesuch. + */ + public synchronized void checkCreateClassLoader() { + if( bCheckSecurity && !isSecureLoader() ) { + if (classLoaderDepth() == 2) + throw(new SandboxSecurityException("checkcreateclassloader")); + } + } + + /** + * Returns true if this threadgroup is in the applet's own thread + * group. This will return false if there is no current class + * loader. + */ + protected boolean inThreadGroup(ThreadGroup g) { + ClassLoader loader = currentClassLoader(); + + /* If this class wasn't loaded by an AppletClassLoader, we have + not eay of telling, for now. */ + + if (loader instanceof ClassContextImpl) { + ClassContext appletLoader = (ClassContextImpl)loader; + ThreadGroup appletGroup = appletLoader.getThreadGroup(); + return appletGroup.parentOf(g); + } + return false; + } + + /** + * Returns true of the threadgroup of thread is in the applet's + * own threadgroup. + */ + protected boolean inThreadGroup(Thread thread) { + return inThreadGroup(thread.getThreadGroup()); + } + + /** + * Applets are not allowed to manipulate threads outside + * applet thread groups. + */ + public synchronized void checkAccess(Thread t) { + if( bCheckSecurity && !isSecureLoader() ) { + if (classLoaderDepth()==3 && (! inThreadGroup(t))) { + throw(new SandboxSecurityException("checkaccess.thread")); + } + } + } + + /** + * Applets are not allowed to manipulate thread groups outside + * applet thread groups. + */ + public synchronized void checkAccess(ThreadGroup g) { + if( bCheckSecurity && !isSecureLoader() ) { + if (classLoaderDepth() == 4 && (! inThreadGroup(g))) { + throw(new SandboxSecurityException("checkaccess.threadgroup", g.toString())); + } + } + } + + /** + * Applets are not allowed to exit the VM. + */ + public synchronized void checkExit(int status) { + if( bNoExit ) { + throw(new SandboxSecurityException("checkexit", String.valueOf(status))); + } + if( bCheckSecurity && !isSecureLoader() ) { + if( inApplet() ) { + throw(new SandboxSecurityException("checkexit", String.valueOf(status))); + } + } + } + + /** + * Applets are not allowed to fork processes. + */ + public synchronized void checkExec(String cmd) { + if( bCheckSecurity && !isSecureLoader()) { + if (inApplet()) { + throw(new SandboxSecurityException("checkexec", cmd)); + } + } + } + + /** + * Applets are not allowed to link dynamic libraries. + */ + public synchronized void checkLink(String lib) { + if( bCheckSecurity && !isSecureLoader() ) { + switch (classLoaderDepth()) { + case 2: // Runtime.load + case 3: // System.loadLibrary + throw(new SandboxSecurityException("checklink", lib)); + default: + break; + } + } + } + + /** + * Applets are not allowed to access the entire system properties + * list, only properties explicitly labeled as accessible to applets. + */ + public synchronized void checkPropertiesAccess() { + if( bCheckSecurity && !isSecureLoader() ) { + if (classLoaderDepth() == 2) { + throw(new SandboxSecurityException("checkpropsaccess")); + } + } + } + + /** + * Applets can access the system property named by <i>key</i> + * only if its twin <i>key.applet</i> property is set to true. + * For example, the property <code>java.home</code> can be read by + * applets only if <code>java.home.applet</code> is <code>true</code>. + */ + public synchronized void checkPropertyAccess(String key) { + if( bCheckSecurity && !isSecureLoader() ) { + if (classLoaderDepth() == 2) { + String prop = System.getProperty(key + ".applet"); + boolean allow = new Boolean(prop).booleanValue(); + if ( !allow ) { + throw(new SandboxSecurityException("checkpropsaccess.key", prop)); + } + } + } + } + + /** + * Parse an ACL. Deals with "~" and "+" + */ + void parseACL(Vector v, String path, String defaultPath) { + String sep = System.getProperty("path.separator"); + StringTokenizer t = new StringTokenizer(path, sep); + + while (t.hasMoreTokens()) { + String dir = t.nextToken(); + if (dir.startsWith("~")) { + v.addElement(System.getProperty("user.home") + + dir.substring(1)); + } else if (dir.equals("+")) { + if (defaultPath != null) { + parseACL(v, defaultPath, null); + } + } else { + v.addElement(dir); + } + } + } + + /** + * Parse an ACL. + */ + String[] parseACL(String path, String defaultPath) { + if (path == null) { + return new String[0]; + } + if (path.equals("*")) { + return null; + } + Vector v = new Vector(); + parseACL(v, path, defaultPath); + + String acl[] = new String[v.size()]; + v.copyInto(acl); + return acl; + } + + /** + * Initialize ACLs. Called only once. + */ + void initializeACLs() { + readACL = parseACL(System.getProperty("acl.read"), + System.getProperty("acl.read.default")); + writeACL = parseACL(System.getProperty("acl.write"), + System.getProperty("acl.write.default")); + initACL = true; + } + + /** + * Check if an applet can read a particular file. + */ + public synchronized void checkRead(String file) { + if( bCheckSecurity && !isSecureLoader() ) { + ClassLoader loader = currentClassLoader(); + + /* If no class loader, it's a system class. */ + if (loader == null) + return; + + /* If not an AppletClassLoader, we don't know what to do */ + if (! (loader instanceof ClassContextImpl)) + throw(new SandboxSecurityException("checkread.unknown", file)); + ClassContext appletLoader = (ClassContextImpl)loader; + URL base = appletLoader.getBase(); + checkRead(file, base); + } + } + + public synchronized void checkRead(String file, URL base) { + if( bCheckSecurity && (base != null) && !isSecureLoader() ) { + if (!initACL) + initializeACLs(); + if (readACL == null) + return; + + String realPath = null; + try { + realPath = (new File(file)).getCanonicalPath(); + } catch (IOException e) { + throw(new SandboxSecurityException("checkread.exception1", e.getMessage(), file)); + } + + for (int i = readACL.length ; i-- > 0 ;) { + if (realPath.startsWith(readACL[i])) + return; + } + + // if the applet is loaded from a file URL, allow reading + // in that directory + if (base.getProtocol().equals("file")) { + String dir = null; + try { + dir = (new File(base.getFile()).getCanonicalPath()); + } catch (IOException e) { // shouldn't happen + throw(new SandboxSecurityException("checkread.exception2", e.toString())); + } + if (realPath.startsWith(dir)) + return; + } + throw new SandboxSecurityException("checkread", file, realPath); + } + } + + /** + * Checks to see if the current context or the indicated context are + * both allowed to read the given file name. + * @param file the system dependent file name + * @param context the alternate execution context which must also + * be checked + * @exception SecurityException If the file is not found. + */ + public void checkRead(String file, Object context) { + checkRead(file); + if (context != null) + checkRead(file, (URL) context); + } + + /** + * Check if an applet can write a particular file. + */ + public synchronized void checkWrite(String file) { + if( bCheckSecurity && inApplet() && !isSecureLoader() ) { + if (!initACL) + initializeACLs(); + if (writeACL == null) + return; + + String realPath = null; + try { + realPath = (new File(file)).getCanonicalPath(); + } catch (IOException e) { + throw(new SandboxSecurityException("checkwrite.exception", e.getMessage(), file)); + } + + for (int i = writeACL.length ; i-- > 0 ;) { + if (realPath.startsWith(writeACL[i])) + return; + } + throw(new SandboxSecurityException("checkwrite", file, realPath)); + } + } + + /** + * Applets are not allowed to open file descriptors unless + * it is done through a socket, in which case other access + * restrictions still apply. + */ + public synchronized void checkRead(FileDescriptor fd) { + if( bCheckSecurity && !isSecureLoader() ) { + if( (inApplet() && !inClass("java.net.SocketInputStream") ) || (!fd.valid()) ) + throw(new SandboxSecurityException("checkread.fd")); + } + } + + /** + * Applets are not allowed to open file descriptors unless + * it is done through a socket, in which case other access + * restrictions still apply. + */ + public synchronized void checkWrite(FileDescriptor fd) { + if( bCheckSecurity && !isSecureLoader() ) { + if( (inApplet() && !inClass("java.net.SocketOutputStream")) || (!fd.valid()) ) + throw(new SandboxSecurityException("checkwrite.fd")); + } + } + + /** + * Applets can only listen on unpriveleged ports > 1024 + * A port of 0 denotes an ephemeral system-assigned port + * Which will be outside this range. Note that java sockets + * take an int and ports are really a u_short, but range + * checking is done in ServerSocket & DatagramSocket, so the port policy + * cannot be subverted by ints that wrap around to an illegal u_short. + */ + public synchronized void checkListen(int port) { + if( bCheckSecurity && !isSecureLoader() ) { + if (inApplet() && port > 0 && port < PRIVELEGED_PORT) + throw(new SandboxSecurityException("checklisten", String.valueOf(port))); + } + } + + /** + * Applets can accept connectionions on unpriveleged ports, from + * any hosts they can also connect to (typically host-of-origin + * only, depending on the network security setting). + */ + public synchronized void checkAccept(String host, int port) { + if( bCheckSecurity && !isSecureLoader() ) { + if( inApplet() && port < PRIVELEGED_PORT ) + throw(new SandboxSecurityException("checkaccept", host, String.valueOf(port))); + checkConnect(host, port); + } + } + + /** + * Check if an applet can connect to the given host:port. + */ + public synchronized void checkConnect(String host, int port) { + if(bCheckSecurity && !isSecureLoader() ) { + ClassLoader loader = currentClassLoader(); + if (loader == null) + return; // Not called from an applet, so it is ok + + // REMIND: This is only appropriate for our protocol handlers. + int depth = classDepth("sun.net.www.http.HttpClient"); + if (depth > 1) + return; // Called through our http protocol handler + + if(getInCheck()) + return; + + if (loader instanceof ClassContextImpl) { + ClassContext appletLoader = (ClassContextImpl)loader; + checkConnect(appletLoader.getBase().getHost(), host); + } else { + throw(new SandboxSecurityException("checkconnect.unknown")); + } + } + } + + /** + * Checks to see if the applet and the indicated execution context + * are both allowed to connect to the indicated host and port. + */ + public void checkConnect(String host, int port, Object context) { + checkConnect(host, port); + if (context != null) + checkConnect(((URL) context).getHost(), host); + } + + public synchronized void checkConnect(String fromHost, String toHost, boolean trustP) { + if( bCheckSecurity && !isSecureLoader() ) { + if (fromHost == null) + return; + + switch (networkMode) { + case NETWORK_NONE: + throw(new SandboxSecurityException("checkconnect.networknone", fromHost, toHost)); + + case NETWORK_HOST: + /* + * The policy here is as follows: + * + * - if the strings match, and we know the IP address for it + * we allow the connection. The calling code downstream will + * substitute the IP in their request to the proxy if needed. + * - if the strings don't match, and we can get the IP of + * both hosts then + * - if the IPs match, we allow the connection + * - if they don't we throw(an exception + * - if the string match works and we don't know the IP address + * then we consult the trustProxy property, and if that is true, + * we allow the connection. + * set inCheck so InetAddress knows it doesn't have to + * check security. + */ + try { + inCheck = true; + InetAddress toHostAddr, fromHostAddr; + if (!fromHost.equals(toHost)) { + try { + // the only time we allow non-matching strings + // is when IPs and the IPs match. + toHostAddr = InetAddress.getByName(toHost); + fromHostAddr = InetAddress.getByName(fromHost); + + if( fromHostAddr.equals(toHostAddr) ) + return; + else + throw(new SandboxSecurityException("checkconnect.networkhost1", toHost, fromHost)); + + } catch (UnknownHostException e) { + throw(new SecurityException("checkconnect.networkhost2" + toHost + fromHost)); +// throw(new SandboxSecurityException("checkconnect.networkhost2", toHost, fromHost)); + } + } else { + try { + toHostAddr = InetAddress.getByName(toHost); + + // strings match: if we have IP, we're homefree, + // otherwise we check the properties. + return; + // getBoolean really defaults to false. + } catch (UnknownHostException e) { + if( trustP ) + return; + else + throw(new SandboxSecurityException("checkconnect.networkhost3", toHost)); + } + } + } finally { + inCheck = false; + } + + case NETWORK_UNRESTRICTED: + return; + } + throw(new SandboxSecurityException("checkconnect", fromHost, toHost)); + } + } + + + + /** + * Check if an applet from a host can connect to another + * host. This usually means that you need to determine whether + * the hosts are inside or outside the firewall. For now applets + * can only access the host they came from. + */ + public synchronized void checkConnect(String fromHost, String toHost) { + checkConnect(fromHost, toHost, Boolean.getBoolean("trustProxy")); + } + + /** + * Checks to see if top-level windows can be created by the caller. + */ + public synchronized boolean checkTopLevelWindow(Object window) { + if( bCheckSecurity && inClassLoader() && !isSecureLoader() ) { + /* XXX: this used to return depth > 3. However, this lets */ + /* some applets create frames without warning strings. */ + return false; + } + return true; + } + + /** + * Check if an applet can access a package. + */ + public synchronized void checkPackageAccess(String pkg) { + if( bCheckSecurity && inClassLoader() && !isSecureLoader() ) { + if( pkg.equals( "stardiv.applet" ) + // Das AWT von StarDivision + || pkg.equals( "stardiv.look" ) + || pkg.equals( "netscape.javascript" ) ) + return; + + final String forbidden[] = new String[]{ + "com.sun.star.uno", + "com.sun.star.lib.uno", + "com.sun.star.comp.connections", + "com.sun.star.comp.loader", + "com.sun.star.comp.servicemanager" + }; + + + for(int j = 0; j < forbidden.length; ++ j) { + if(pkg.startsWith(forbidden[j])) + throw(new SandboxSecurityException("checkpackageaccess2", pkg)); + } + + int i = pkg.indexOf('.'); + while (i > 0) { + String subpkg = pkg.substring(0,i); + if( Boolean.getBoolean("package.restrict.access." + subpkg) ) + throw(new SandboxSecurityException("checkpackageaccess", pkg)); + i = pkg.indexOf('.',i+1); + } + } + } + + /** + * Check if an applet can define classes in a package. + */ + public synchronized void checkPackageDefinition(String pkg) { + return; +/* + if (!inClassLoader()) + return; + int i = pkg.indexOf('.'); + + while (i > 0) { + String subpkg = pkg.substring(0,i); + if (Boolean.getBoolean("package.restrict.definition." + subpkg)) { + throw(new SandboxSecurityException("checkpackagedefinition", pkg); + } + i = pkg.indexOf('.',i+1); + } +*/ + } + + + /** + * Check if an applet can set a networking-related object factory. + */ + public synchronized void checkSetFactory() { + if( bCheckSecurity && inApplet() && !isSecureLoader() ) + throw(new SandboxSecurityException("cannotsetfactory")); + } + + /** + * Check if client is allowed to reflective access to a member or + * a set of members for the specified class. Once initial access + * is granted, the reflected members can be queried for + * identifying information, but can only be <strong>used</strong> + * (via get, set, invoke, or newInstance) with standard Java + * language access control. + * + * <p>The policy is to deny <em>untrusted</em> clients access to + * <em>declared</em> members of classes other than those loaded + * via the same class loader. All other accesses are granted. + * + * XXX: Should VerifyClassAccess here? Should Class.forName do it? + */ + public void checkMemberAccess(Class clazz, int which) { + if( bCheckSecurity && !isSecureLoader() ) { + if( which != java.lang.reflect.Member.PUBLIC ) { + ClassLoader currentLoader = currentClassLoader(); + if( currentLoader != null && (classLoaderDepth() <= 3) ) + /* Client is an untrusted class loaded by currentLoader */ + if( currentLoader != clazz.getClassLoader() ) + throw(new SandboxSecurityException("checkmemberaccess")); + } + } + } + + /** + * Checks to see if an applet can initiate a print job request. + */ + public void checkPrintJobAccess() { + if( bCheckSecurity && inApplet() && !isSecureLoader() ) + throw(new SandboxSecurityException("checkgetprintjob")); + } + + /** + * Checks to see if an applet can get System Clipboard access. + */ + public void checkSystemClipboardAccess() { + if( bCheckSecurity && inApplet() && !isSecureLoader() ) + throw(new SandboxSecurityException("checksystemclipboardaccess")); + } + + /** + * Checks to see if an applet can get EventQueue access. + */ + public void checkAwtEventQueueAccess() { + if( bCheckSecurity && inClassLoader() && !isSecureLoader() ) { +// throw(new SandboxSecurityException("checkawteventqueueaccess")); + } + } + + /** + * Checks to see if an applet can perform a given operation. + */ + public void checkSecurityAccess(String action) { + if( bCheckSecurity && inApplet() && !isSecureLoader() ) + throw(new SandboxSecurityException("checksecurityaccess", action)); + } + + /** + * Returns the thread group of the applet. We consult the classloader + * if there is one. + */ + public ThreadGroup getThreadGroup() { + /* First we check if any classloaded thing is on the stack. */ + ClassLoader loader = currentClassLoader(); + if (loader != null && (loader instanceof ClassContextImpl)) { + if( inThreadGroup( Thread.currentThread() ) ) + return Thread.currentThread().getThreadGroup(); + ClassContextImpl appletLoader = (ClassContextImpl)loader; + return appletLoader.getThreadGroup(); + } else + return super.getThreadGroup(); + } + + public void debug(String s) { + if( debug ) + System.err.println(s); + } + + private boolean isSecureLoader() { + ClassLoader loader = currentClassLoader(); + if (loader != null) { + if (loader instanceof ClassContextImpl) { + return !((ClassContextImpl) loader).checkSecurity(); + } else { + return true; // fremder ClassLoader: kann machen was er will + } + } else { + return true; + } + } +} + diff --git a/sandbox/com/sun/star/lib/sandbox/SandboxSecurityException.java b/sandbox/com/sun/star/lib/sandbox/SandboxSecurityException.java new file mode 100644 index 000000000000..781d81f80998 --- /dev/null +++ b/sandbox/com/sun/star/lib/sandbox/SandboxSecurityException.java @@ -0,0 +1,102 @@ +/************************************************************************* + * + * $RCSfile: SandboxSecurityException.java,v $ + * + * $Revision: 1.1.1.1 $ + * + * last change: $Author: hr $ $Date: 2000-09-18 17:24:28 $ + * + * The Contents of this file are made available subject to the terms of + * either of the following licenses + * + * - GNU Lesser General Public License Version 2.1 + * - Sun Industry Standards Source License Version 1.1 + * + * Sun Microsystems Inc., October, 2000 + * + * GNU Lesser General Public License Version 2.1 + * ============================================= + * Copyright 2000 by Sun Microsystems, Inc. + * 901 San Antonio Road, Palo Alto, CA 94303, USA + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software Foundation. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, + * MA 02111-1307 USA + * + * + * Sun Industry Standards Source License Version 1.1 + * ================================================= + * The contents of this file are subject to the Sun Industry Standards + * Source License Version 1.1 (the "License"); You may not use this file + * except in compliance with the License. You may obtain a copy of the + * License at http://www.openoffice.org/license.html. + * + * Software provided under this License is provided on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, + * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS, + * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. + * See the License for the specific provisions governing your rights and + * obligations concerning the Software. + * + * The Initial Developer of the Original Code is: Sun Microsystems, Inc. + * + * Copyright: 2000 by Sun Microsystems, Inc. + * + * All Rights Reserved. + * + * Contributor(s): _______________________________________ + * + * + ************************************************************************/ + +package com.sun.star.lib.sandbox; + +/** + * An applet security exception. + * + * @version 1.6, 11/23/96 + * @author Arthur van Hoff + */ +public class SandboxSecurityException extends SecurityException { + private String key = null; + private Object msgobj[] = null; + + public SandboxSecurityException(String name) { + super(name); + this.key = name; + } + + public SandboxSecurityException(String name, String arg) { + this(name); + msgobj = new Object[1]; + msgobj[0] = (Object)arg; + } + + public SandboxSecurityException(String name, String arg1, String arg2) { + this(name); + msgobj = new Object[2]; + msgobj[0] = (Object)arg1; + msgobj[1] = (Object)arg2; + } + + public String getLocalizedMessage() { + if( msgobj != null) + return amh.getMessage(key, msgobj); + else + return amh.getMessage(key); + } + + private static SandboxMessageHandler amh = new SandboxMessageHandler("appletsecurityexception"); + +} + diff --git a/sandbox/com/sun/star/lib/sandbox/SandboxThreadGroup.java b/sandbox/com/sun/star/lib/sandbox/SandboxThreadGroup.java new file mode 100644 index 000000000000..f343f9ec5966 --- /dev/null +++ b/sandbox/com/sun/star/lib/sandbox/SandboxThreadGroup.java @@ -0,0 +1,94 @@ +/************************************************************************* + * + * $RCSfile: SandboxThreadGroup.java,v $ + * + * $Revision: 1.1.1.1 $ + * + * last change: $Author: hr $ $Date: 2000-09-18 17:24:28 $ + * + * The Contents of this file are made available subject to the terms of + * either of the following licenses + * + * - GNU Lesser General Public License Version 2.1 + * - Sun Industry Standards Source License Version 1.1 + * + * Sun Microsystems Inc., October, 2000 + * + * GNU Lesser General Public License Version 2.1 + * ============================================= + * Copyright 2000 by Sun Microsystems, Inc. + * 901 San Antonio Road, Palo Alto, CA 94303, USA + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software Foundation. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, + * MA 02111-1307 USA + * + * + * Sun Industry Standards Source License Version 1.1 + * ================================================= + * The contents of this file are subject to the Sun Industry Standards + * Source License Version 1.1 (the "License"); You may not use this file + * except in compliance with the License. You may obtain a copy of the + * License at http://www.openoffice.org/license.html. + * + * Software provided under this License is provided on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, + * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS, + * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. + * See the License for the specific provisions governing your rights and + * obligations concerning the Software. + * + * The Initial Developer of the Original Code is: Sun Microsystems, Inc. + * + * Copyright: 2000 by Sun Microsystems, Inc. + * + * All Rights Reserved. + * + * Contributor(s): _______________________________________ + * + * + ************************************************************************/ + +package com.sun.star.lib.sandbox; + +public class SandboxThreadGroup extends ThreadGroup { + private static int instances; + private Object context = null; + + public SandboxThreadGroup(String name, Object context) { + this(Thread.currentThread().getThreadGroup(), name, context); + } + + public SandboxThreadGroup(ThreadGroup parent, String name, Object context) { + super(parent, name); + + instances ++; + + setMaxPriority(Thread.NORM_PRIORITY - 1); + + this.context = context; + } + + public Object getContext() { + return context; + } + + public void dispose() { + context = null; + } + + public void finalize() { + instances --; + } +} + diff --git a/sandbox/com/sun/star/lib/sandbox/WeakEntry.java b/sandbox/com/sun/star/lib/sandbox/WeakEntry.java new file mode 100644 index 000000000000..2a3a3d889797 --- /dev/null +++ b/sandbox/com/sun/star/lib/sandbox/WeakEntry.java @@ -0,0 +1,77 @@ +/************************************************************************* + * + * $RCSfile: WeakEntry.java,v $ + * + * $Revision: 1.1.1.1 $ + * + * last change: $Author: hr $ $Date: 2000-09-18 17:24:28 $ + * + * The Contents of this file are made available subject to the terms of + * either of the following licenses + * + * - GNU Lesser General Public License Version 2.1 + * - Sun Industry Standards Source License Version 1.1 + * + * Sun Microsystems Inc., October, 2000 + * + * GNU Lesser General Public License Version 2.1 + * ============================================= + * Copyright 2000 by Sun Microsystems, Inc. + * 901 San Antonio Road, Palo Alto, CA 94303, USA + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software Foundation. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, + * MA 02111-1307 USA + * + * + * Sun Industry Standards Source License Version 1.1 + * ================================================= + * The contents of this file are subject to the Sun Industry Standards + * Source License Version 1.1 (the "License"); You may not use this file + * except in compliance with the License. You may obtain a copy of the + * License at http://www.openoffice.org/license.html. + * + * Software provided under this License is provided on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, + * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS, + * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. + * See the License for the specific provisions governing your rights and + * obligations concerning the Software. + * + * The Initial Developer of the Original Code is: Sun Microsystems, Inc. + * + * Copyright: 2000 by Sun Microsystems, Inc. + * + * All Rights Reserved. + * + * Contributor(s): _______________________________________ + * + * + ************************************************************************/ + +package com.sun.star.lib.sandbox; + +class WeakEntry { + Class weakClass; + WeakRef weakRef; + + public WeakEntry(Class weakClass, WeakRef weakRef) { + this.weakClass = weakClass; + this.weakRef = weakRef; + } + + public String toString() { + return (weakRef == null) ? "null" : weakRef.toString(); + } +} + diff --git a/sandbox/com/sun/star/lib/sandbox/WeakRef.java b/sandbox/com/sun/star/lib/sandbox/WeakRef.java new file mode 100644 index 000000000000..2ed3b25c0a29 --- /dev/null +++ b/sandbox/com/sun/star/lib/sandbox/WeakRef.java @@ -0,0 +1,111 @@ +/************************************************************************* + * + * $RCSfile: WeakRef.java,v $ + * + * $Revision: 1.1.1.1 $ + * + * last change: $Author: hr $ $Date: 2000-09-18 17:24:28 $ + * + * The Contents of this file are made available subject to the terms of + * either of the following licenses + * + * - GNU Lesser General Public License Version 2.1 + * - Sun Industry Standards Source License Version 1.1 + * + * Sun Microsystems Inc., October, 2000 + * + * GNU Lesser General Public License Version 2.1 + * ============================================= + * Copyright 2000 by Sun Microsystems, Inc. + * 901 San Antonio Road, Palo Alto, CA 94303, USA + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software Foundation. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, + * MA 02111-1307 USA + * + * + * Sun Industry Standards Source License Version 1.1 + * ================================================= + * The contents of this file are subject to the Sun Industry Standards + * Source License Version 1.1 (the "License"); You may not use this file + * except in compliance with the License. You may obtain a copy of the + * License at http://www.openoffice.org/license.html. + * + * Software provided under this License is provided on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, + * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS, + * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. + * See the License for the specific provisions governing your rights and + * obligations concerning the Software. + * + * The Initial Developer of the Original Code is: Sun Microsystems, Inc. + * + * Copyright: 2000 by Sun Microsystems, Inc. + * + * All Rights Reserved. + * + * Contributor(s): _______________________________________ + * + * + ************************************************************************/ + +package com.sun.star.lib.sandbox; + +public class WeakRef { + static private final boolean DEBUG = false; + + private int refCnt; + private Object ref; + private Object key; + + WeakRef(Object key, Object ref) { + this.key = key; + this.ref = ref; + } + + public Object getRef() { + return ref; + } + + public Object getKey() { + return key; + } + + int getRefCount() { + return refCnt; + } + + // the following two methods where synchronized, but need not to be + public void incRefCnt() { + refCnt ++; + } + + public synchronized void decRefCnt() { + refCnt --; + if(refCnt <= 0) { + WeakTable.remove(key); + + if(DEBUG)System.err.println("#### WeakRef - object freeed:" + key + " " + ref); + if(ref instanceof Disposable) { + ((Disposable)ref).dispose(); + } + + ref = null; + } + } + + public String toString() { + return "WeakRef - " + key + " " + ((ref == null) ? "null" : ref.toString()); + } +} + diff --git a/sandbox/com/sun/star/lib/sandbox/WeakTable.java b/sandbox/com/sun/star/lib/sandbox/WeakTable.java new file mode 100644 index 000000000000..4bfa39f1ea81 --- /dev/null +++ b/sandbox/com/sun/star/lib/sandbox/WeakTable.java @@ -0,0 +1,178 @@ +/************************************************************************* + * + * $RCSfile: WeakTable.java,v $ + * + * $Revision: 1.1.1.1 $ + * + * last change: $Author: hr $ $Date: 2000-09-18 17:24:28 $ + * + * The Contents of this file are made available subject to the terms of + * either of the following licenses + * + * - GNU Lesser General Public License Version 2.1 + * - Sun Industry Standards Source License Version 1.1 + * + * Sun Microsystems Inc., October, 2000 + * + * GNU Lesser General Public License Version 2.1 + * ============================================= + * Copyright 2000 by Sun Microsystems, Inc. + * 901 San Antonio Road, Palo Alto, CA 94303, USA + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software Foundation. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, + * MA 02111-1307 USA + * + * + * Sun Industry Standards Source License Version 1.1 + * ================================================= + * The contents of this file are subject to the Sun Industry Standards + * Source License Version 1.1 (the "License"); You may not use this file + * except in compliance with the License. You may obtain a copy of the + * License at http://www.openoffice.org/license.html. + * + * Software provided under this License is provided on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, + * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS, + * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. + * See the License for the specific provisions governing your rights and + * obligations concerning the Software. + * + * The Initial Developer of the Original Code is: Sun Microsystems, Inc. + * + * Copyright: 2000 by Sun Microsystems, Inc. + * + * All Rights Reserved. + * + * Contributor(s): _______________________________________ + * + * + ************************************************************************/ + +package com.sun.star.lib.sandbox; + +import java.lang.reflect.Method; + +import java.util.Hashtable; +import java.util.Observable; +import java.util.Observer; + +public class WeakTable extends Observable { + private static final boolean DEBUG = false; + + private static final void DEBUG(String dbg) { + if (DEBUG) + System.err.println(">>> com.sun.star.lib.sandbox.WeakTable - " + dbg); + } + + static WeakTable weakTable = new WeakTable(); + + public Hashtable hash = new Hashtable(); + + synchronized private void pput(Object key, Cachable cachable) { + DEBUG("put:" + key + " " + cachable); + + synchronized(hash) { + Object hardObject = cachable.getHardObject(); + Class weakClass = cachable.getClass(); + + WeakRef weakRef = new WeakRef(key, hardObject); + cachable.setWeakRef(weakRef); + + hash.put(key, new WeakEntry(weakClass, weakRef)); + } + setChanged(); + notifyObservers(); + } + + synchronized private Cachable pget(Object key) { + DEBUG("get:" + key); + + String error = null; + + Cachable cachable = null; + + synchronized(hash) { + WeakEntry weakEntry = (WeakEntry)hash.get(key); + if(weakEntry != null) { + try { + // Class sig[] = new Class[1]; + // sig[0] = weakRef.getClass(); + // Method method = weakClass.getMethod("<init>", sig); + + cachable = (Cachable)weakEntry.weakClass.newInstance(); + cachable.setWeakRef(weakEntry.weakRef); + } + catch(IllegalAccessException e) { + error = "#### WeakTable.get:" + e; + } + catch(InstantiationException e) { + error = "#### WeakTable.get:" + e; + } + } + } + if(error != null) + System.err.println(error); + + return cachable; + } + + synchronized private void premove(Object key) { + hash.remove(key); + + setChanged(); + notifyObservers(); + } + + synchronized private void pclear() { + hash.clear(); + + setChanged(); + notifyObservers(); + } + + public void addObserver(Observer observer) { + super.addObserver(observer); + + observer.update(this, null); + } + + public static void put(Object key, Cachable cachable) { + weakTable.pput(key, cachable); + } + + public static Cachable get(Object key) { + return weakTable.pget(key); + } + + public static void remove(Object key) { + weakTable.premove(key); + } + + public static void AddObserver(Observer observer) { + weakTable.addObserver(observer); + } + + public static void DeleteObserver(Observer observer) { + weakTable.deleteObserver(observer); + } + + static void clear() { + weakTable.pclear(); + } + + static java.util.Enumeration elements() { + return weakTable.hash.elements(); + } +} + diff --git a/sandbox/com/sun/star/lib/sandbox/XImage.java b/sandbox/com/sun/star/lib/sandbox/XImage.java new file mode 100644 index 000000000000..848ae2b7efc0 --- /dev/null +++ b/sandbox/com/sun/star/lib/sandbox/XImage.java @@ -0,0 +1,101 @@ +/************************************************************************* + * + * $RCSfile: XImage.java,v $ + * + * $Revision: 1.1.1.1 $ + * + * last change: $Author: hr $ $Date: 2000-09-18 17:24:28 $ + * + * The Contents of this file are made available subject to the terms of + * either of the following licenses + * + * - GNU Lesser General Public License Version 2.1 + * - Sun Industry Standards Source License Version 1.1 + * + * Sun Microsystems Inc., October, 2000 + * + * GNU Lesser General Public License Version 2.1 + * ============================================= + * Copyright 2000 by Sun Microsystems, Inc. + * 901 San Antonio Road, Palo Alto, CA 94303, USA + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software Foundation. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, + * MA 02111-1307 USA + * + * + * Sun Industry Standards Source License Version 1.1 + * ================================================= + * The contents of this file are subject to the Sun Industry Standards + * Source License Version 1.1 (the "License"); You may not use this file + * except in compliance with the License. You may obtain a copy of the + * License at http://www.openoffice.org/license.html. + * + * Software provided under this License is provided on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, + * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS, + * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. + * See the License for the specific provisions governing your rights and + * obligations concerning the Software. + * + * The Initial Developer of the Original Code is: Sun Microsystems, Inc. + * + * Copyright: 2000 by Sun Microsystems, Inc. + * + * All Rights Reserved. + * + * Contributor(s): _______________________________________ + * + * + ************************************************************************/ + +package com.sun.star.lib.sandbox; + +import java.awt.Color; +import java.awt.Graphics; +import java.awt.Rectangle; + +import java.awt.image.ImageObserver; +import java.awt.image.ImageProducer; + +public interface XImage { + public void addWatcher(ImageObserver observer); + public boolean isWatcher(ImageObserver observer); + public void removeWatcher(ImageObserver observer); + public void notifyWatchers(Rectangle refreshed); + + public int getWidth(ImageObserver observer); + public int getHeight(ImageObserver observer); + public Object getProperty(String name, ImageObserver observer); + public boolean prepare(int w, int h, ImageObserver o); + public int check(int w, int h, ImageObserver o); + + public Graphics getGraphics(); + + public ImageProducer getSource(); + + public void flush(); + + public boolean drawOn(int xGraphicsRef, int xDeviceRef, + Color bgColor, + ImageObserver observer, + int dx1, int dy1, int dx2, int dy2, + int sx1, int sy1, int sx2, int sy2); + + public boolean drawOn(int xGraphicsRef, int xDeviceRef, int x, int y, ImageObserver observer); + + public boolean drawOn(int xGraphicsRef, int xDeviceRef, int x, int y, java.awt.Color bgColor, ImageObserver observer); + public boolean drawOn(int xGraphicsRef, int xDeviceRef, int x, int y, int width, int height, Color bgColor, ImageObserver observer); + public boolean drawOn(int xGraphicsRef, int xDeviceRef, int x, int y, int width, int height, ImageObserver observer); +} + diff --git a/sandbox/com/sun/star/lib/sandbox/makefile.mk b/sandbox/com/sun/star/lib/sandbox/makefile.mk new file mode 100644 index 000000000000..bf250c9f6e6d --- /dev/null +++ b/sandbox/com/sun/star/lib/sandbox/makefile.mk @@ -0,0 +1,118 @@ +#************************************************************************* +# +# $RCSfile: makefile.mk,v $ +# +# $Revision: 1.1.1.1 $ +# +# last change: $Author: hr $ $Date: 2000-09-18 17:24:28 $ +# +# The Contents of this file are made available subject to the terms of +# either of the following licenses +# +# - GNU Lesser General Public License Version 2.1 +# - Sun Industry Standards Source License Version 1.1 +# +# Sun Microsystems Inc., October, 2000 +# +# GNU Lesser General Public License Version 2.1 +# ============================================= +# Copyright 2000 by Sun Microsystems, Inc. +# 901 San Antonio Road, Palo Alto, CA 94303, USA +# +# This library is free software; you can redistribute it and/or +# modify it under the terms of the GNU Lesser General Public +# License version 2.1, as published by the Free Software Foundation. +# +# This library is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# Lesser General Public License for more details. +# +# You should have received a copy of the GNU Lesser General Public +# License along with this library; if not, write to the Free Software +# Foundation, Inc., 59 Temple Place, Suite 330, Boston, +# MA 02111-1307 USA +# +# +# Sun Industry Standards Source License Version 1.1 +# ================================================= +# The contents of this file are subject to the Sun Industry Standards +# Source License Version 1.1 (the "License"); You may not use this file +# except in compliance with the License. You may obtain a copy of the +# License at http://www.openoffice.org/license.html. +# +# Software provided under this License is provided on an "AS IS" basis, +# WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, +# WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS, +# MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. +# See the License for the specific provisions governing your rights and +# obligations concerning the Software. +# +# The Initial Developer of the Original Code is: Sun Microsystems, Inc. +# +# Copyright: 2000 by Sun Microsystems, Inc. +# +# All Rights Reserved. +# +# Contributor(s): _______________________________________ +# +# +# +#************************************************************************* + +PRJ = ..$/..$/..$/..$/.. +PRJNAME = sandbox +TARGET = lib_sandbox +PACKAGE = com$/sun$/star$/lib$/sandbox + +# --- Settings ----------------------------------------------------- + +.INCLUDE : $(PRJ)$/util$/makefile.pmk + +JARFILES= + +# --- Files -------------------------------------------------------- + +# WORKAROUND FOR #77482# +JAVAFLAGS+=$(JAVAFLAGSDEBUG) + +JAVAFILES= \ + AudioProxy.java \ + Cachable.java \ + ClassContext.java \ + ClassContextImpl.java \ + ClassContextProxy.java \ + CodeSource.java \ + Disposable.java \ + ExecutionContext.java \ + FilePermission.java \ + Holder.java \ + ImageProducerProxy.java \ + JarEntry.java \ + JarInputStream.java \ + Permission.java \ + PermissionCollection.java \ + ProtectionDomain.java \ + Resource.java \ + ResourceImpl.java \ + ResourceProxy.java \ + ResourceViewer.java \ + RuntimePermission.java \ + SandboxMessageHandler.java \ + SandboxThreadGroup.java \ + SandboxSecurity.java \ + SandboxSecurityException.java \ + SocketPermission.java \ + WeakRef.java \ + WeakTable.java \ + WeakEntry.java \ + XImage.java + +JAVACLASSFILES = $(foreach,i,$(JAVAFILES) $(CLASSDIR)$/$(PACKAGE)$/$(i:b).class) + +RC_SUBDIRSDEPS=$(JAVATARGET) + +# --- Targets ------------------------------------------------------ + +.INCLUDE : target.mk + |