0
我已經看過谷歌文檔中的Oauth2工作流程,它看起來非常直觀。使用基本的servlet我知道如何處理所有的回調,但使用Spring Boot我有點困惑,如果我使用oauth和Spring安全模塊,我需要做的事情。spring boot和google oauth
我發現一篇教程here描述如何使用用戶名和密碼添加認證,但我不確定這是否是我的需求的最佳選擇,因爲我主要想限制頁面中的內容而不是頁面本身。無論如何,假設我需要每頁身份驗證,我如何設置使用Oauth的用戶?看看這個教程,看起來安全模塊正在做一些神奇的事情來獲取相對於內存數據庫的用戶名/密碼。
@Configuration
@EnableWebMvcSecurity
public class WebSecurityConfig extends WebSecurityConfigurerAdapter {
@Override
protected void configure(HttpSecurity http) throws Exception {
http
.authorizeRequests()
.antMatchers("/", "/home").permitAll()
.anyRequest().authenticated()
.and()
.formLogin()
.loginPage("/login")
.permitAll()
.and()
.logout()
.permitAll();
}
@Autowired
public void configureGlobal(AuthenticationManagerBuilder auth) throws Exception {
auth
.inMemoryAuthentication()
.withUser("user").password("password").roles("USER");
}
}
在上面的例子我看到configureGlobal
設置的用戶名/密碼存儲到覈對。春季引導有用戶名/密碼的硬編碼邏輯,這將阻止我將它用於Oauth2嗎?我應該忽略這個安全模塊並直接使用我自己的處理程序來設置用戶嗎?
你是如何配置你的項目到谷歌最終使用oauth? – jpboudreault 2015-02-21 04:04:39