气氛不适用于 Wildfly 10 但相同版本的气氛在 Tomcat8 中工作
Atmosphere not working with Wildfly 10 But same version of atmosphere working in Tomcat8
我在 spring - spring-security.
中运行的项目中配置了 Atmosphere
对我的 @ManagedService
类 的所有 websocket 调用都工作正常。
但现在我想移动到 Wildfly 10,当部署相同的 war 时,大气呼叫不会进入我的 @ManagedService
Class。它进入我的 spring 安全过滤器。
我的氛围版:
<dependency>
<groupId>org.atmosphere</groupId>
<artifactId>atmosphere-runtime</artifactId>
<version>2.4.12</version>
</dependency>
Spring版本:4.3.6.RELEASE
Spring 安全性:4.2.1.RELEASE
这是我的 WepAppInitializer
// Create the dispatcher servlet's Spring application context
AnnotationConfigWebApplicationContext dispatcherServlet = new AnnotationConfigWebApplicationContext();
dispatcherServlet.register(SpringMVCConfig.class);
// AtmosphereServlet atmosphereServlet = new AtmosphereServlet();
AtmosphereServlet atmosphereServlet = servletContext.createServlet(AtmosphereServlet.class);
ServletRegistration.Dynamic websocketServlet = servletContext.addServlet("websocketServlet", atmosphereServlet);
websocketServlet.setLoadOnStartup(0);
websocketServlet.setAsyncSupported(true);
Set<String> mappingConflicts = websocketServlet.addMapping("/subscribe/*");
// Register and map the dispatcher servlet
ServletRegistration.Dynamic dispatcher = servletContext.addServlet("dispatcher",
new DispatcherServlet(dispatcherServlet));
dispatcher.setAsyncSupported(true);
dispatcher.setLoadOnStartup(1);
dispatcher.addMapping("/");
mappingConflicts = dispatcher.addMapping("/");
if (!mappingConflicts.isEmpty()) {
throw new IllegalStateException("'appServlet' cannot be mapped to '/'");
}
AtmosphereFramework framework = atmosphereServlet.framework();
broadcasterFactory = framework.getBroadcasterFactory();
下面是我的 Spring 安全代码段:
@Override
protected void configure(HttpSecurity http) throws Exception {
http.csrf().disable().sessionManagement().sessionCreationPolicy(SessionCreationPolicy.STATELESS).and()
.authorizeRequests()
...
My ant matchers...
...
// All other request need to be authenticated
.anyRequest().authenticated()
// Custom Token based authentication based on the header
// previously given to the client
.and().addFilterBefore(authenticationFilter, UsernamePasswordAuthenticationFilter.class).logout()
.logoutUrl("/logout").disable().exceptionHandling().accessDeniedPage("/accessDenied");
}
问题:
在 wildfly 中,我所有的 websocket 调用都将转到身份验证过滤器,而不是 @ManagedService
类
Anything specific that I am missing that has to be done for wildfly?
终于明白问题所在了。
奇怪的是,在 wildfly 中,websocket 调用也通过身份验证过滤器,而在 Tomcat 中,websocket 调用直接绕过 @ManagedService
类.
所以我刚刚为我的氛围添加了一个 ignore antMatcher url。
@Override
public void configure(WebSecurity web) throws Exception {
web.ignoring().antMatchers(REQUEST_MAPPING_AUTHENTICATEUSER).antMatchers("/heartBeat")
.antMatchers("/subscribe/**");
}
这解决了我的问题。
我在 spring - spring-security.
中运行的项目中配置了 Atmosphere对我的 @ManagedService
类 的所有 websocket 调用都工作正常。
但现在我想移动到 Wildfly 10,当部署相同的 war 时,大气呼叫不会进入我的 @ManagedService
Class。它进入我的 spring 安全过滤器。
我的氛围版:
<dependency>
<groupId>org.atmosphere</groupId>
<artifactId>atmosphere-runtime</artifactId>
<version>2.4.12</version>
</dependency>
Spring版本:4.3.6.RELEASE
Spring 安全性:4.2.1.RELEASE
这是我的 WepAppInitializer
// Create the dispatcher servlet's Spring application context
AnnotationConfigWebApplicationContext dispatcherServlet = new AnnotationConfigWebApplicationContext();
dispatcherServlet.register(SpringMVCConfig.class);
// AtmosphereServlet atmosphereServlet = new AtmosphereServlet();
AtmosphereServlet atmosphereServlet = servletContext.createServlet(AtmosphereServlet.class);
ServletRegistration.Dynamic websocketServlet = servletContext.addServlet("websocketServlet", atmosphereServlet);
websocketServlet.setLoadOnStartup(0);
websocketServlet.setAsyncSupported(true);
Set<String> mappingConflicts = websocketServlet.addMapping("/subscribe/*");
// Register and map the dispatcher servlet
ServletRegistration.Dynamic dispatcher = servletContext.addServlet("dispatcher",
new DispatcherServlet(dispatcherServlet));
dispatcher.setAsyncSupported(true);
dispatcher.setLoadOnStartup(1);
dispatcher.addMapping("/");
mappingConflicts = dispatcher.addMapping("/");
if (!mappingConflicts.isEmpty()) {
throw new IllegalStateException("'appServlet' cannot be mapped to '/'");
}
AtmosphereFramework framework = atmosphereServlet.framework();
broadcasterFactory = framework.getBroadcasterFactory();
下面是我的 Spring 安全代码段:
@Override
protected void configure(HttpSecurity http) throws Exception {
http.csrf().disable().sessionManagement().sessionCreationPolicy(SessionCreationPolicy.STATELESS).and()
.authorizeRequests()
...
My ant matchers...
...
// All other request need to be authenticated
.anyRequest().authenticated()
// Custom Token based authentication based on the header
// previously given to the client
.and().addFilterBefore(authenticationFilter, UsernamePasswordAuthenticationFilter.class).logout()
.logoutUrl("/logout").disable().exceptionHandling().accessDeniedPage("/accessDenied");
}
问题:
在 wildfly 中,我所有的 websocket 调用都将转到身份验证过滤器,而不是 @ManagedService
类
Anything specific that I am missing that has to be done for wildfly?
终于明白问题所在了。
奇怪的是,在 wildfly 中,websocket 调用也通过身份验证过滤器,而在 Tomcat 中,websocket 调用直接绕过 @ManagedService
类.
所以我刚刚为我的氛围添加了一个 ignore antMatcher url。
@Override
public void configure(WebSecurity web) throws Exception {
web.ignoring().antMatchers(REQUEST_MAPPING_AUTHENTICATEUSER).antMatchers("/heartBeat")
.antMatchers("/subscribe/**");
}
这解决了我的问题。