private Authentication authenticateRequest(final HttpServletRequest request) {
        val converter = new BasicAuthenticationConverter();
        val token = converter.convert(request);
        return FunctionUtils.doIfNotNull(token, () -> {
            LOGGER.debug("Received basic authentication ECP request from credentials [{}]", token.getPrincipal());
            val upc = new UsernamePasswordCredential(token.getPrincipal().toString(), token.getCredentials().toString());
            val serviceRequest = this.serviceFactory.createService(request);
            val result = authenticationSystemSupport.finalizeAuthenticationTransaction(serviceRequest, upc);
            if (result == null) {
                throw new BadRestRequestException("Unable to establish authentication using provided credentials for " + upc.getUsername());
            }
            return result.getAuthentication();
        });
    }
Create new service.

@param service  the service
@param request  the request
@param response the response
@return {@link ResponseEntity} representing RESTful response
@throws Throwable the throwable
support/cas-server-support-rest-services/src/main/java/org/apereo/cas/support/rest/RegisteredServiceResource.java