@Override
    protected Optional<RegisteredService> prepareFilterBeforeExecution(final HttpServletResponse httpServletResponse,
                                                                       final HttpServletRequest httpServletRequest) throws Throwable {
        val basePath = webEndpointProperties.getBasePath();
        if (httpServletRequest.getRequestURI().contains(basePath)) {
            return Optional.empty();
        }
        
        val service = argumentExtractor.getObject().extractService(httpServletRequest);
        if (service != null) {
            LOGGER.trace("Attempting to resolve service for [{}]", service);
            val resolved = authenticationRequestServiceSelectionStrategies.getObject().resolveService(service);
            val servicesManager = servicesManagerProvider.getObject();
            val registeredService = NumberUtils.isCreatable(resolved.getId())
                ? servicesManager.findServiceBy(Long.parseLong(resolved.getId()))
                : servicesManager.findServiceBy(resolved);
            val audit = AuditableContext
                .builder()
                .registeredService(registeredService)
                .service(service)
                .build();
            val accessResult = registeredServiceAccessStrategyEnforcer.getObject().execute(audit);
            if (accessResult.isExecutionFailure()) {
                LOGGER.warn("Service [{}] is not authorized", resolved);
                httpServletResponse.setStatus(HttpStatus.FORBIDDEN.value());
                httpServletRequest.setAttribute(RequestDispatcher.ERROR_EXCEPTION, accessResult.getException().orElse(null));
                return Optional.empty();
            }
            return Optional.of(registeredService);
        }
        return Optional.empty();
    }
This is {@link RegisteredServiceResponseHeadersEnforcementFilter}. A filter extension that looks at the properties of a
registered service to determine if headers should be injected into the response.

@author Misagh Moayyed
@since 5.3.0
core/cas-server-core-web-api/src/main/java/org/apereo/cas/services/web/support/RegisteredServiceResponseHeadersEnforcementFilter.java