@Override
    public void doFilter(
            final ServletRequest servletRequest,
            final ServletResponse servletResponse,
            final FilterChain filterChain
    ) throws IOException, ServletException {
        val httpRequest = (HttpServletRequest) servletRequest;
        val httpResponse = (HttpServletResponse) servletResponse;

        String requestURI = httpRequest.getRequestURI();
        if (!requestURI.matches("^/(swagger|webjars|v2|api/v1/migrate|api/v1/consistence/status|api/v1/static|api/v1/config).*$")) {
            val headersMap =
                    list(httpRequest.getHeaderNames()).stream()
                            .collect(Collectors.<String, String, List<String>>toMap(
                                    identity(),
                                    header -> list(httpRequest.getHeaders(header))
                            ));

            var apiKey = headersMap.getOrDefault(X_FRS_API_KEY_HEADER, emptyList());

            if (!apiKey.isEmpty()) {
                val key = apiKey.get(0);
                try {
                    if (key.length() < 36) {
                        throw new IllegalArgumentException("UUID length is incorrect");
                    }

                    UUID.fromString(key);
                } catch (Exception e) {
                    val objectResponseEntity = handler.handleDefinedExceptions(new BadFormatModelKeyException());
                    buildException(httpResponse, objectResponseEntity);

                    return;
                }
                val modelType = getModelTypeByUrl(requestURI);
                val validationResult = modelService.validateModelKey(key, modelType);
                if (validationResult.getResult() != OK) {
                    val capitalize = ModelType.VERIFY.equals(modelType) ? VERIFICATION : StringUtils.capitalize(modelType.name().toLowerCase());
                    val objectResponseEntity = handler.handleDefinedExceptions(new ModelNotFoundException(key, capitalize));
                    buildException(httpResponse, objectResponseEntity);

                    return;
                }
                if (requestURI.matches("^/(api/v1/recognition/recognize|api/v1/detection/detect|api/v1/verification/verify).*$")) {
                    modelStatisticCacheProvider.incrementRequestCount(validationResult.getModelId());
                }
            } else {
                val objectResponseEntity = handler.handleMissingRequestHeader(X_FRS_API_KEY_HEADER);
                buildException(httpResponse, objectResponseEntity);

                return;
            }
        }

        filterChain.doFilter(servletRequest, servletResponse);
    }
Filter created to validate if this application has access to requested model
java/api/src/main/java/com/exadel/frs/core/trainservice/filter/SecurityValidationFilter.java