class TokenAuthenticationFilter extends AbstractAuthFilter {

    @Override
    public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain chain) throws IOException, ServletException {
        HttpServletRequest request = (HttpServletRequest) servletRequest;
        HttpServletResponse response = (HttpServletResponse) servletResponse;

        String bearerToken = resolveBearerToken(request);

        if (StringUtils.isBlank(bearerToken)) {
            chain.doFilter(request, response);
            return;
        }

        if (authenticationIsRequired()) {
            try {
                authInterceptor.setAccessToken(bearerToken);
                ResponseEntity<BearerTokenTO> validateResponse = ledgersUserMgmt.validate(bearerToken);
                BearerTokenTO token = Optional.ofNullable(validateResponse.getBody())
                                          .orElseThrow(() -> new RestException("Couldn't get bearer token"));

                fillSecurityContext(token);
            } catch (FeignException | RestException e) {
                handleAuthenticationFailure(response, e);
                return;
            }
        }
        chain.doFilter(request, response);
    }

}