我開發一個彈簧引導應用程序和問題,我有如下:春季安全的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();
}
}