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