@ Override protected PermissionCollection getPermissions ( CodeSource codesource ) { final PermissionCollection perms = super . getPermissions ( codesource ) ; final URL url = codesource . getLocation ( ) ; Permission permission ; URLConnection urlConnection ; try { urlConnection = url . openConnection ( ) ; permission = urlConnection . getPermission ( ) ; } catch ( IOException ioe ) { permission = null ; urlConnection = null ; } if ( ( permission != null ) && ( permission instanceof FilePermission ) ) { // if the permission has a separator char on the end, // it means the codebase is a directory, and we need // to add an additional permission to read recursively String path = permission . getName ( ) ; if ( path . endsWith ( File . separator ) ) { path += "-" ; //$NON-NLS-1$ permission = new FilePermission ( path , sun . security . util . SecurityConstants . FILE_READ_ACTION ) ; } } else if ( ( permission == null ) && ( URISchemeType . FILE . isURL ( url ) ) ) { String path = url . getFile ( ) . replace ( ' ' , File . separatorChar ) ; path = sun . net . www . ParseUtil . decode ( path ) ; if ( path . endsWith ( File . separator ) ) { path += "-" ; //$NON-NLS-1$ } permission = new FilePermission ( path , sun . security . util . SecurityConstants . FILE_READ_ACTION ) ; } else { URL locUrl = url ; if ( urlConnection instanceof JarURLConnection ) { locUrl = ( ( JarURLConnection ) urlConnection ) . getJarFileURL ( ) ; } String host = locUrl . getHost ( ) ; if ( host == null ) { host = "localhost" ; //$NON-NLS-1$ } permission = new SocketPermission ( host , sun . security . util . SecurityConstants . SOCKET_CONNECT_ACCEPT_ACTION ) ; } // make sure the person that created this class loader // would have this permission final SecurityManager sm = System . getSecurityManager ( ) ; if ( sm != null ) { final Permission fp = permission ; AccessController . doPrivileged ( new PrivilegedAction < Object > ( ) { @ Override public Object run ( ) throws SecurityException { sm . checkPermission ( fp ) ; return null ; } } , this . acc ) ; } perms . add ( permission ) ; return perms ; }
Returns the permissions for the given codesource object . The implementation of this method first calls super . getPermissions and then adds permissions based on the URL of the codesource .