在特定子路径上禁用 BasicAuth
Disable BasicAuth on specific sub paths
我知道有一些关于 Whosebug 的问题,但没有任何帮助...
http
.addFilterBefore(RestConfiguration.getCorsFilter(), ChannelProcessingFilter.class)
.authorizeRequests() //Authorize Request Configuration
.antMatchers("/api/**").hasRole("API")
.antMatchers("/api/confirm/**").permitAll()
.antMatchers("/api/version").permitAll()
.anyRequest().authenticated()
.and() //HTTP basic Authentication only for API
.antMatcher("/api/**").httpBasic()
.and() // angularjs requires csrf
.addFilterAfter(new CsrfHeaderFilter(), CsrfFilter.class)
.csrf().disable();
我有一个包含一些子路径的 api 路径。但是我想在没有基本身份验证的情况下访问其中两个(confirm/**
和 version
)。
我该怎么做?我总是得到登录对话框。
您应该在 /api/confirm/**
和 /api/version
之后使用 antMatchers("/api/**").hasRole("API")
规则。当前排序不太正确:
.antMatchers("/api/confirm/**").permitAll()
.antMatchers("/api/version").permitAll()
.antMatchers("/api/**").hasRole("API")
总而言之,如果您只想保护 /api/*
并让 public 访问 /api/confirm/**
、/api/version
和所有其他没有 api
的路径前缀,你应该有这样的 HttpSecurity
配置:
http
// Same as before
.httpBasic()
.and()
.authorizeRequests()
.antMatchers("/api/confirm/**").permitAll()
.antMatchers("/api/version").permitAll()
.antMatchers("/api/**").hasRole("API")
.anyRequest().permitAll();
// Same as before
我知道有一些关于 Whosebug 的问题,但没有任何帮助...
http
.addFilterBefore(RestConfiguration.getCorsFilter(), ChannelProcessingFilter.class)
.authorizeRequests() //Authorize Request Configuration
.antMatchers("/api/**").hasRole("API")
.antMatchers("/api/confirm/**").permitAll()
.antMatchers("/api/version").permitAll()
.anyRequest().authenticated()
.and() //HTTP basic Authentication only for API
.antMatcher("/api/**").httpBasic()
.and() // angularjs requires csrf
.addFilterAfter(new CsrfHeaderFilter(), CsrfFilter.class)
.csrf().disable();
我有一个包含一些子路径的 api 路径。但是我想在没有基本身份验证的情况下访问其中两个(confirm/**
和 version
)。
我该怎么做?我总是得到登录对话框。
您应该在 /api/confirm/**
和 /api/version
之后使用 antMatchers("/api/**").hasRole("API")
规则。当前排序不太正确:
.antMatchers("/api/confirm/**").permitAll()
.antMatchers("/api/version").permitAll()
.antMatchers("/api/**").hasRole("API")
总而言之,如果您只想保护 /api/*
并让 public 访问 /api/confirm/**
、/api/version
和所有其他没有 api
的路径前缀,你应该有这样的 HttpSecurity
配置:
http
// Same as before
.httpBasic()
.and()
.authorizeRequests()
.antMatchers("/api/confirm/**").permitAll()
.antMatchers("/api/version").permitAll()
.antMatchers("/api/**").hasRole("API")
.anyRequest().permitAll();
// Same as before