class ConnectionFactoryDecoratingPostProcessor implements BeanPostProcessor {

	@Override
	public Object postProcessAfterInitialization(Object bean, String beanName) throws BeansException {
		if (bean instanceof ConnectionFactory) {
			
			UserCredentialsConnectionFactoryAdapter adapter = new UserCredentialsConnectionFactoryAdapter();
			adapter.setTargetConnectionFactory((ConnectionFactory) bean);
			adapter.setUsername(username);
			adapter.setPassword(password);

			if (useCachingConnectionFactory) {
				return new CachingConnectionFactory(adapter);
			}
			return adapter;
		}
		return bean;
	}

}