首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Spring安全配置错误

Spring安全配置错误
EN

Stack Overflow用户
提问于 2022-07-07 06:12:46
回答 1查看 27关注 0票数 0

我试图为actuator端点启用基本的http身份验证,同时保留api端点的jwt身份验证。为此,我尝试了以下配置:

代码语言:javascript
复制
  @Override
  public void configure(HttpSecurity http) throws Exception {
    http.csrf()
        .disable()
        .anonymous()
        .disable()
        .sessionManagement()
        .sessionCreationPolicy(SessionCreationPolicy.STATELESS)
        .and()
        .antMatcher("/service/actuator/**")
        .httpBasic()
        .and()
        .authorizeRequests()
        .antMatchers("/service/api/**")
        .authenticated()
        .anyRequest()
        .authenticated()
        .and()
        .exceptionHandling()
        .authenticationEntryPoint(restAuthenticationEntryPoint);

    http.addFilterBefore(jwtTokenFilter, UsernamePasswordAuthenticationFilter.class);
  }

但是,我似乎也可以对actuator端点使用JWT令牌和基本auth,而对所有api端点也不进行身份验证。我把命令搞砸了吗?有更好的方法吗?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2022-07-07 07:12:01

下面这句话对我有用

代码语言:javascript
复制
  @Override
  public void configure(HttpSecurity http) throws Exception {
    http.csrf()
        .disable()
        .anonymous()
        .disable()
        .sessionManagement()
        .sessionCreationPolicy(SessionCreationPolicy.STATELESS)
        .and()
        .authorizeRequests()
        .antMatchers("/service/actuator/**")
        .permitAll()
        .and()
        .httpBasic()
        .and()
        .authorizeRequests()
        .antMatchers("/service/api/**")
        .authenticated()
        .anyRequest()
        .authenticated()
        .and()
        .exceptionHandling()
        .authenticationEntryPoint(restAuthenticationEntryPoint);

    http.addFilterBefore(jwtTokenFilter, UsernamePasswordAuthenticationFilter.class);
  }
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/72893018

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档