I am trying to use WSO2 5.3.0 as identification server.
My application is running in JBOSS EAP 7.0 and WSO2 is running in Tomcat which ships with it.
I have followed this document from ws02 and able to do SSO successfully when the sample application is running in tomcat. But when I deploy the same application to JBOSS EAP 7.0 I am getting this error when I hit the application URL.
ERROR [io.undertow.request] (default task-2) UT005023: Exception handling request to /travevlocity.com: java.lang.IllegalStateException: UT010041: The servlet context has already been initialized, you can only call this method from a ServletContainerInitializer or a ServletContextListener at io.undertow.servlet.spec.ServletContextImpl.ensureNotInitialized(ServletContextImpl.java:778) at io.undertow.servlet.spec.ServletContextImpl.addListener(ServletContextImpl.java:653) at io.undertow.servlet.spec.ServletContextImpl.addListener(ServletContextImpl.java:632) at org.wso2.carbon.identity.sso.agent.SSOAgentFilter.init(SSOAgentFilter.java:57)
In WSO2, here is the init method of SSOAgentFilter.
public void init(FilterConfig fConfig)
throws ServletException
{
try
{
SSOAgentConfigs.initConfig(fConfig);
SSOAgentConfigs.initCheck();
samlSSOManager = new SAML2SSOManager();
openIdManager = new OpenIDManager();
fConfig.getServletContext().addListener("org.wso2.carbon.identity.sso.agent.saml.SSOAgentHttpSessionListener");
} catch(SSOAgentException e){
LOGGER.log(Level.SEVERE, "An error has occurred", e);
throw e;
}
}
I think the issue is with JBOSS EAP 7.0 which uses undertow as the servlet api implementation. Here is the code snippet of ServletContextImpl of undertow.
@Override
public void addListener(final Class<? extends EventListener> listenerClass) {
ensureNotInitialized();
ensureNotProgramaticListener();
if (ApplicationListeners.listenerState() != NO_LISTENER
&& ServletContextListener.class.isAssignableFrom(listenerClass)) {
throw UndertowServletMessages.MESSAGES.cannotAddServletContextListener();
}
InstanceFactory<? extends EventListener> factory = null;
try {
factory = deploymentInfo.getClassIntrospecter().createInstanceFactory(listenerClass);
} catch (Exception e) {
throw new IllegalArgumentException(e);
}
final ListenerInfo listener = new ListenerInfo(listenerClass, factory);
deploymentInfo.addListener(listener);
deployment.getApplicationListeners().addListener(new ManagedListener(listener, true));
}
Before adding any listener, they are checking whether the ServletContext is initialized or not. And if it's already initialized, we can't add any listener to it.
But in the implementation of Tomcat or other containers, this is not being checked. Hence it's working fine there.
Is there anything we can do to resolve this. I can use only Jboss EAP 7.0 as server in my application. Please help.