kevdoran commented on a change in pull request #302: URL: https://github.com/apache/nifi-registry/pull/302#discussion_r490535141
########## File path: nifi-registry-core/nifi-registry-security-utils/src/main/java/org/apache/nifi/registry/security/util/ProxiedEntitiesUtils.java ########## @@ -39,6 +41,55 @@ private static final String ANONYMOUS_CHAIN = "<>"; + /** + * Formats a list of DN/usernames to be set as a HTTP header using well known conventions. + * + * @param proxiedEntities the raw identities (usernames and DNs) to be formatted as a chain + * @return the value to use in the X-ProxiedEntitiesChain header + */ + public static String getProxiedEntitiesChain(final String[] proxiedEntities) { + if (proxiedEntities == null) { + return null; + } + + final List<String> proxiedEntityChain = Arrays.stream(proxiedEntities) + .map(ProxiedEntitiesUtils::formatProxyDn) + .collect(Collectors.toList()); + return StringUtils.join(proxiedEntityChain, ""); + } + + /** + * Tokenizes the specified proxy chain. + * + * @param rawProxyChain raw chain + * @return tokenized proxy chain + */ + public static List<String> tokenizeProxiedEntitiesChain(final String rawProxyChain) { + final List<String> proxyChain = new ArrayList<>(); + if (!StringUtils.isEmpty(rawProxyChain)) { + // Split the String on the >< token + rawProxyChain.split("><"); + List<String> elements = Arrays.asList(StringUtils.splitByWholeSeparatorPreserveAllTokens(rawProxyChain, "><")); + + // Remove the leading < from the first element + elements.set(0, elements.get(0).replaceFirst(LT, "")); Review comment: I left this logic unchanged (just moved it from down below to keep all the `public` methods at the top of the file and to keep it close to the reverse method which is `getProxiedEntitiesChain()`, but now that you point it out, I will look at possibly simplifying this when I make the other suggestions you had. Thanks! ---------------------------------------------------------------- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. For queries about this service, please contact Infrastructure at: us...@infra.apache.org