8068320: Limit applet requests
Reviewed-by: prr, skoivu, art
This commit is contained in:
parent
ecdd3ad65a
commit
e307e3921e
@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (c) 1998, 2014, Oracle and/or its affiliates. All rights reserved.
|
* Copyright (c) 1998, 2015, Oracle and/or its affiliates. All rights reserved.
|
||||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||||
*
|
*
|
||||||
* This code is free software; you can redistribute it and/or modify it
|
* This code is free software; you can redistribute it and/or modify it
|
||||||
@ -92,25 +92,38 @@ public class @(BeanClassName)BeanInfo extends javax.swing.SwingBeanInfoBase {
|
|||||||
/**
|
/**
|
||||||
* @return an icon of the specified kind for @(BeanClassName)
|
* @return an icon of the specified kind for @(BeanClassName)
|
||||||
*/
|
*/
|
||||||
public Image getIcon(int kind) {
|
public Image getIcon(final int kind) {
|
||||||
Image i;
|
Image i;
|
||||||
switch (kind){
|
switch (kind){
|
||||||
case ICON_COLOR_32x32:
|
case ICON_COLOR_32x32:
|
||||||
i = loadImage("beaninfo/images/@(BeanClassName)Color32.gif");
|
i = loadStandardImage("beaninfo/images/@(BeanClassName)Color32.gif");
|
||||||
return ((i == null) ? loadImage("beaninfo/images/JComponentColor32.gif") : i);
|
return ((i == null) ? loadStandardImage("beaninfo/images/JComponentColor32.gif") : i);
|
||||||
case ICON_COLOR_16x16:
|
case ICON_COLOR_16x16:
|
||||||
i = loadImage("beaninfo/images/@(BeanClassName)Color16.gif");
|
i = loadStandardImage("beaninfo/images/@(BeanClassName)Color16.gif");
|
||||||
return ((i == null) ? loadImage("beaninfo/images/JComponentColor16.gif") : i);
|
return ((i == null) ? loadStandardImage("beaninfo/images/JComponentColor16.gif") : i);
|
||||||
case ICON_MONO_32x32:
|
case ICON_MONO_32x32:
|
||||||
i = loadImage("beaninfo/images/@(BeanClassName)Mono32.gif");
|
i = loadStandardImage("beaninfo/images/@(BeanClassName)Mono32.gif");
|
||||||
return ((i == null) ? loadImage("beaninfo/images/JComponentMono32.gif") : i);
|
return ((i == null) ? loadStandardImage("beaninfo/images/JComponentMono32.gif") : i);
|
||||||
case ICON_MONO_16x16:
|
case ICON_MONO_16x16:
|
||||||
i = loadImage("beaninfo/images/@(BeanClassName)Mono16.gif");
|
i = loadStandardImage("beaninfo/images/@(BeanClassName)Mono16.gif");
|
||||||
return ((i == null) ? loadImage("beaninfo/images/JComponentMono16.gif") : i);
|
return ((i == null) ? loadStandardImage("beaninfo/images/JComponentMono16.gif") : i);
|
||||||
default:
|
default:
|
||||||
return super.getIcon(kind);
|
return super.getIcon(kind);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This is a utility method to help in loading standard icon images.
|
||||||
|
*
|
||||||
|
* @param resourceName A pathname relative to the directory holding the
|
||||||
|
* class file of the current class
|
||||||
|
* @return an image object. May be null if the load failed.
|
||||||
|
* @see java.beans.SimpleBeanInfo#loadImage(String)
|
||||||
|
*/
|
||||||
|
private Image loadStandardImage(final String resourceName) {
|
||||||
|
return java.security.AccessController.doPrivileged(
|
||||||
|
(java.security.PrivilegedAction<Image>) () -> loadImage(resourceName));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (c) 1996, 2013, Oracle and/or its affiliates. All rights reserved.
|
* Copyright (c) 1996, 2015, Oracle and/or its affiliates. All rights reserved.
|
||||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||||
*
|
*
|
||||||
* This code is free software; you can redistribute it and/or modify it
|
* This code is free software; you can redistribute it and/or modify it
|
||||||
@ -46,9 +46,6 @@ import java.lang.reflect.Modifier;
|
|||||||
|
|
||||||
import java.net.URL;
|
import java.net.URL;
|
||||||
|
|
||||||
import java.security.AccessController;
|
|
||||||
import java.security.PrivilegedAction;
|
|
||||||
|
|
||||||
import java.util.Enumeration;
|
import java.util.Enumeration;
|
||||||
import java.util.Hashtable;
|
import java.util.Hashtable;
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
@ -183,16 +180,10 @@ public class Beans {
|
|||||||
|
|
||||||
// Try to find a serialized object with this name
|
// Try to find a serialized object with this name
|
||||||
final String serName = beanName.replace('.','/').concat(".ser");
|
final String serName = beanName.replace('.','/').concat(".ser");
|
||||||
final ClassLoader loader = cls;
|
if (cls == null)
|
||||||
ins = AccessController.doPrivileged
|
ins = ClassLoader.getSystemResourceAsStream(serName);
|
||||||
(new PrivilegedAction<InputStream>() {
|
else
|
||||||
public InputStream run() {
|
ins = cls.getResourceAsStream(serName);
|
||||||
if (loader == null)
|
|
||||||
return ClassLoader.getSystemResourceAsStream(serName);
|
|
||||||
else
|
|
||||||
return loader.getResourceAsStream(serName);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
if (ins != null) {
|
if (ins != null) {
|
||||||
try {
|
try {
|
||||||
if (cls == null) {
|
if (cls == null) {
|
||||||
@ -283,19 +274,10 @@ public class Beans {
|
|||||||
URL docBase = null;
|
URL docBase = null;
|
||||||
|
|
||||||
// Now get the URL correponding to the resource name.
|
// Now get the URL correponding to the resource name.
|
||||||
|
if (cls == null) {
|
||||||
final ClassLoader cloader = cls;
|
objectUrl = ClassLoader.getSystemResource(resourceName);
|
||||||
objectUrl =
|
} else
|
||||||
AccessController.doPrivileged
|
objectUrl = cls.getResource(resourceName);
|
||||||
(new PrivilegedAction<URL>() {
|
|
||||||
public URL run() {
|
|
||||||
if (cloader == null)
|
|
||||||
return ClassLoader.getSystemResource
|
|
||||||
(resourceName);
|
|
||||||
else
|
|
||||||
return cloader.getResource(resourceName);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
// If we found a URL, we try to locate the docbase by taking
|
// If we found a URL, we try to locate the docbase by taking
|
||||||
// of the final path name component, and the code base by taking
|
// of the final path name component, and the code base by taking
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (c) 1996, 2011, Oracle and/or its affiliates. All rights reserved.
|
* Copyright (c) 1996, 2015, Oracle and/or its affiliates. All rights reserved.
|
||||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||||
*
|
*
|
||||||
* This code is free software; you can redistribute it and/or modify it
|
* This code is free software; you can redistribute it and/or modify it
|
||||||
@ -25,6 +25,11 @@
|
|||||||
|
|
||||||
package java.beans;
|
package java.beans;
|
||||||
|
|
||||||
|
import java.awt.Image;
|
||||||
|
import java.awt.Toolkit;
|
||||||
|
import java.awt.image.ImageProducer;
|
||||||
|
import java.net.URL;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This is a support class to make it easier for people to provide
|
* This is a support class to make it easier for people to provide
|
||||||
* BeanInfo classes.
|
* BeanInfo classes.
|
||||||
@ -101,7 +106,7 @@ public class SimpleBeanInfo implements BeanInfo {
|
|||||||
* Claim there are no icons available. You can override
|
* Claim there are no icons available. You can override
|
||||||
* this if you want to provide icons for your bean.
|
* this if you want to provide icons for your bean.
|
||||||
*/
|
*/
|
||||||
public java.awt.Image getIcon(int iconKind) {
|
public Image getIcon(int iconKind) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -116,33 +121,17 @@ public class SimpleBeanInfo implements BeanInfo {
|
|||||||
* "wombat.gif".
|
* "wombat.gif".
|
||||||
* @return an image object. May be null if the load failed.
|
* @return an image object. May be null if the load failed.
|
||||||
*/
|
*/
|
||||||
public java.awt.Image loadImage(final String resourceName) {
|
public Image loadImage(final String resourceName) {
|
||||||
try {
|
try {
|
||||||
final Class<?> c = getClass();
|
final URL url = getClass().getResource(resourceName);
|
||||||
java.awt.image.ImageProducer ip = (java.awt.image.ImageProducer)
|
if (url != null) {
|
||||||
java.security.AccessController.doPrivileged(
|
final ImageProducer ip = (ImageProducer) url.getContent();
|
||||||
new java.security.PrivilegedAction<Object>() {
|
if (ip != null) {
|
||||||
public Object run() {
|
return Toolkit.getDefaultToolkit().createImage(ip);
|
||||||
java.net.URL url;
|
}
|
||||||
if ((url = c.getResource(resourceName)) == null) {
|
}
|
||||||
return null;
|
} catch (final Exception ignored) {
|
||||||
} else {
|
|
||||||
try {
|
|
||||||
return url.getContent();
|
|
||||||
} catch (java.io.IOException ioe) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
if (ip == null)
|
|
||||||
return null;
|
|
||||||
java.awt.Toolkit tk = java.awt.Toolkit.getDefaultToolkit();
|
|
||||||
return tk.createImage(ip);
|
|
||||||
} catch (Exception ex) {
|
|
||||||
return null;
|
|
||||||
}
|
}
|
||||||
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,53 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.
|
||||||
|
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||||
|
*
|
||||||
|
* This code is free software; you can redistribute it and/or modify it
|
||||||
|
* under the terms of the GNU General Public License version 2 only, as
|
||||||
|
* published by the Free Software Foundation.
|
||||||
|
*
|
||||||
|
* This code 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 General Public License
|
||||||
|
* version 2 for more details (a copy is included in the LICENSE file that
|
||||||
|
* accompanied this code).
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License version
|
||||||
|
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||||
|
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||||
|
*
|
||||||
|
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||||
|
* or visit www.oracle.com if you need additional information or have any
|
||||||
|
* questions.
|
||||||
|
*/
|
||||||
|
|
||||||
|
import java.awt.Image;
|
||||||
|
import java.beans.BeanInfo;
|
||||||
|
import java.beans.IntrospectionException;
|
||||||
|
import java.beans.Introspector;
|
||||||
|
|
||||||
|
import javax.swing.JButton;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @test
|
||||||
|
* @bug 4141523
|
||||||
|
* @run main/othervm/policy=java.policy -Djava.security.manager LoadingStandardIcons
|
||||||
|
*/
|
||||||
|
public final class LoadingStandardIcons {
|
||||||
|
|
||||||
|
public static void main(final String[] args) {
|
||||||
|
final Object bi;
|
||||||
|
try {
|
||||||
|
bi = Introspector.getBeanInfo(JButton.class);
|
||||||
|
} catch (IntrospectionException e) {
|
||||||
|
throw new RuntimeException(e);
|
||||||
|
}
|
||||||
|
final Image m16 = ((BeanInfo) bi).getIcon(BeanInfo.ICON_MONO_16x16);
|
||||||
|
final Image m32 = ((BeanInfo) bi).getIcon(BeanInfo.ICON_MONO_32x32);
|
||||||
|
final Image c16 = ((BeanInfo) bi).getIcon(BeanInfo.ICON_COLOR_16x16);
|
||||||
|
final Image c32 = ((BeanInfo) bi).getIcon(BeanInfo.ICON_COLOR_32x32);
|
||||||
|
if (m16 == null || m32 == null || c16 == null || c32 == null) {
|
||||||
|
throw new RuntimeException("Image should not be null");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1 @@
|
|||||||
|
;
|
Loading…
Reference in New Issue
Block a user