1 /* |
1 /* |
2 * Copyright 2010 Google Inc. All Rights Reserved. |
2 * Copyright 2010 Google Inc. All Rights Reserved. |
|
3 * Copyright (c) 2019, Oracle and/or its affiliates. All rights reserved. |
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 * |
5 * |
5 * This code is free software; you can redistribute it and/or modify it |
6 * This code is free software; you can redistribute it and/or modify it |
6 * under the terms of the GNU General Public License version 2 only, as |
7 * under the terms of the GNU General Public License version 2 only, as |
7 * published by the Free Software Foundation. |
8 * published by the Free Software Foundation. |
33 |
34 |
34 import java.io.*; |
35 import java.io.*; |
35 import java.security.*; |
36 import java.security.*; |
36 |
37 |
37 public class SecurityManagerClinit { |
38 public class SecurityManagerClinit { |
38 private static class Policy extends java.security.Policy { |
39 private static class SimplePolicy extends Policy { |
|
40 static final Policy DEFAULT_POLICY = Policy.getPolicy(); |
|
41 |
39 private Permissions perms; |
42 private Permissions perms; |
40 |
43 |
41 public Policy(Permission... permissions) { |
44 public SimplePolicy(Permission... permissions) { |
42 perms = new Permissions(); |
45 perms = new Permissions(); |
43 for (Permission permission : permissions) |
46 for (Permission permission : permissions) |
44 perms.add(permission); |
47 perms.add(permission); |
45 } |
48 } |
46 |
49 |
47 public boolean implies(ProtectionDomain pd, Permission p) { |
50 public boolean implies(ProtectionDomain pd, Permission p) { |
48 return perms.implies(p); |
51 return perms.implies(p) || DEFAULT_POLICY.implies(pd, p); |
49 } |
52 } |
50 } |
53 } |
51 |
54 |
52 public static void main(String[] args) throws Throwable { |
55 public static void main(String[] args) throws Throwable { |
53 String javaExe = |
56 String javaExe = |
54 System.getProperty("java.home") + |
57 System.getProperty("java.home") + |
55 File.separator + "bin" + File.separator + "java"; |
58 File.separator + "bin" + File.separator + "java"; |
56 |
59 |
57 final Policy policy = |
60 final SimplePolicy policy = |
58 new Policy |
61 new SimplePolicy |
59 (new FilePermission("<<ALL FILES>>", "execute"), |
62 (new FilePermission("<<ALL FILES>>", "execute"), |
60 new RuntimePermission("setSecurityManager")); |
63 new RuntimePermission("setSecurityManager")); |
61 Policy.setPolicy(policy); |
64 Policy.setPolicy(policy); |
62 |
65 |
63 System.setSecurityManager(new SecurityManager()); |
66 System.setSecurityManager(new SecurityManager()); |