将您的Spring
Boot版本更新为1.3.0.RELEASE,您将
Http401AuthenticationEntryPoint免费获得。像这样在您的安全配置中配置身份验证入口点:
@Overrideprotected void configure(HttpSecurity http) throws Exception { http .csrf().disable() .authorizeRequests() .antMatchers(PROTECTED_RESOURCES) .hasRole("USER") .anyRequest() .permitAll() .and() .anonymous().disable() .exceptionHandling() .authenticationEntryPoint(new org.springframework.boot.autoconfigure.security.Http401AuthenticationEntryPoint("headerValue"));}然后Spring Boot将返回
HTTP 401:
Status Code: 401 UnauthorizedCache-Control: no-cache, no-store, max-age=0, must-revalidateExpires: 0Pragma: no-cacheServer: Apache-Coyote/1.1Transfer-Encoding: chunkedWWW-Authenticate: headerValueX-Content-Type-Options: nosniffx-xss-protection: 1; mode=block



