code: public Optional<AuthenticationResultBuilder> buildSurrogateAuthenticationResult(final AuthenticationResultBuilder authenticationResultBuilder,
                                                                                      final Credential credential,
                                                                                      final String surrogateTargetId,
                                                                                      final RegisteredService registeredService) {
          val currentAuthn = authenticationResultBuilder.getInitialAuthentication();
          if (currentAuthn.isPresent()) {
              val authentication = currentAuthn.get();
              val surrogatePrincipal = buildSurrogatePrincipal(surrogateTargetId, authentication.getPrincipal(), credential, registeredService);
              val auth = DefaultAuthenticationBuilder.newInstance(authentication).setPrincipal(surrogatePrincipal).build();
              return Optional.of(authenticationResultBuilder.collect(auth));
          }
          return Optional.empty();
      }
docs: Build surrogate authentication result optional.
  
  @param authenticationResultBuilder the authentication result builder
  @param credential                  the credential
  @param surrogateTargetId           the surrogate target id
  @param registeredService           the registered service
  @return the optional