public void resolveAssertionConsumerService(AuthenticationRequest authenticationRequest) throws SamlValidationException {

        // set URL if set in authnRequest
        final String authnAcsURL = authenticationRequest.getAuthnRequest().getAssertionConsumerServiceURL();
        if (authnAcsURL != null) {
            authenticationRequest.setAssertionConsumerURL(authnAcsURL);
            return;
        }

        // search url from metadata endpoints
        final Integer authnAcsIdx = authenticationRequest.getAuthnRequest().getAssertionConsumerServiceIndex();
        List<Endpoint> endpoints = authenticationRequest.getConnectionEntity().getRoleDescriptors().get(0).getEndpoints(AssertionConsumerService.DEFAULT_ELEMENT_NAME);

        if (endpoints.isEmpty()) {
            throw new SamlValidationException("Authentication: Assertion Consumer Service not found in metadata");
        }

        if (authnAcsIdx != null && endpoints.size() <= authnAcsIdx) {
            throw new SamlValidationException("Authentication: Assertion Consumer Index is out of bounds");
        }

        // TODO: check if this statement is correct
        if (endpoints.size() == 1) {
            authenticationRequest.setAssertionConsumerURL(endpoints.get(0).getLocation());
            return;
        }

        if(authnAcsIdx == null) {
            AssertionConsumerService defaultAcs = endpoints.stream()
                    .filter(e -> e instanceof AssertionConsumerService)
                    .map(acs -> (AssertionConsumerService) acs)
                    .filter(IndexedEndpoint::isDefault)
                    .findAny()
                    .orElse(null);

            if (defaultAcs == null) {
                throw new SamlValidationException("Authentication: There is no default AssertionConsumerService");
            }

            authenticationRequest.setAssertionConsumerURL(defaultAcs.getLocation());
            return;
        }

        authenticationRequest.setAssertionConsumerURL(endpoints.get(authnAcsIdx).getLocation());
    }
@Test
    void resolveAcsUrlWithIndex1InMultiAcsMetadata() throws SamlValidationException {
        AuthnRequest authnRequest = OpenSAMLUtils.buildSAMLObject(AuthnRequest.class);
        authnRequest.setAssertionConsumerServiceIndex(1);

        AuthenticationRequest authenticationRequest = new AuthenticationRequest();
        authenticationRequest.setAuthnRequest(authnRequest);
        authenticationRequest.setConnectionEntity(MetadataParser.readMetadata(stubsMultiAcsMetadataFile, CONNECTION_ENTITY_ID));

        assertionConsumerServiceUrlService.resolveAssertionConsumerService(authenticationRequest);
        assertEquals("SSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSS", authenticationRequest.getAssertionConsumerURL());
    }