使用Spring Boot 1.3,Spring Boot中的Oauth2有一个自动配置。
有一个spring guide提供了一些很好的例子,但我希望实现一个不同的解决方案。 我的问题基于提供的click示例。 我想在访问“/ login”端点后重定向到授权服务器。如果我在没有身份验证的情况下请求受保护的资源,我想获得401(未授权)而不是即时重定向(302)到授权uri。
这是点击示例的
的Java代码 @Override
protected void configure(HttpSecurity http) throws Exception {
http.antMatcher("/**")
.authorizeRequests()
.antMatchers("/", "/login**", "/webjars/**")
.permitAll()
.anyRequest()
.authenticated()
.and()
.exceptionHandling()
.authenticationEntryPoint(new Http401AuthenticationEntryPoint("Session realm=\"JSESSIONID\""));
}
我尝试添加自定义AuthenticationEntryPoint,但似乎只是忽略了这一点:(
我尝试了什么:
<peoplesearchlist [people]="peopleSearchData"></peoplesearchlist>
点击示例的完整源代码可以在github上找到。
是否可以实现401而不是重定向?
答案 0 :(得分:0)
在spring-boot 1.3.0之前,由于在使用此组合时应用自定义配置程序的顺序存在问题,因此无法执行此操作(请参阅#4629 for further resolution)。
从spring-boot 1.3.1开始,请求标头X-Requested-With: XMLHttpRequest
表示呼叫者更喜欢401 Unauthorized
而不是302 Found