pzampino commented on a change in pull request #542: URL: https://github.com/apache/knox/pull/542#discussion_r822835650
########## File path: gateway-service-knoxtoken/src/main/java/org/apache/knox/gateway/service/knoxtoken/TokenResource.java ########## @@ -405,11 +408,43 @@ public Response doPost() { @GET @Path(GET_USER_TOKENS) @Produces({APPLICATION_JSON, APPLICATION_XML}) - public Response getUserTokens(@QueryParam("userName") String userName) { + public Response getUserTokens(@Context UriInfo uriInfo) { if (tokenStateService == null) { return Response.status(Response.Status.SERVICE_UNAVAILABLE).entity("{\n \"error\": \"Token management is not configured\"\n}\n").build(); } else { - final Collection<KnoxToken> tokens = tokenStateService.getTokens(userName); + if (uriInfo == null) { + throw new IllegalArgumentException("URI info cannot be NULL."); + } + final Map<String, String> metadataMap = new HashMap<>(); + uriInfo.getQueryParameters().entrySet().forEach(entry -> { + if (entry.getKey().startsWith(METADATA_QUERY_PARAM_PREFIX)) { + String metadataName = entry.getKey().substring(METADATA_QUERY_PARAM_PREFIX.length()); + metadataMap.put(metadataName, entry.getValue().get(0)); + } + }); + + final String userName = uriInfo.getQueryParameters().getFirst("userName"); + final Collection<KnoxToken> userTokens = tokenStateService.getTokens(userName); + final Collection<KnoxToken> tokens = new TreeSet<>(); + if (metadataMap.isEmpty()) { + tokens.addAll(userTokens); + } else { + userTokens.forEach(knoxToken -> { + for (Map.Entry<String, String> entry : metadataMap.entrySet()) { + if (StringUtils.isBlank(entry.getValue()) || "*".equals(entry.getValue())) { + // we should only filter tokens by metadata name + if (knoxToken.getMetadata().getMetadataMap().containsKey(entry.getKey())) { Review comment: Not necessarily related to this change, but it seems to me that TokenMetadata could have a generic `get(String key)` method, rather than requiring making a copy of the `metadataMap` every time a value is needed to be looked up (`knoxToken.getMetadata().getMetadataMap()`). `public String get(final String key) { return metadataMap.get(key); }` -- 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. To unsubscribe, e-mail: dev-unsubscr...@knox.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org