2017-06-20 137 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後面還會有東西。