【发布时间】:2015-10-02 08:50:34
【问题描述】:
我尝试使用 jersey 和 spring security 创建一个 SpringBoot 应用程序。 我想使用基本身份验证保护我的整个应用程序。 我的安全配置:
@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;
}
}
没有 Spring 安全性(如果我允许所有请求)应用程序控制器运行,但如果我启用 httpBasic 身份验证,我总是得到 http 404。
有什么想法吗?
【问题讨论】:
标签: java spring spring-security spring-boot jersey-2.0