2017-06-20 130 views
-1

我想禁用具有spring安全性的资源的认证。资源url包含一个java uuid。我的匹配器不符合uuid。Spring Security antMatchers UUID

web.ignoring().antMatchers(HttpMethod.GET, "/tobaccos/^[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$"); 

这段代码匹配/ tobaccos后面的所有内容。但我只想匹配例如/烟草/ 4da42fa2-4fad-4c7f-af77-1d7890741009

我该如何解决我的问题?

回答

1

你需要雇用regexMatchers()使用正则表达式(在你的情况),而不是antMatchers()(其预计Ant Patterns)。

此外,^似乎并不需要在中间。

web.ignoring().regexMatchers(HttpMethod.GET, "/tobaccos/[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$"); 

这将匹配任何/ tobaccos/$ UUID URL(以$ UUID结尾)。

web.ignoring().regexMatchers(HttpMethod.GET, "/tobaccos/[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}/.*"); 

在UUID后面还会有东西。