小编b0c*_*0c1的帖子

带有Jersey基本身份验证的Spring Boot总是404

我尝试使用jersey和spring安全性创建一个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");
    }
}
Run Code Online (Sandbox Code Playgroud)

我的泽西岛控制器:

@Component
@Path("/")
public class Home {

    @GET
    @Produces("application/json")
    public String list() {
        String email = (String) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
        return email;
    }
}
Run Code Online (Sandbox Code Playgroud)

如果没有Spring安全性(如果我允许所有请求),则应用程序控制器将运行,但是如果启用httpBasic身份验证,则始终会获得http 404。

任何的想法?

java spring spring-security jersey-2.0 spring-boot

2
推荐指数
1
解决办法
1423
查看次数

标签 统计

java ×1

jersey-2.0 ×1

spring ×1

spring-boot ×1

spring-security ×1