【发布时间】:2015-04-14 00:16:29
【问题描述】:
我正在尝试使用 Spring 配置 RESTFul Web 服务,并且我已经配置了 OAuth。所以我得到了几个需要用户 OAuth 令牌的页面。但是,我有一些用于匿名访问的页面,例如注册或忘记密码。
像 www.mywebsite.com/api/doStuff [GET/POST] 这样的页面需要有效的 OAuth 令牌来保护,但是我如何使用 保护像 www.mywebsite.com/api/signup [POST] 这样的页面仅 客户 ID 和 secret 带有标头 Authorization: Basic [Base64EncodedString] ?
我不希望任何人访问这些“不安全的页面”,但客户端(例如移动应用程序 (iOS/Android))除外。
这是我的 ResourceServerConfigurerAdapter 类中的 configure(HttpSecurity) 方法
public void configure(HttpSecurity http) throws Exception {
http
.requestMatchers().antMatchers("/api/**")
.and()
.authorizeRequests()
.antMatchers("/api/doStuff", "/api/getOtherStuff").access("#oauth2.hasScope('read') and hasRole('ROLE_USER')")
.antMatchers("/api/signup").access("#oauth2.isClient()") // Not working like I thought...
.and().sessionManagement().sessionCreationPolicy(SessionCreationPolicy.STATELESS);
}
感谢您的帮助!
【问题讨论】:
标签: java spring spring-mvc spring-security spring-security-oauth2