[logback-user] File appenders under SecurityManager

Sergey Kabashnyuk ksmster at gmail.com
Wed Feb 22 08:54:02 CET 2012


Hello

I'd like to contribute the  FileAppender and RollingFileAppender what
made file operation from it's own name.
It will allow to user code with restricted file access by
SecurityManager to use loggers with file backend.

If proposition is interesting I can create jira issue and provide
patches with implementation.
Example of SecurityFileAppender

/**
 * Implementation of FileAppender what made file operation from it's own name.
 * Created to be used with enabled SecurityManager.
 */
public class SecurityFileAppender<E> extends FileAppender<E>
{

   /**
    * @see ch.qos.logback.core.FileAppender#openFile(java.lang.String)
    */
   @Override
   public void openFile(final String file_name) throws IOException
   {

      try
      {
         AccessController.doPrivileged(new PrivilegedExceptionAction<Void>()
         {

            @Override
            public Void run() throws Exception
            {
               SecurityFileAppender.super.openFile(file_name);
               return null;
            }

         });
      }
      catch (PrivilegedActionException e)
      {
         throw new IOException(e.getLocalizedMessage(), e);
      }

   }

   /**
    * @see ch.qos.logback.core.FileAppender#writeOut(java.lang.Object)
    */
   @Override
   protected void writeOut(final E event) throws IOException
   {

      try
      {
         AccessController.doPrivileged(new PrivilegedExceptionAction<Void>()
         {

            @Override
            public Void run() throws Exception
            {
               SecurityFileAppender.super.writeOut(event);
               return null;
            }

         });
      }
      catch (PrivilegedActionException e)
      {
         throw new IOException(e.getLocalizedMessage(), e);
      }
   }

}


Sergey Kabashnyuk


More information about the Logback-user mailing list