How to detect running on WebSphere
- by Pedro Guedes
Hi,
I'm building a webapp that should run on both Tomcat and WebSphere and I've managed to make almost all the differences into properties with default values that I can override for deployment on the Tomcat server.
I need to do yet another override for the authentication provider bean...
public void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory) throws BeansException {
if(isWebSphere()){
LOG.warn("Running on WebSphere... not overriding default authentication mechanism.");
return;
}
LOG.info("Running on Tomcat... overriding authentication provider bean ("+AUTHENTICATION_PROVIDER_BEAN+")");
if (beanFactory.containsBean(AUTHENTICATOR_BEAN) && beanFactory.containsBean(POPULATOR_BEAN) && beanFactory.containsBean(USERDETAIL_PROVIDER_BEAN)){
LdapAuthenticator authenticator = (LdapAuthenticator) beanFactory.getBean(AUTHENTICATOR_BEAN);
LdapAuthoritiesPopulator populator = (LdapAuthoritiesPopulator) beanFactory.getBean(POPULATOR_BEAN);
UserDetailProvider userDetailProvider = (UserDetailProvider) beanFactory.getBean(USERDETAIL_PROVIDER_BEAN);
ExtendedLdapAuthenticationProvider override = new ExtendedLdapAuthenticationProvider(authenticator, populator);
override.setUserDetailProvider(userDetailProvider);
beanFactory.registerSingleton(AUTHENTICATION_PROVIDER_BEAN, override);
} else {
throw new BeanCreationException("Could not find required beans to assemble overriding object for authentication...");
}
}
Now my problem is how to implement the isWebSphere() method. I was thinking Class.forName("someWebSphereSpecific"), but is there a better way?