【发布时间】:2015-01-29 19:25:32
【问题描述】:
我查看了 Google 文档上的 Oauth2 工作流程,它看起来非常直观。使用基本的 servlet,我了解如何处理所有回调,但是使用 Spring Boot,如果我使用 oauth 和 Spring 安全模块,我对我需要做什么感到有点困惑。
我找到了一个教程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 设置了要检查的用户名/密码存储。 spring boot 是否有用户名/密码的硬编码逻辑,会阻止我将它用于 Oauth2?我应该忽略这个安全模块并使用我自己的处理程序直接设置用户吗?
【问题讨论】:
-
最后你是如何配置你的项目使用 oauth 和 google 的?