/*
 * Copyright 2016-2019 the original author or authors.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package org.joinfaces.autoconfigure.tobago;

import org.apache.myfaces.tobago.webapp.SecretSessionListener;
import org.apache.myfaces.tobago.webapp.TobagoServletContextListener;
import org.joinfaces.autoconfigure.servlet.WebFragmentRegistrationBean;

import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.boot.autoconfigure.condition.ConditionalOnWebApplication;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * {@link org.springframework.boot.autoconfigure.EnableAutoConfiguration Auto configuration}
 * for Apache MyFaces Tobago.
 *
 * @author Lars Grefer
 */
@Configuration(proxyBeanMethods = false)
@ConditionalOnClass(TobagoServletContextListener.class)
@ConditionalOnWebApplication(type = ConditionalOnWebApplication.Type.SERVLET)
public class TobagoAutoConfiguration {

	/**
	 * This {@link WebFragmentRegistrationBean} is equivalent to the
	 * {@code META-INF/web-fragment.xml} of the {@code tobago-core.jar}.
	 *
	 * @return tobagoWebFragmentRegistrationBean
	 */
	@Bean
	public WebFragmentRegistrationBean tobagoWebFragmentRegistrationBean() {
		WebFragmentRegistrationBean bean = new WebFragmentRegistrationBean();
		bean.getListeners().add(TobagoServletContextListener.class);
		bean.getListeners().add(SecretSessionListener.class);
		return bean;
	}
}

@@ -671,54 +671,23 @@
 ort 
-org.apache.myfaces.tobago.webapp.SecretSession
+java.util.Event
 List
@@ -684,32 +684,33 @@
 .EventListener;%0A
+%0A
 import org.apach
@@ -1109,16 +1109,60 @@
 uration;
+%0Aimport org.springframework.util.ClassUtils;
 %0A%0A/**%0A *
@@ -1308,16 +1308,42 @@
  Grefer%0A
+ * @author Carsten Dimmek%0A
  */%0A@Con
@@ -1553,16 +1553,131 @@
 tion %7B%0A%0A
+%0A%09private static final String SECRET_SESSION_LISTENER = %22org.apache.myfaces.tobago.webapp.SecretSessionListener%22;%0A%0A
 %09/**%0A%09 *
@@ -1942,16 +1942,46 @@
 onBean()
+ throws ClassNotFoundException
  %7B%0A%09%09Web
@@ -2116,61 +2116,272 @@
 ;%0A%09%09
-bean.getListeners().add(SecretSessionListener.class);
+ClassLoader classLoader = TobagoAutoConfiguration.class.getClassLoader();%0A%09%09if (ClassUtils.isPresent(SECRET_SESSION_LISTENER, classLoader)) %7B%0A%09%09%09bean.getListeners().add((Class%3C? extends EventListener%3E) ClassUtils.forName(SECRET_SESSION_LISTENER, classLoader));%0A%09%09%7D
 %0A%09%09r

Make SecretSessionListener optional