tydhot commented on a change in pull request #2918:
URL: https://github.com/apache/incubator-shenyu/pull/2918#discussion_r811534314
##########
File path:
shenyu-plugin/shenyu-plugin-jwt/src/main/java/org/apache/shenyu/plugin/jwt/JwtPlugin.java
##########
@@ -162,10 +157,41 @@ private ServerWebExchange converter(final
ServerWebExchange exchange,
* @param converters converters
*/
private void addHeader(final HttpHeaders headers,
- final Map<String, String> body,
+ final Map<String, Object> body,
final List<JwtRuleHandle.Convert> converters) {
for (JwtRuleHandle.Convert converter : converters) {
- headers.add(converter.getHeaderVal(),
body.get(converter.getJwtVal()));
+ if (converter.getJwtVal().contains(".")) {
+ headers.add(converter.getHeaderVal(), parse(body,
converter.getJwtVal().split("\\."), new AtomicInteger(0)));
+ } else {
+ headers.add(converter.getHeaderVal(),
String.valueOf(body.get(converter.getJwtVal())));
+ }
}
}
+
+ /**
+ * Parsing multi-level tokens.
+ *
+ * @param body token
+ * @param split jwt of key
+ * @param deep level default 0
+ * @return token of val
+ */
+ private String parse(final Map<String, Object> body,
+ final String[] split,
+ final AtomicInteger deep) {
+ for (Map.Entry<String, Object> entry : body.entrySet()) {
+ if (entry.getKey().equals(split[deep.get()])) {
+ if (entry.getValue() instanceof Map && split.length > 1) {
+ deep.incrementAndGet();
+ return parse((Map<String, Object>) entry.getValue(),
split, deep);
+ } else {
+ return String.valueOf(entry.getValue());
+ }
+ } else {
+ return String.valueOf(entry.getValue());
+ }
+ }
+ return String.valueOf(body.get(split[deep.get()]));
Review comment:
I think the logic here still has room for optimization
--
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: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]