我开发一个弹簧引导应用程序和问题,我有如下:春季安全的Oauth 2重定向行为对/的OAuth /令牌
默认情况下,我的控制器每个请求重定向到/登录,所以我不能用这种方式。
我可以通过在application.properties设置
security.oauth2.resource.filter-order = 3
禁用/登录。
但我想知道如何禁用它只适用于非浏览器,所以我仍然可以使用登录。
编辑:
这将是我的做法:从什么/ API运行
http.antMatcher("/api/**")
.authorizeRequests().anyRequest().authenticated();
http.antMatcher("/**")
.formLogin();
一切/是休息和只能由端Oauth处理。 其余应通过登录处理。
但它仍然没有工作,我仍然得到重定向。
没关系,修复它。感谢userWithLongNumber!
就我而言,事实证明我的WebSecurity配置错误。 这现在工作:
@Override
protected void configure(HttpSecurity http) throws Exception {
http.
formLogin().permitAll()
.and()
.authorizeRequests().anyRequest().authenticated();
}
我RessourceServerConfig看起来是这样的:
@Override
public void configure(HttpSecurity http) throws Exception {
http
.exceptionHandling()
.authenticationEntryPoint(customAuthenticationEntryPoint)
.and()
.logout()
.logoutUrl("/oauth/logout")
.logoutSuccessHandler(customLogoutSuccessHandler)
.and()
.headers()
.frameOptions().disable()
.and()
.sessionManagement()
.sessionCreationPolicy(SessionCreationPolicy.STATELESS)
.and()
.authorizeRequests()
.antMatchers("/api/**").authenticated();
}
}