Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/spring-boot/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Spring引导授权基本头永远不会更改_Spring_Spring Boot - Fatal编程技术网

Spring引导授权基本头永远不会更改

Spring引导授权基本头永远不会更改,spring,spring-boot,Spring,Spring Boot,我正在尝试设置一个非常基本的spring boot认证应用程序。我正在客户端设置授权头并将其发送到后端。我可以验证客户端是否发送了正确的头 后端在第一次尝试登录时正确接收标头。但是,如果登录凭据不正确,后续请求将保留初始请求的头(缓存它或其他内容) 我正在使用Redis缓存会话。我的配置如下: @Configuration @EnableWebSecurity public class WebSecurityConfig extends WebSecurityConfigurerAdapter

我正在尝试设置一个非常基本的spring boot认证应用程序。我正在客户端设置授权头并将其发送到后端。我可以验证客户端是否发送了正确的头

后端在第一次尝试登录时正确接收标头。但是,如果登录凭据不正确,后续请求将保留初始请求的头(缓存它或其他内容)

我正在使用Redis缓存会话。我的配置如下:

@Configuration
@EnableWebSecurity
public class WebSecurityConfig extends WebSecurityConfigurerAdapter {

    @Autowired AuthenticationEntryPoint authenticationEntryPoint;
    @Autowired CsrfTokenRepository csrfTokenRepository;


    @Override
    protected void configure(HttpSecurity http) throws Exception {
        http
            .exceptionHandling()
            .authenticationEntryPoint(authenticationEntryPoint)
            .and()
        .csrf()
            .disable()
        .authorizeRequests().antMatchers("**")
            .permitAll()
            .anyRequest()
            .authenticated()
            ;
    }
}
AuthenticationEntryPoint

public class AuthenticationEntryPointBean {
@Bean
    AuthenticationEntryPoint authenticationEntryPoint() {
        return new RestAuthenticationEntryPoint();
    }
}
任何指示都将不胜感激

**编辑** 添加缓存设置

@Configuration
@EnableRedisHttpSession
public class HttpSessionConfig {

    @Bean
    public JedisConnectionFactory connectionFactory() {
        return new JedisConnectionFactory(); // <2>
    }
}

将以下内容添加到我的web安全配置中似乎就达到了目的

.requestCache()
.requestCache(new NullRequestCache())
我不知道这样做有什么副作用。我从博客上找到的

如果有任何关于这是好的做法还是坏的做法的更多见解,我将不胜感激

我的最终web安全配置如下所示:

 http
        .exceptionHandling()
            .authenticationEntryPoint(authenticationEntryPoint)
            .and()
        .csrf()
            .disable()
        .authorizeRequests().antMatchers("**")
            .permitAll()
            .anyRequest()
            .authenticated()
            .and()
        .requestCache()
            .requestCache(new NullRequestCache())
            .and()
        .sessionManagement()
            .sessionFixation()
            .newSession()
            ;

将以下内容添加到我的web安全配置中似乎就达到了目的

.requestCache()
.requestCache(new NullRequestCache())
我不知道这样做有什么副作用。我从博客上找到的

如果有任何关于这是好的做法还是坏的做法的更多见解,我将不胜感激

我的最终web安全配置如下所示:

 http
        .exceptionHandling()
            .authenticationEntryPoint(authenticationEntryPoint)
            .and()
        .csrf()
            .disable()
        .authorizeRequests().antMatchers("**")
            .permitAll()
            .anyRequest()
            .authenticated()
            .and()
        .requestCache()
            .requestCache(new NullRequestCache())
            .and()
        .sessionManagement()
            .sessionFixation()
            .newSession()
            ;

您可能需要在问题中包括缓存配置。一个现成的猜测是缓存配置不正确,因此它不知道如何在登录失败时使缓存内容无效,因此它只返回缓存的会话信息。您可能需要在问题中包括缓存配置。一个现成的猜测是缓存配置不正确,因此它不知道如何在登录失败时使缓存内容无效,因此它只返回缓存的会话信息。是的,这正是您所需要的。如果没有
.requestCache(new NullRequestCache())
,请求将被缓存,这就是为什么第二次登录尝试会显示相同的参数。是的,这正是您所需要的。如果没有
.requestCache(new NullRequestCache())
,请求将被缓存,这就是为什么第二次登录尝试会显示相同的参数。