001 package com.croftsoft.apps.vaft.security; 002 003 import java.io.FileDescriptor; 004 import java.net.InetAddress; 005 006 import com.croftsoft.core.security.manager.UntrustedSecurityManager; 007 008 /********************************************************************* 009 * A subclass of <I>UntrustedSecurityManager</I> that overrides 010 * some restrictions. 011 * 012 * <P> 013 * 014 * @author 015 * <A HREF="http://www.alumni.caltech.edu/~croft">David W. Croft</A> 016 * @version 017 * 1998-04-26 018 *********************************************************************/ 019 020 public class HostSecurityManager extends UntrustedSecurityManager 021 ////////////////////////////////////////////////////////////////////// 022 ////////////////////////////////////////////////////////////////////// 023 { 024 025 public static final String [ ] PACKAGES_FORBIDDEN 026 = { "java.", 027 "javax.", 028 "sun.", 029 "com.sun.", 030 "com.orbs.pub.app.vaft." 031 }; 032 033 ////////////////////////////////////////////////////////////////////// 034 // Check methods 035 ////////////////////////////////////////////////////////////////////// 036 037 // There may be a problem with classloaders for classes loaded from 038 // different URLs but using the same class names. 039 040 /********************************************************************* 041 * Allows the agent to use classes from the packages "java.lang", 042 * "java.io", and the "vaft.*" hierarchy. All other classes are 043 * forbidden. 044 *********************************************************************/ 045 public void checkPackageAccess ( String pkg ) 046 ////////////////////////////////////////////////////////////////////// 047 { 048 if ( pkg.equals ( "java.lang" ) ) return; 049 if ( pkg.equals ( "java.io" ) ) return; 050 if ( pkg.startsWith ( "com.orbs.pub.app.agent.vaft." ) ) return; 051 super.checkPackageAccess ( pkg ); 052 } 053 054 /********************************************************************* 055 * Prevents any thread, trusted or untrusted, from creating new 056 * classes within the following package hierarchies: 057 * <UL> 058 * <LI> java.* 059 * <LI> javax.* 060 * <LI> sun.* 061 * <LI> com.sun.* 062 * <LI> com.orbs.pub.app.vaft.* 063 * </UL> 064 *********************************************************************/ 065 public void checkPackageDefinition ( String pkg ) 066 ////////////////////////////////////////////////////////////////////// 067 { 068 for ( int i = 0; i < PACKAGES_FORBIDDEN.length; i++ ) 069 { 070 if ( pkg.startsWith ( PACKAGES_FORBIDDEN [ i ] ) ) 071 throw new SecurityException ( pkg ); 072 } 073 super.checkPackageDefinition ( pkg ); 074 } 075 076 ////////////////////////////////////////////////////////////////////// 077 ////////////////////////////////////////////////////////////////////// 078 }