jboss-logging/log4j-jboss-logmanager — pull request #7 by jamezp (2014-06-06 22:02:00+00:00)
Title: Use privileged access where required when using a security manager.

The ```JBossLogManagerFacade``` stores log4j information in attachments on the loggers. Attaching items to a logger requires ```control``` permissions for ```java.util.logging.LoggingPermission```. Getting a log4j logger and creating the ```Hierarchy``` should be allowed even if permissions aren't granted by the security policy.

Getting the ```LogContext``` also has potential to throw a different permissions exception due to an ```AtomicReferenceFieldUpdater``` not having ```accessDeclaredMembers``` permissions.

```
Exception in thread "main" java.lang.ExceptionInInitializerError
at org.jboss.logmanager.LogContext.(LogContext.java:106)
at org.jboss.logmanager.LogContext.(LogContext.java:41)
at org.apache.log4j.LogManager.getLoggerRepository(LogManager.java:50)
at org.apache.log4j.LogManager.getLogger(LogManager.java:58)
at org.apache.log4j.Logger.getLogger(Logger.java:39)
at com.jamezp.test.Main.(Main.java:19)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:270)
at org.jboss.modules.Module.run(Module.java:302)
at org.jboss.modules.Main.main(Main.java:460)
Caused by: java.lang.RuntimeException: java.security.AccessControlException: access denied ("java.lang.RuntimePermission" "accessDeclaredMembers")
at java.util.concurrent.atomic.AtomicReferenceFieldUpdater$AtomicReferenceFieldUpdaterImpl.(AtomicReferenceFieldUpdater.java:219)
at java.util.concurrent.atomic.AtomicReferenceFieldUpdater.newUpdater(AtomicReferenceFieldUpdater.java:95)
at org.jboss.logmanager.LoggerNode.(LoggerNode.java:87)
... 10 more
Caused by: java.security.AccessControlException: access denied ("java.lang.RuntimePermission" "accessDeclaredMembers")
at java.security.AccessControlContext.checkPermission(AccessControlContext.java:372)
at java.security.AccessController.checkPermission(AccessController.java:559)
at java.lang.SecurityManager.checkPermission(SecurityManager.java:549)
at java.lang.Class.checkMemberAccess(Class.java:2237)
at java.lang.Class.getDeclaredField(Class.java:1945)
at java.util.concurrent.atomic.AtomicReferenceFieldUpdater$AtomicReferenceFieldUpdaterImpl.(AtomicReferenceFieldUpdater.java:212)
... 12 more
```

While this only appears to happen during initialization of the first ```LoggerNode``` it seems safest to always wrap the access to it.

Moved appender support to it's own class as the ```ExtHandler``` throws exceptions the static handler updater isn't created in a privilege block.