@Override
    public ModelAndView build(final RegisteredService registeredService, final String redirectUrl,
                              final Map<String, String> parameters) throws Exception {

        val urlBuilder = new URIBuilder(redirectUrl);
        val currentParams = urlBuilder.getQueryParams();
        urlBuilder.removeQuery();
        currentParams.removeIf(p -> parameters.containsKey(p.getName()));
        val fragment = parameters.entrySet()
            .stream()
            .map(entry -> entry.getKey() + '=' + entry.getValue())
            .collect(Collectors.joining("&"));

        val queryParams = new LinkedMultiValueMap<String, String>(currentParams.size());
        currentParams.forEach(param -> queryParams.put(param.getName(), List.of(param.getValue())));
        
        val resultUrl = UriComponentsBuilder.fromUriString(redirectUrl)
            .fragment(fragment)
            .queryParams(queryParams)
            .build()
            .toUriString();
        
        LOGGER.debug("Redirecting to [{}]", resultUrl);
        val mv = new RedirectView(resultUrl);
        return new ModelAndView(mv);
    }
This is {@link OAuth20ResponseModeFragmentBuilder}.

@author Misagh Moayyed
@since 7.0.0
support/cas-server-support-oauth-core-api/src/main/java/org/apereo/cas/support/oauth/web/response/callback/mode/OAuth20ResponseModeFragmentBuilder.java