Source:
<code>public List<SecretDeliveryResponse> getBatchSecret(@Auth Client client, @Valid BatchSecretRequest request) { <START> List<SanitizedSecret> sanitizedSecrets = aclDAO.getBatchSanitizedSecretsFor(client, request.secrets); <END> List<Secret> secrets = secretController.getSecretsByName(request.secrets); boolean clientExists = clientDAO.getClient(client.getName()).isPresent(); Iterator reqsecretsiter = request.secrets.iterator(); while (reqsecretsiter.hasNext()) { String secretname = (String) reqsecretsiter.next(); SanitizedSecret sanitizedsecret = null; for (SanitizedSecret s : sanitizedSecrets) { if (s.name().equals(secretname)) { sanitizedsecret = s; break; } } Secret secret = null; for (Secret s : secrets) { if (s.getName().equals(secretname)) { secret = s; break; } } boolean secretExists = secret != null; boolean sanitzedsecretExists = sanitizedsecret != null; if (!sanitzedsecretExists) { if (clientExists && secretExists) { throw new ForbiddenException(format("Access denied: %s at '%s' by '%s'", client.getName(), "/batchsecret " + secretname, client)); } else { if (clientExists) { logger.info("Client requested unknown secret {}", client.getName(), secretname); } throw new NotFoundException(); } } } logger.info("Client granted access to {}.", client.getName(), sanitizedSecrets); try { return secrets.stream() .map(SecretDeliveryResponse::fromSecret) .collect(toList()); } catch (IllegalArgumentException e) { logger.error(format("Failed creating batch response for secrets %s", secrets), e); throw new InternalServerErrorException(); } }</code><technical_language>rename (and booleans below) clientAccessibleSecrets existingSecrets significance of a secret missing other list clearer</technical_language>

Target:
public List<SecretDeliveryResponse> getBatchSecret(@Auth Client client, @Valid BatchSecretRequest request) { List<SanitizedSecret> clientAccessibleSecrets = aclDAO.getBatchSanitizedSecretsFor(client, request.secrets()); List<Secret> existingSecrets = secretController.getSecretsByName(request.secrets()); boolean clientExists = clientDAO.getClientByName(client.getName()).isPresent(); List<String> forbiddenSecrets = new ArrayList<>(); for (String secretname : request.secrets()) { boolean secretExists = existingSecrets.stream().anyMatch(s -> s.getName().equals(secretname)); boolean secretAccessible = clientAccessibleSecrets.stream().anyMatch(s -> s.name().equals(secretname)); if (!(clientExists && secretExists)) { logger.warn("Client or secret does not exist (client exists={}, secret exists={})", client.getName(), secretname, clientExists, secretExists); throw new NotFoundException(); } if (!secretAccessible) { forbiddenSecrets.add(secretname); } } if (!forbiddenSecrets.isEmpty()) { throw new ForbiddenException(format("Access denied: %s to secret(s) '%s'", client.getName(), forbiddenSecrets)); } logger.info("Client granted access to {}.", client.getName(), clientAccessibleSecrets.stream().map(s -> s.name()).collect(toList())); try { return existingSecrets.stream() .map(SecretDeliveryResponse::fromSecret) .collect(toList()); } catch (IllegalArgumentException e) { logger.error(format("Failed creating batch response for secrets %s", existingSecrets.stream().map(s -> s.getName()).collect(toList())), e); throw new InternalServerErrorException(); } }