/*
 * JBoss, Home of Professional Open Source.
 * Copyright 2006, Red Hat Middleware LLC, and individual contributors
 * as indicated by the @author tags. See the copyright.txt file in the
 * distribution for a full listing of individual contributors.
 *
 * This is free software; you can redistribute it and/or modify it
 * under the terms of the GNU Lesser General Public License as
 * published by the Free Software Foundation; either version 2.1 of
 * the License, or (at your option) any later version.
 *
 * This software is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this software; if not, write to the Free
 * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
 * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
 */
package org.jboss.wsf.stack.cxf.config;

import static org.jboss.wsf.stack.cxf.Loggers.ROOT_LOGGER;

import java.security.AccessController;
import java.security.PrivilegedAction;

import org.apache.wss4j.common.crypto.WSProviderConfig;
import org.jboss.wsf.spi.classloading.ClassLoaderProvider;
import org.jboss.wsf.spi.management.StackConfig;
import org.jboss.wsf.spi.management.StackConfigFactory;
import org.jboss.wsf.stack.cxf.addressRewrite.SoapAddressRewriteHelper;

/**
 * 
 * @author alessio.soldano@jboss.com
 * @since 25-May-2009
 *
 */
public class CXFStackConfigFactory extends StackConfigFactory
{
   @Override
   public StackConfig getStackConfig()
   {
      return new CXFStackConfig();
   }
}

class CXFStackConfig implements StackConfig
{
   public CXFStackConfig()
   {
      final ClassLoader orig = getContextClassLoader();
      //try early configuration of xmlsec engine through WSS4J:
      //* to avoid doing this later when the TCCL won't have visibility over the xmlsec internals
      //* to make sure any ws client will also have full xmlsec functionalities setup (BC enabled, etc.)
      try
      {
         setContextClassLoader(ClassLoaderProvider.getDefaultProvider().getServerIntegrationClassLoader());
         WSProviderConfig.init(true, false, true);
      }
      catch (Exception e)
      {
         ROOT_LOGGER.couldNotInitSecurityEngine();
         ROOT_LOGGER.errorGettingWSSConfig(e);
      }
      finally
      {
         setContextClassLoader(orig);
      }
   }

   public String getImplementationTitle()
   {
      return getClass().getPackage().getImplementationTitle();
   }

   public String getImplementationVersion()
   {
      return getClass().getPackage().getImplementationVersion();
   }
   
   /**
    * Get context classloader.
    * 
    * @return the current context classloader
    */
   private static ClassLoader getContextClassLoader()
   {
      SecurityManager sm = System.getSecurityManager();
      if (sm == null)
      {
         return Thread.currentThread().getContextClassLoader();
      }
      else
      {
         return AccessController.doPrivileged(new PrivilegedAction<ClassLoader>() {
            public ClassLoader run()
            {
               return Thread.currentThread().getContextClassLoader();
            }
         });
      }
   }
   
   /**
    * Set context classloader.
    *
    * @param classLoader the classloader
    */
   private static void setContextClassLoader(final ClassLoader classLoader)
   {
      if (System.getSecurityManager() == null)
      {
         Thread.currentThread().setContextClassLoader(classLoader);
      }
      else
      {
         AccessController.doPrivileged(new PrivilegedAction<Object>()
         {
            public Object run()
            {
               Thread.currentThread().setContextClassLoader(classLoader);
               return null;
            }
         });
      }
   }

   @Override
   public void validatePathRewriteRule(String rule)
   {
      SoapAddressRewriteHelper.validatePathRewriteRule(rule);
   }
}
@@ -1205,16 +1205,43 @@
 ction;%0A%0A
+import org.apache.cxf.Bus;%0A
 import o
@@ -2570,138 +2570,387 @@
 %0A   
-public String getImplementationTitle()%0A   %7B%0A      return getClass().getPackage().getImplementationTitle();%0A   %7D%0A%0A   public String 
+//hack the 2 methods below to make the logs show something like%0A   // %22JBossWS 5.1.1.Final (Apache CXF 3.1.4)%22%0A   %0A   public String getImplementationTitle()%0A   %7B%0A      StringBuilder sb = new StringBuilder();%0A      sb.append(%22JBossWS %22);%0A      sb.append(getClass().getPackage().getImplementationVersion());%0A      sb.append(%22 (Apache CXF %22);%0A      sb.append(Bus.class.getPackage().
 getI
@@ -2975,51 +2975,84 @@
 on()
+);
 %0A   
-%7B%0A      return getClass().getPackage().
+   sb.append(%22)%22);%0A      return sb.toString();%0A   %7D%0A%0A   public String 
 getI
@@ -3073,16 +3073,37 @@
 ersion()
+%0A   %7B%0A      return %22%22
 ;%0A   %7D%0A 

Improve stack version log