简体   繁体   English

如何使用spring安全性仅保护一个URL并允许所有

[英]how to secure only one url with spring security and permit all

Im trying to configure Spring security to block only request to swagger, however it is blocking all urls. 我试图将Spring安全性配置为仅阻止请求摇摇欲坠,但是它阻止了所有URL。 Does anyone know how to only lock the swagger's url and leave all the rest not secured? 有谁知道如何只锁定招摇号的网址,而其余所有都不固定?

protected void configure(HttpSecurity http) throws Exception {

        http.csrf().disable()
        .authorizeRequests().anyRequest().permitAll()
        .and()
        .authorizeRequests()
            .antMatchers("/swagger*/**").authenticated();

        http.httpBasic();
    }

Try the following: 请尝试以下操作:

http.authorizeRequests()
.antMatchers("/swagger*/**").authenticated()
.anyRequest().permitAll()
.and()
.csrf().disable();

This should only authenticate swagger but permit the rest of the requests. 这仅应验证摇摇欲坠,但允许其余请求。

Is this what you intent ? 这是你的意图吗?

protected void configure(HttpSecurity http) throws Exception {

    http.csrf().disable()
    .authorizeRequests()
        .antMatchers("/swagger*/**").authenticated()
        .anyRequest().permitAll();            

    http.httpBasic();
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM