2
我需要为登台服务器设置全局基本HTTP身份验证。没有什么花哨。我只想要求用户名/密码来访问任何东西。我也只想使用Java配置。我已经尝试了很多不同的解决方案,但都没有工作。我总是能够访问服务器上的所有资源。这是我现在在做什么:Spring MVC 4全局基本HTTP身份验证
@Configuration
@EnableWebSecurity
public class WebSecurityConfig extends WebSecurityConfigurerAdapter {
@Override
protected void configure(HttpSecurity http) throws Exception {
System.out.println("Configuring HttpSecurity");
http
.authorizeRequests()
.anyRequest().authenticated()
.and()
.httpBasic();
}
@Autowired
public void configureGlobal(AuthenticationManagerBuilder auth) throws Exception {
System.out.println("Configuring global AuthenticationManagerBuilder");
auth
.inMemoryAuthentication()
.withUser("user").password("password").roles("USER");
}
}
我可以在正在执行这些片段中的日志中看到。如您所见,在第一种方法中,我要求所有请求都经过身份验证。在第二种方法中,我在内存认证中指定。
你得到的错误是什么?还有你是如何尝试登录的?需要更多的信息给问题 – ArunM
没有错误。问题是我没有提示执行基本的HTTP身份验证。每当请求任何资源时,我都希望始终需要基本的HTTP身份验证。 –