From ed7e4ae849b0077902415cfa8241ee816bce269f Mon Sep 17 00:00:00 2001 From: aoshiguchen <1052045476@qq.com> Date: Sun, 25 Sep 2022 21:46:00 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0SecurityManager=E6=B5=8B?= =?UTF-8?q?=E8=AF=95=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../core/security/SecurityManagerTest.java | 57 +++++++++++++++++++ 1 file changed, 57 insertions(+) create mode 100644 neutrino-core/src/test/java/fun/asgc/neutrino/core/security/SecurityManagerTest.java diff --git a/neutrino-core/src/test/java/fun/asgc/neutrino/core/security/SecurityManagerTest.java b/neutrino-core/src/test/java/fun/asgc/neutrino/core/security/SecurityManagerTest.java new file mode 100644 index 00000000..a288942d --- /dev/null +++ b/neutrino-core/src/test/java/fun/asgc/neutrino/core/security/SecurityManagerTest.java @@ -0,0 +1,57 @@ +/** + * Copyright (c) 2022 aoshiguchen + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ +package fun.asgc.neutrino.core.security; + +import java.io.BufferedReader; +import java.io.FileReader; +import java.io.IOException; +import java.security.AccessController; +import java.security.PrivilegedAction; +import java.util.stream.Collectors; + +/** + * @author: aoshiguchen + * @date: 2022/9/25 + */ +public class SecurityManagerTest { + + public static void main(String[] args) { + // -Djava.security.manager -Djava.security.policy=/work/tmp/policy1.policy + System.out.println("SecurityManager: " + System.getSecurityManager()); + + try (BufferedReader br = new BufferedReader(new FileReader("/work/tmp/test.txt"))){ + System.out.println("content:\n" + br.lines().collect(Collectors.joining())); + } catch (IOException e) { + throw new RuntimeException(e); + } + + AccessController.doPrivileged(new PrivilegedAction() { + @Override + public Object run() { + System.out.println(System.getProperty("file.encoding")); + return null; + } + }); +// System.out.println(System.getProperty("file.encoding")); + } + +}