Как можно добавить кастомный фильтр для проверки JWT токена

Здравствуйте, как можно создать кастомный фильтр для проверки JWT токена?
Фильтр создается, но выполняется в самом конце. Как можно задать очередь?
Пробовал добавлять @Order(JmixSecurityFilterChainOrder.FLOWUI - 10) на бин SecurityFilterChain-а, не помогло.

Основная цель: Создать 2 открытых эндпойнта /auth/login и /auth/register, которые будут возвращать токен. Далее во всех запросах по пути /api/** должен валидироваться токен…

Здравствуйте,

С помощью аннотации @Order(…) вы задаете очередность для компонента, то есть при добавлении аннотации на метод public SecurityFilterChain securityFilterChain(HttpSecurity http) вы задаёте приоритет вашей конфигурации над уже ранее созданными securityFilterChain.

Для добавления кастомного фильтра в цепочке фильтров вы можете воспользоваться одним из методов addFilter() (подробнее по ссылке ниже).

Пример добавления кастомного фильтра, который будет выполняться до AnonymousAuthenticationFilter фильтра:

    @Bean
    @Order(JmixOrder.HIGHEST_PRECEDENCE + 200)
    public SecurityFilterChain securityFilterChain(HttpSecurity http) throws Exception {
        ....
        http.addFilterBefore(
                new CustomAuthenticationProcessingFilter(getRequestMatchers(),
                        authenticationConfiguration.getAuthenticationManager()),
                AnonymousAuthenticationFilter.class
        );
        ...
        return http.build();
    }


    private RequestMatcher getRequestMatchers() {
        return new OrRequestMatcher(new AntPathRequestMatcher("/api/**"));
    }

CustomAuthenticationProcessingFilter:

public class CustomAuthenticationProcessingFilter extends AbstractAuthenticationProcessingFilter {

    ...

    @Override
    public Authentication attemptAuthentication(HttpServletRequest request,
                                                HttpServletResponse response) throws AuthenticationException {

        //todo
        return new UsernamePasswordAuthenticationToken(user, password, authorities);
    }

    @Override
    protected void successfulAuthentication(HttpServletRequest request,
                                            HttpServletResponse response,
                                            FilterChain chain,
                                            Authentication authResult) throws IOException, ServletException {
        SecurityContextHolder.getContext().setAuthentication(authResult);
        chain.doFilter(request, response);
    }
}

Пример:

С Уважением,
Никита