有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

java为授权和非授权restful服务配置Spring安全性

我有一个SpringBoot应用程序,提供安全的RESTfulWeb服务。它在自己的WebSecurityConfigurerAdapter类中与以下HttpSecurity配置配合得很好:

@Override
protected void configure(HttpSecurity http) throws Exception {
   http.csrf().disable();
   http.sessionManagement().sessionCreationPolicy(SessionCreationPolicy.STATELESS);
   http.authorizeRequests()
      .antMatchers("/secure/**").hasRole(ROLE_XXX)
      .anyRequest().authenticated().and().httpBasic();
}

此配置强制所有Web服务在/secure下进行授权。 现在我想添加另一个Web服务,比如/public/test,它可以在没有任何身份验证的情况下调用。有什么建议吗


共 (1) 个答案

  1. # 1 楼答案

    重写void configure(WebSecurity web)方法解决了我的问题:

    @Override
    public void configure(WebSecurity web) throws Exception {
    web.ignoring().antMatchers("/public/**");
    }