@@ -0,0 +1,3135 @@
+/*%0A * Licensed to the Apache Software Foundation (ASF) under one or more%0A * contributor license agreements. See the NOTICE file distributed with%0A * this work for additional information regarding copyright ownership.%0A * The ASF licenses this file to You under the Apache license, Version 2.0%0A * (the %22License%22); you may not use this file except in compliance with%0A * the License. You may obtain a copy of the License at%0A *%0A *      http://www.apache.org/licenses/LICENSE-2.0%0A *%0A * Unless required by applicable law or agreed to in writing, software%0A * distributed under the License is distributed on an %22AS IS%22 BASIS,%0A * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.%0A * See the license for the specific language governing permissions and%0A * limitations under the license.%0A */%0A%0Apackage org.apache.logging.log4j.util;%0A%0Aimport java.security.Permission;%0A%0Aimport org.junit.Test;%0A%0A/**%0A * Tests https://issues.apache.org/jira/browse/LOG4J2-2274.%0A * %0A * @see EnvironmentPropertySource%0A * @see SecurityManager%0A * @see System#setSecurityManager(SecurityManager)%0A */%0Apublic class EnvironmentPropertySourceSecurityManagerTest %7B%0A%0A%09/**%0A%09 * Always throws a SecurityException for any environment variables permission%0A%09 * check.%0A%09 */%0A%09private class TestSecurityManager extends SecurityManager %7B%0A%09%09@Override%0A%09%09public void checkPermission(Permission permission) %7B%0A%09%09%09if (%22getenv.*%22.equals(permission.getName())) %7B%0A%09%09%09%09throw new SecurityException();%0A%09%09%09%7D%0A%09%09%7D%0A%09%7D%0A%0A%09/**%0A%09 * Makes sure we do not blow up with exception below due to a security manager%0A%09 * rejecting environment variable access in %7B@link EnvironmentPropertySource%7D.%0A%09 * %0A%09 * %3Cpre%3E%0A%09 * java.lang.NoClassDefFoundError: Could not initialize class org.apache.logging.log4j.util.PropertiesUtil%0A%09 *     at org.apache.logging.log4j.status.StatusLogger.%3Cclinit%3E(StatusLogger.java:78)%0A%09 *     at org.apache.logging.log4j.core.AbstractLifeCycle.%3Cclinit%3E(AbstractLifeCycle.java:38)%0A%09 *     at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)%0A%09 *     at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)%0A%09 *     at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)%0A%09 *     at java.lang.reflect.Constructor.newInstance(Constructor.java:423)%0A%09 *     at org.apache.logging.log4j.core.config.builder.impl.DefaultConfigurationBuilder.build(DefaultConfigurationBuilder.java:172)%0A%09 *     at org.apache.logging.log4j.core.config.builder.impl.DefaultConfigurationBuilder.build(DefaultConfigurationBuilder.java:161)%0A%09 *     at org.apache.logging.log4j.core.config.builder.impl.DefaultConfigurationBuilder.build(DefaultConfigurationBuilder.java:1)%0A%09 *     at org.apache.logging.log4j.util.EnvironmentPropertySourceSecurityManagerTest.test(EnvironmentPropertySourceSecurityManagerTest.java:55)%0A%09 * %3C/pre%3E%0A%09 */%0A%09@Test%0A%09public void test() %7B%0A%09%09try %7B%0A%09%09%09SecurityManager securityManager = new TestSecurityManager();%0A%09%09%09System.setSecurityManager(securityManager);%0A%09%09%7D catch (SecurityException se) %7B%0A%09%09%09// The SecurityManager is already set%0A%09%09%7D%0A%09%09PropertiesUtil.getProperties();%0A%09%7D%0A%7D%0A

Allow EnvironmentPropertySource to run with a SecurityManager that rejects environment variable access.