【发布时间】:2017-01-19 01:01:11
【问题描述】:
我有一个使用 Spring Security 进行身份验证的现有 Web 应用程序。它还使用会话管理来允许用户在预定义的时间段内登录,并使用 XSRF 令牌来防止 XSS 攻击。
@Override
protected void configure(HttpSecurity http) throws Exception {
// @formatter:off
http
.exceptionHandling()
.authenticationEntryPoint(restEntryPoint())
.and()
.headers().addHeaderWriter(new StaticHeadersWriter("Server",""))
.and()
.httpBasic()
.authenticationEntryPoint(restEntryPoint())
.and()
.logout().addLogoutHandler(myLogoutHandler())
.logoutSuccessHandler(logoutSuccessHandler())
.and()
.authorizeRequests()
.antMatchers("/index.html", "/login", "/").permitAll()
.antMatchers(HttpMethod.OPTIONS).denyAll()
.antMatchers(HttpMethod.HEAD).denyAll()
.anyRequest().authenticated()
.and()
.authenticationProvider(myAuthenticationProvider)
.csrf()
.csrfTokenRepository(csrfTokenRepository())
.and()
.addFilterAfter(csrfHeaderFilter(), SessionManagementFilter.class);
// @formatter:on
}
这非常适合 Web 应用程序。但是,现在我被要求添加一个配置,允许第三方客户端应用程序通过纯 REST 调用调用我的服务,即它们应该是完全无状态的并使用 http 基本身份验证 - 不应该创建会话并且应该禁用 xsrf(我想想……)。
我可以为所有这些客户端 API 调用定义一个共享 URL 路径。但是如何利用我现有的安全配置和服务器来支持这两个要求?
【问题讨论】:
标签: java spring security session spring-security