【问题标题】:What is the correct antmatcher for this URI?此 URI 的正确匹配器是什么?
【发布时间】: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

【问题讨论】:

    标签: spring-security spring-4


    【解决方案1】:

    我能够让它与以下蚂蚁匹配器一起工作。

    .antMatchers(HttpMethod.GET, "/" + Constants.restApiUriPrefix + UserController.uriExtension + "*")
    .permitAll()
    

    【讨论】:

      猜你喜欢
      • 2013-05-19
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-05-02
      相关资源
      最近更新 更多