Я добавил эту зависимость в свое приложение Spring Boot
org.springdoc
springdoc-openapi-ui
1.4.3
pom.sha512
Тогда мне удалось открыть:
https://localhost:8443/v3/api-docs
Браузер запрашивает мои учетные данные, и пока я правильно ввожу пользователя/пароль, он работает, но показывает мне ВСЕ методы, доступные глобально. Я бы хотел, чтобы в документации API отображались только те методы, на которые у пользователя есть права.
Для конкретного метода используйте этот тег для авторизации моего вызова:
@PreAuthorize("hasRole('USER') OR hasRole('ADMIN')")
Это мой класс конфигурации веб-безопасности:
@Configuration
@EnableWebSecurity
@EnableGlobalMethodSecurity(prePostEnabled = true)
public class WebSecurityConfig extends WebSecurityConfigurerAdapter
{
@Override
protected void configure(AuthenticationManagerBuilder auth) throws Exception
{
auth.inMemoryAuthentication()
.passwordEncoder(new BCryptPasswordEncoder())
.withUser("user").password(new BCryptPasswordEncoder().encode("blabl")).roles("USER")
.and()
.withUser("admin").password(new BCryptPasswordEncoder().encode("blabla")).roles("ADMIN");
}
@Override
protected void configure(HttpSecurity http) throws Exception
{
http.authorizeRequests()
.antMatchers("/").permitAll()
.anyRequest().authenticated()
.and()
.httpBasic();
}
}
Подробнее здесь: https://stackoverflow.com/questions/632 ... pring-boot