You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@shenyu.apache.org by GitBox <gi...@apache.org> on 2022/12/06 08:49:58 UTC

[GitHub] [shenyu] li-keguo commented on a diff in pull request #4234: [type:refactor]Decoupled and enhanced SignUtil

li-keguo commented on code in PR #4234:
URL: https://github.com/apache/shenyu/pull/4234#discussion_r1040665920


##########
shenyu-plugin/shenyu-plugin-sign/src/main/java/org/apache/shenyu/plugin/sign/api/DefaultSignProvider.java:
##########
@@ -29,13 +32,28 @@ public class DefaultSignProvider implements SignProvider {
     /**
      * acquired sign.
      *
-     * @param signKey sign key
-     * @param jsonParams json params
-     * @param queryParams  url query params
+     * @param signKey     sign key
+     * @param jsonParams  json params
+     * @param queryParams url query params
      * @return sign
      */
     @Override
     public String generateSign(final String signKey, final Map<String, String> jsonParams, final Map<String, String> queryParams) {
-        return SignUtils.generateSign(signKey, jsonParams, queryParams);
+
+        final String jsonSign = Optional.ofNullable(jsonParams).map(e -> e.keySet().stream()
+                .sorted(Comparator.naturalOrder())
+                .map(key -> String.join("", key, jsonParams.get(key)))
+                .collect(Collectors.joining()).trim())
+                .orElse("");
+
+        final String querySign = Optional.ofNullable(queryParams).map(e -> e.keySet().stream()
+                .sorted(Comparator.naturalOrder())
+                .map(key -> String.join("", key, queryParams.get(key)))
+                .collect(Collectors.joining()).trim())
+                .orElse("");
+
+        final String data = String.join("", jsonSign, querySign);
+
+        return SignUtils.sign(SignUtils.SIGN_MD5, signKey, data).toUpperCase();

Review Comment:
   maybe you
   
   ```java
   interface SignProvider {
   // ...
       default HmacAlgorithms signMethod(){
           return SignUtils.SIGN_MD5;
       }
   
   // ...
   }
   ```
   
   end .
   add doc



-- 
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: notifications-unsubscribe@shenyu.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org