home *** CD-ROM | disk | FTP | other *** search
- package opera;
-
- import java.io.FilePermission;
- import java.lang.reflect.Constructor;
- import java.lang.reflect.Field;
- import java.lang.reflect.Method;
- import java.net.InetAddress;
- import java.net.MalformedURLException;
- import java.net.SocketPermission;
- import java.net.URL;
- import java.net.UnknownHostException;
- import java.security.AccessControlContext;
- import java.security.AccessController;
- import java.security.CodeSource;
- import java.security.PermissionCollection;
- import java.security.Policy;
- import java.security.ProtectionDomain;
- import java.security.cert.Certificate;
-
- public class LiveConnectPrivilegedActions {
- public static Object newObject(Constructor var0, Object[] var1, String var2) throws Exception {
- originCheck(var2, var0.getDeclaringClass());
- return AccessController.doPrivileged(new PrivilegedNewObject(var0, var1), createAccessControllerContext(var2));
- }
-
- public static Object invoke(Object var0, Method var1, Object[] var2, String var3) throws Exception {
- originCheck(var3, var1.getDeclaringClass());
- return AccessController.doPrivileged(new PrivilegedInvoke(var0, var1, var2), createAccessControllerContext(var3));
- }
-
- public static Object getField(Field var0, Object var1, String var2) throws Exception {
- originCheck(var2, var0.getDeclaringClass());
- return AccessController.doPrivileged(new PrivilegedGetField(var0, var1), createAccessControllerContext(var2));
- }
-
- public static void setField(Field var0, Object var1, Object var2, String var3) throws Exception {
- originCheck(var3, var0.getDeclaringClass());
- AccessController.doPrivileged(new PrivilegedSetField(var0, var1, var2), createAccessControllerContext(var3));
- }
-
- private static void originCheck(String var0, Class var1) throws OriginNotAllowedException {
- ProtectionDomain var2 = var1.getProtectionDomain();
- CodeSource var3 = var2.getCodeSource();
- if (var3 != null && var1.getClassLoader() != ClassLoader.getSystemClassLoader()) {
- URL var4 = var3.getLocation();
- URL var5 = null;
- if (var0 != null) {
- try {
- var5 = new URL(var0);
- } catch (MalformedURLException var10) {
- var10.printStackTrace();
- return;
- }
- }
-
- if (var4 != null && var5 != null) {
- InetAddress var6 = null;
- InetAddress var7 = null;
-
- try {
- var6 = InetAddress.getByName(var4.getHost());
- var7 = InetAddress.getByName(var5.getHost());
- } catch (UnknownHostException var9) {
- }
-
- if (var4.getProtocol().equalsIgnoreCase(var5.getProtocol()) && (var6 != null && var6.equals(var7) || var4.getHost().equalsIgnoreCase(var5.getHost())) && var4.getPort() == var5.getPort()) {
- return;
- }
- }
-
- throw new OriginNotAllowedException("LiveConnect origin check failed for JavaScript trying to access Java object, caller=" + var5 + ", callee=" + var4);
- }
- }
-
- private static ProtectionDomain getProtectionDomain(String var0) {
- URL var1 = null;
- if (var0 != null) {
- try {
- var1 = new URL(var0);
- } catch (MalformedURLException var6) {
- }
- }
-
- Policy var2 = Policy.getPolicy();
- CodeSource var3 = new CodeSource(var1, (Certificate[])null);
- PermissionCollection var4 = var2.getPermissions(var3);
- if (var1.getProtocol().equals("file")) {
- var4.add(new FilePermission("<<ALL FILES>>", "read"));
- var4.add(new SocketPermission("localhost", "connect,accept"));
- AccessController.doPrivileged(new 1(var4));
- } else {
- String var5 = var1.getHost();
- if (var5 == null) {
- var5 = "localhost";
- }
-
- var4.add(new SocketPermission(var5, "connect,accept"));
- }
-
- return new LiveConnectProtectionDomain(var4);
- }
-
- private static AccessControlContext createAccessControllerContext(String var0) throws Exception {
- ProtectionDomain[] var1 = new ProtectionDomain[]{getProtectionDomain(var0)};
- return new AccessControlContext(var1);
- }
- }
-