【发布时间】:2015-01-09 16:10:04
【问题描述】:
我有一个带有这样映射的控制器。我已经为常量提供了值。
Constants.restApiUriPrefix = "rest/"
UserController.uriExtension = "users"
@RequestMapping(value = Constants.restApiUriPrefix + UserController.uriExtension)
public class UserController {
@RequestMapping(params = "username")
@ResponseBody
public ResponseWithView<User> getUserByName(@RequestParam String username, @ModelAttribute User authenticatingUser) {
return new ResponseWithView<User>(userService.findByUsername(username));
}
}
当我运行测试时,我使用来自 Web 服务器根上下文的以下 URI。
/rest/users?username=testUser%40gmail.com
这是我的安全配置。
@Override
protected void configure(HttpSecurity http) throws Exception {
if(environment == Environment.DEVELOPMENT) {
http.authorizeRequests().antMatchers("/" + Constants.restApiUriPrefix + TestHelperController.uriExtension + "/**").permitAll();
}
http.csrf().disable(); //TODO Someday fix this and turn csrf back on safely
http
.httpBasic()
.and()
.authorizeRequests()
.antMatchers(HttpMethod.GET, "/" + Constants.restApiUriPrefix + UserController.uriExtension + "?username=**").permitAll()
.antMatchers(HttpMethod.POST, "/" + Constants.restApiUriPrefix + UserController.uriExtension + "/").permitAll()
.antMatchers(HttpMethod.POST, "/" + Constants.restApiUriPrefix + UserController.uriExtension).permitAll()
.antMatchers("/" + Constants.restApiUriPrefix + "**").hasRole("USER");
}
我期待
.antMatchers(HttpMethod.GET, "/" + Constants.restApiUriPrefix + UserController.uriExtension + "?username=**").permitAll()
为了匹配我的请求,通过用户名发现用户以通过身份验证而不受到挑战,但我是。
我正在使用 Spring 4.0.2.RELEASE 和 Spring Security 3.2.0.RELEASE
【问题讨论】: