43
43
import java .io .ByteArrayInputStream ;
44
44
import java .io .ByteArrayOutputStream ;
45
45
import java .io .File ;
46
- import java .io .FilePermission ;
47
46
import java .io .IOException ;
48
47
import java .io .InputStream ;
49
48
import java .io .InputStreamReader ;
62
61
import java .nio .charset .CharsetEncoder ;
63
62
import java .nio .charset .IllegalCharsetNameException ;
64
63
import java .nio .charset .UnsupportedCharsetException ;
65
- import java .security .ProtectionDomain ;
66
64
import java .util .AbstractMap ;
67
65
import java .util .ArrayList ;
68
66
import java .util .Arrays ;
@@ -756,7 +754,7 @@ public byte[] translateTransferable(Transferable contents,
756
754
(String .class .equals (flavor .getRepresentationClass ()) &&
757
755
DataFlavorUtil .isFlavorCharsetTextType (flavor ) && isTextFormat (format ))) {
758
756
759
- String str = removeSuspectedData ( flavor , contents , ( String )obj ) ;
757
+ String str = ( String )obj ;
760
758
761
759
return translateTransferableString (
762
760
str ,
@@ -869,9 +867,7 @@ public byte[] translateTransferable(Transferable contents,
869
867
870
868
final List <?> list = (List <?>)obj ;
871
869
872
- final ProtectionDomain userProtectionDomain = getUserProtectionDomain (contents );
873
-
874
- final ArrayList <String > fileList = castToFiles (list , userProtectionDomain );
870
+ final ArrayList <String > fileList = castToFiles (list );
875
871
876
872
try (ByteArrayOutputStream bos = convertFileListToBytes (fileList )) {
877
873
theByteArray = bos .toByteArray ();
@@ -896,8 +892,7 @@ public byte[] translateTransferable(Transferable contents,
896
892
targetCharset = "UTF-8" ;
897
893
}
898
894
final List <?> list = (List <?>)obj ;
899
- final ProtectionDomain userProtectionDomain = getUserProtectionDomain (contents );
900
- final ArrayList <String > fileList = castToFiles (list , userProtectionDomain );
895
+ final ArrayList <String > fileList = castToFiles (list );
901
896
final ArrayList <String > uriList = new ArrayList <>(fileList .size ());
902
897
for (String fileObject : fileList ) {
903
898
final URI uri = new File (fileObject ).toURI ();
@@ -979,69 +974,12 @@ private static byte[] convertObjectToBytes(Object object) throws IOException {
979
974
980
975
protected abstract ByteArrayOutputStream convertFileListToBytes (ArrayList <String > fileList ) throws IOException ;
981
976
982
- @ SuppressWarnings ("removal" )
983
- private String removeSuspectedData (DataFlavor flavor , final Transferable contents , final String str )
984
- {
985
- if (null == System .getSecurityManager ()
986
- || !flavor .isMimeTypeEqual ("text/uri-list" ))
987
- {
988
- return str ;
989
- }
990
-
991
- final ProtectionDomain userProtectionDomain = getUserProtectionDomain (contents );
992
- StringBuilder allowedFiles = new StringBuilder (str .length ());
993
- String [] uriArray = str .split ("(\\ s)+" );
994
-
995
- for (String fileName : uriArray )
996
- {
997
- File file = new File (fileName );
998
- if (file .exists () &&
999
- !(isFileInWebstartedCache (file ) ||
1000
- isForbiddenToRead (file , userProtectionDomain )))
1001
- {
1002
- if (0 != allowedFiles .length ())
1003
- {
1004
- allowedFiles .append ("\\ r\\ n" );
1005
- }
1006
-
1007
- allowedFiles .append (fileName );
1008
- }
1009
- }
1010
- return allowedFiles .toString ();
1011
- }
1012
-
1013
- private static ProtectionDomain getUserProtectionDomain (Transferable contents ) {
1014
- return contents .getClass ().getProtectionDomain ();
1015
- }
1016
-
1017
- private boolean isForbiddenToRead (File file , ProtectionDomain protectionDomain )
1018
- {
1019
- if (null == protectionDomain ) {
1020
- return false ;
1021
- }
1022
- try {
1023
- FilePermission filePermission =
1024
- new FilePermission (file .getCanonicalPath (), "read, delete" );
1025
- if (protectionDomain .implies (filePermission )) {
1026
- return false ;
1027
- }
1028
- } catch (IOException e ) {}
1029
-
1030
- return true ;
1031
- }
1032
-
1033
- @ SuppressWarnings ("removal" )
1034
- private ArrayList <String > castToFiles (final List <?> files ,
1035
- final ProtectionDomain userProtectionDomain ) throws IOException {
977
+ private ArrayList <String > castToFiles (final List <?> files ) throws IOException {
1036
978
ArrayList <String > fileList = new ArrayList <>();
1037
979
for (Object fileObject : files )
1038
980
{
1039
981
File file = castToFile (fileObject );
1040
- if (file != null &&
1041
- (null == System .getSecurityManager () ||
1042
- !(isFileInWebstartedCache (file ) ||
1043
- isForbiddenToRead (file , userProtectionDomain ))))
1044
- {
982
+ if (file != null ) {
1045
983
fileList .add (file .getCanonicalPath ());
1046
984
}
1047
985
}
@@ -1062,43 +1000,6 @@ private File castToFile(Object fileObject) throws IOException {
1062
1000
return new File (filePath );
1063
1001
}
1064
1002
1065
- private static final String [] DEPLOYMENT_CACHE_PROPERTIES = {
1066
- "deployment.system.cachedir" ,
1067
- "deployment.user.cachedir" ,
1068
- "deployment.javaws.cachedir" ,
1069
- "deployment.javapi.cachedir"
1070
- };
1071
-
1072
- private static final ArrayList <File > deploymentCacheDirectoryList = new ArrayList <>();
1073
-
1074
- private static boolean isFileInWebstartedCache (File f ) {
1075
-
1076
- if (deploymentCacheDirectoryList .isEmpty ()) {
1077
- for (String cacheDirectoryProperty : DEPLOYMENT_CACHE_PROPERTIES ) {
1078
- String cacheDirectoryPath = System .getProperty (cacheDirectoryProperty );
1079
- if (cacheDirectoryPath != null ) {
1080
- try {
1081
- File cacheDirectory = (new File (cacheDirectoryPath )).getCanonicalFile ();
1082
- if (cacheDirectory != null ) {
1083
- deploymentCacheDirectoryList .add (cacheDirectory );
1084
- }
1085
- } catch (IOException ioe ) {}
1086
- }
1087
- }
1088
- }
1089
-
1090
- for (File deploymentCacheDirectory : deploymentCacheDirectoryList ) {
1091
- for (File dir = f ; dir != null ; dir = dir .getParentFile ()) {
1092
- if (dir .equals (deploymentCacheDirectory )) {
1093
- return true ;
1094
- }
1095
- }
1096
- }
1097
-
1098
- return false ;
1099
- }
1100
-
1101
-
1102
1003
public Object translateBytes (byte [] bytes , DataFlavor flavor ,
1103
1004
long format , Transferable localeTransferable )
1104
1005
throws IOException
0 commit comments