在"无状态模式下"避免使用Spring安全认证创建JSESSIONID cookie

mem*_*mi 8 java spring spring-security

我需要建立一个无状态的休息服务.因此,不能在应用服务器上创建会话,也不能在标头响应中创建JSESSIONID cookie.

在我的spring XML文件中,我添加了以下配置:

  <http create-session="stateless"  disable-url-rewriting="true" use-expressions="true">
  <intercept-url pattern="/product/**" />
  <intercept-url pattern="/*"  />
  <http-basic />
 </http>
Run Code Online (Sandbox Code Playgroud)

这样就不会创建JSESSIONID cookie.Everthing还可以.

但是,只要添加身份验证配置,就像下面这样:

<context:component-scan base-package="training.rest" />
 <http create-session="stateless" use-expressions="true">
  <intercept-url pattern="/product/**" access="hasRole('ROLE_ADMIN')"/>
  <http-basic />
 </http>

 <authentication-manager alias="authenticationManager">
  <authentication-provider>
   <user-service>
    <user authorities="ROLE_ADMIN" name="user1" password="password1" />
   </user-service>
  </authentication-provider>
 </authentication-manager>
Run Code Online (Sandbox Code Playgroud)

我在响应头中看到了JSESSIONID.

如何解决此问题并确保在标头响应中未返回JSESSIONID cookie?