我尝试创建使用的球衣和春季安全SpringBoot应用。 我想用基本认证来保护我的整个应用程序。 我的安全配置:春季启动与新泽西基本验证总是404
@Configuration
@EnableWebSecurity
@EnableGlobalMethodSecurity(jsr250Enabled = true, securedEnabled = true, prePostEnabled = true)
public class WebSerucityConfig extends WebSecurityConfigurerAdapter {
@Override
protected void configure(HttpSecurity http) throws Exception {
http.authorizeRequests().anyRequest().authenticated().and().httpBasic();
@Override
public void configure(WebSecurity web) throws Exception {
web.debug(true);
}
@Autowired(required = false)
public void configureGlobal(AuthenticationManagerBuilder auth) throws Exception {
auth
.inMemoryAuthentication()
.withUser("user").password("password").roles("USER").and()
.withUser("admin").password("password").roles("USER", "ADMIN");
}
}
我的球衣控制器:
@Component
@Path("/")
public class Home {
@GET
@Produces("application/json")
public String list() {
String email = (String) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
return email;
}
}
没有春季安全(如果我允许所有的请求),应用控制器运行,但如果我能httpBasic验证我总是HTTP 404。
有什么想法?