GET参数的蚂蚁匹配器

时间:2018-08-30 19:25:24

标签: java spring spring-boot ant

使用Java + SpringBoot,我正在尝试创建和终结点以确认用户电子邮件。

我生成并发送的链接为/confirm-email?id=x&token=xyztetc

但是,由于只有/signup被允许在没有Bearer令牌的情况下被访问,因此该链接将始终获得403响应。我试图添加/confirm-email?{id:.+}&{token:.+}以获得允许,但没有成功。

我100%肯定未正确编写正则表达式,但找不到任何相关的Ant模式文档进行检查。

2 个答案:

答案 0 :(得分:0)

我不认为蚂蚁使用.来匹配任何字符,而是使用?

https://docs.spring.io/spring/docs/current/javadoc-api/org/springframework/util/AntPathMatcher.html

答案 1 :(得分:0)

为了允许使用正则表达式匹配器,必须使用.regexMatchers()而不是.antMatchers()

有关更多信息,请参见此类:

org.springframework.security.web.util.matcher.RegexRequestMatcher

在您的情况下会是这样的:

public class ServerSecurityAppConfig extends ResourceServerConfigurerAdapter {

    // ...

    private static final String[] UNAUTHENTICATED_ROUTES = new String[] {
            "/confirm-email?{.+}&{.+}",
    };


    @Override
    public void configure(final HttpSecurity http) throws Exception {
        http
                .authorizeRequests()
                .regexMatchers( UNAUTHENTICATED_ROUTES ).permitAll()
                .anyRequest().access( myAppSecurityExpression );
    }

相关问题