harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From le...@apache.org
Subject svn commit: r556571 - in /harmony/enhanced/classlib/trunk/modules/logging/src: main/java/java/util/logging/LogManager.java main/java/java/util/logging/Logger.java test/java/org/apache/harmony/logging/tests/java/util/logging/LoggerTest.java
Date Mon, 16 Jul 2007 09:22:39 GMT
Author: leoli
Date: Mon Jul 16 02:22:33 2007
New Revision: 556571

URL: http://svn.apache.org/viewvc?view=rev&rev=556571
Log:
Apply patch for HARMONY-4474([classlib][logging] Logger initialize should bypass security
check).

Modified:
    harmony/enhanced/classlib/trunk/modules/logging/src/main/java/java/util/logging/LogManager.java
    harmony/enhanced/classlib/trunk/modules/logging/src/main/java/java/util/logging/Logger.java
    harmony/enhanced/classlib/trunk/modules/logging/src/test/java/org/apache/harmony/logging/tests/java/util/logging/LoggerTest.java

Modified: harmony/enhanced/classlib/trunk/modules/logging/src/main/java/java/util/logging/LogManager.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/logging/src/main/java/java/util/logging/LogManager.java?view=diff&rev=556571&r1=556570&r2=556571
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/logging/src/main/java/java/util/logging/LogManager.java
(original)
+++ harmony/enhanced/classlib/trunk/modules/logging/src/main/java/java/util/logging/LogManager.java
Mon Jul 16 02:22:33 2007
@@ -345,12 +345,18 @@
         // find children
         //TODO: performance can be improved here?
         Collection<Logger> allLoggers = loggers.values();
-        for (Logger child : allLoggers) {
+        for (final Logger child : allLoggers) {
             Logger oldParent = child.getParent();
             if (parent == oldParent
                     && (name.length() == 0 || child.getName().startsWith(
                             name + '.'))) {
-                child.setParent(logger);
+                final Logger thisLogger = logger;
+                AccessController.doPrivileged(new PrivilegedAction<Object>() {
+                    public Object run() {
+                        child.setParent(thisLogger);
+                        return null;
+                    }
+                });
                 if (null != oldParent) {
                     //-- remove from old parent as the parent has been changed
                     oldParent.removeChild(child);

Modified: harmony/enhanced/classlib/trunk/modules/logging/src/main/java/java/util/logging/Logger.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/logging/src/main/java/java/util/logging/Logger.java?view=diff&rev=556571&r1=556570&r2=556571
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/logging/src/main/java/java/util/logging/Logger.java
(original)
+++ harmony/enhanced/classlib/trunk/modules/logging/src/main/java/java/util/logging/Logger.java
Mon Jul 16 02:22:33 2007
@@ -1377,10 +1377,15 @@
             handlerInited  = false;
         }
         //init level here, but let handlers be for lazy loading
-        String configedLevel = manager.getProperty(name+ ".level"); //$NON-NLS-1$
+        final String configedLevel = manager.getProperty(name+ ".level"); //$NON-NLS-1$
         if (null != configedLevel) {
             try {
-                setLevel(Level.parse(configedLevel));
+                AccessController.doPrivileged(new PrivilegedAction<Object>() {
+                    public Object run() {
+                        setLevel(Level.parse(configedLevel));
+                        return null;
+                    }
+                });
             } catch (IllegalArgumentException e) {
                 //ignore
             }

Modified: harmony/enhanced/classlib/trunk/modules/logging/src/test/java/org/apache/harmony/logging/tests/java/util/logging/LoggerTest.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/logging/src/test/java/org/apache/harmony/logging/tests/java/util/logging/LoggerTest.java?view=diff&rev=556571&r1=556570&r2=556571
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/logging/src/test/java/org/apache/harmony/logging/tests/java/util/logging/LoggerTest.java
(original)
+++ harmony/enhanced/classlib/trunk/modules/logging/src/test/java/org/apache/harmony/logging/tests/java/util/logging/LoggerTest.java
Mon Jul 16 02:22:33 2007
@@ -76,9 +76,9 @@
 	 * Reset the log manager.
 	 */
 	protected void tearDown() throws Exception {
-		super.tearDown();
         CallVerificationStack.getInstance().clear();
 		Locale.setDefault(oldLocale);
+        super.tearDown();
 	}
 
 	/**
@@ -3414,6 +3414,42 @@
         } catch (MissingResourceException ex) {
             // Expected exception is precisely a MissingResourceException
             assertTrue(ex.getClass() == MissingResourceException.class);
+        }
+    }
+    
+    /**
+     * @tests java.util.logging.Logger#logrb(Level, String, String, String,
+     *        String, Object)
+     */
+    public void test_init_logger()
+            throws Exception {
+        Properties p = new Properties();
+        p.put("testGetLogger_Normal_ANewLogger2.level", "ALL");
+        LogManager.getLogManager().readConfiguration(
+                EnvironmentHelper.PropertiesToInputStream(p));
+
+        assertNull(LogManager.getLogManager().getLogger(
+                "testGetLogger_Normal_ANewLogger2"));
+        SecurityManager originalSecurityManager = System.getSecurityManager();
+        try {
+            System.setSecurityManager(new SecurityManager());
+            // should not throw expection
+            Logger logger = Logger.getLogger("testGetLogger_Normal_ANewLogger2");
+            // should thrpw exception
+            try{
+                logger.setLevel(Level.ALL);
+                fail("should throw SecurityException");
+            } catch (SecurityException e){
+                // expected
+            }
+            try{
+                logger.setParent(Logger.getLogger("root"));
+                fail("should throw SecurityException");
+            } catch (SecurityException e){
+                // expected
+            }
+        } finally {
+            System.setSecurityManager(originalSecurityManager);
         }
     }
 



Mime
View raw message