antMatchers that matches any beginning of path

后端 未结 1 1764
悲&欢浪女
悲&欢浪女 2020-12-07 02:31

I\'ve got REST service that will be used for authentication. The authentication endpoint will look like /api/v.1/authentication. The API version is a variable t

相关标签:
1条回答
  • 2020-12-07 03:06

    You have to use absolute pattern, see AntPathMatcher:

    Note: a pattern and a path must both be absolute or must both be relative in order for the two to match. Therefore it is recommended that users of this implementation to sanitize patterns in order to prefix them with "/" as it makes sense in the context in which they're used.

    Your modified and simplified configuration:

    @Override
    protected void configure(HttpSecurity http) throws Exception {
        http
            .sessionManagement()
                .sessionCreationPolicy(SessionCreationPolicy.STATELESS)
                .and()
            .csrf().disable()
            .authorizeRequests()
                .antMatchers(HttpMethod.POST, "/**/authenticate").permitAll()
                .antMatchers(HttpMethod.GET, "/**/get-public-key").permitAll()
                .antMatchers(HttpMethod.OPTIONS, "/**").permitAll()
                .anyRequest().authenticated();
    }
    
    0 讨论(0)
提交回复
热议问题