【问题标题】:Session id keeps changing for every request with https and spring security in IE browserIE浏览器中使用https和spring security的每个请求的会话ID不断变化
【发布时间】:2017-02-24 10:45:57
【问题描述】:

我有一个 spring MVC 4 和 spring 安全应用程序部署在 websphere 8.5 共享服务器上,比如 server123。我以公司 F5 域名上的 https 应用程序访问该应用程序。

我遇到了一个奇怪的问题,即会话 ID 在每个 servlet 请求上都不断变化。这会导致 IE 上的无限重定向循环。但是,这适用于 chrome 和 firefox。

我如下调用我的应用程序,其中 apps/MyApp/ 是上下文根 MainPage 是控制器请求映射 url https://example.server.com/apps/MyApp/MainPage

我还使用 UserNamePasswordAuthenticationFilter 配置了 SSO 身份验证,该身份验证拦截 spring 重定向身份验证 url /loginSSO。一旦认证成功,在 IE 中正向路径 /MainPage 会丢失,并反复重定向到 https://example.server.com/apps/MyApp/https://example.server.com/apps/MyApp/loginSSO。以下是我的安全配置详细信息。

@Override
protected void configure(HttpSecurity http) throws Exception {
    http.authorizeRequests().antMatchers("/loginSSO").permitAll();
    http.authorizeRequests()
            .anyRequest()
            .authenticated()
            .and()
            .formLogin()
            .loginPage("/loginSSO")
            .successHandler(successHandler())
            .and()
            .csrf()
            .csrfTokenRepository(csrfTokenRepository())
            .and()
            .addFilterBefore(new CookieFilter(),
                    ChannelProcessingFilter.class)
            .addFilterAfter(new CSRFFilter(), CsrfFilter.class)
            .addFilterBefore(authFilter(),
                    UsernamePasswordAuthenticationFilter.class)
            .requiresChannel()
            .channelProcessors(
                    Arrays.<ChannelProcessor> asList(
                            new InsecureChannelProcessor(),
                            new SecureChannelProcessor()));

    http.portMapper().http(8080).mapsTo(8443).http(80).mapsTo(44)
            .http(9080).mapsTo(9443).http(7777).mapsTo(7443);
}

/**
 * Auth filter.
 * 
 * @return the auth filter
 */
@Bean
public AuthFilter authFilter() {
    AuthFilter authFilter = new AuthFilter();
    try {

        authFilter
                .setRequiresAuthenticationRequestMatcher(new AntPathRequestMatcher(
                        "/loginSSO"));
        authFilter.setAuthenticationManager(authenticationManager());

    } catch (Exception e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
    return authFilter;
}

@Autowired
@Qualifier("customUserDetailsService")
UserDetailsService userDetailsService;

@Bean
public SavedRequestAwareAuthenticationSuccessHandler successHandler() {
    SavedRequestAwareAuthenticationSuccessHandler successHandler = new SavedRequestAwareAuthenticationSuccessHandler();
    successHandler.setTargetUrlParameter("targetUrl");
    return successHandler;
}

@Autowired
public void configure(AuthenticationManagerBuilder auth) throws Exception {
    auth.userDetailsService(userDetailsService);
}

/**
 * Csrf token repository.
 * 
 * @return the csrf token repository
 */
private CsrfTokenRepository csrfTokenRepository() {
    HttpSessionCsrfTokenRepository repository = new HttpSessionCsrfTokenRepository();
    repository.setSessionAttributeName("_csrf");
    repository.setHeaderName("X-XSRF-TOKEN");
    return repository;
}

}

【问题讨论】:

  • 这个问题只发生在公司服务器上,而不是我的本地主机上
  • 我的第一个猜测是旧版 IE + 公司代理的副作用。

标签: java spring-mvc internet-explorer spring-security jsessionid


【解决方案1】:

此问题已解决。恰好是 Websphere application.xml 文件中应用上下文根配置的问题。

【讨论】:

  • 这不是一个有效的答案。你必须开发更多。我面临同样的问题,您没有提供任何有关您为解决该问题所做的工作的信息。
  • 抱歉回复晚了。 EAR 文件上下文根上发生的问题未正确映射到 websphere 上。所以浏览器上没有正确设置 jSession cookie 上下文根来维护会话状态。在服务器上修复上下文根后它工作了。
猜你喜欢
  • 2018-11-15
  • 2016-01-12
  • 2012-02-24
  • 1970-01-01
  • 1970-01-01
  • 2021-09-11
  • 2019-08-08
  • 2014-03-29
  • 1970-01-01
相关资源
最近更新 更多