In Specific
我想只为特定的URL模式进行HTTP基本身份验证 .
In Detail
我正在为我的应用程序创建一个API接口,需要通过简单的HTTP基本身份验证进行身份验证 . 但是其他网页应该使用HTTP basic,而不是普通的表单登录 .
Current Configuration - NOT Working
@Override
protected void configure(HttpSecurity http) throws Exception {
http //HTTP Security
.csrf().disable() //Disable CSRF
.authorizeRequests() //Authorize Request Configuration
.antMatchers("/connect/**").permitAll()
.antMatchers("/", "/register").permitAll()
.antMatchers("/admin/**").hasRole("ADMIN")
.antMatchers("/api/**").hasRole("API")
.anyRequest().authenticated()
.and() //HTTP basic Authentication only for API
.antMatcher("/api/**").httpBasic()
.and() //Login Form configuration for all others
.formLogin().loginPage("/login").permitAll()
.and() //Logout Form configuration
.logout().permitAll();
}
2 回答
等了2天,在这里没有得到任何帮助 . 但我的研究为我提供了解决方案:)
Solution
我不知道它是否有用,但我无法实现上述解决方案 . 我找到了一个定义单个安全性的解决方法
扩展
同时配置了httpBasic()和formLogin() . 然后我创建了一个自定义
在开始方法中有这个逻辑:
Dunno是关于这个问题的“最佳实践战略”