reta commented on code in PR #3809:
URL: https://github.com/apache/cxf/pull/3809#discussion_r4755465693
##########
rt/rs/security/oauth-parent/oauth2/src/main/java/org/apache/cxf/rs/security/oauth2/utils/crypto/ModelEncryptionSupport.java:
##########
@@ -594,16 +623,82 @@ private static void tokenizeUserSubject(StringBuilder
state, UserSubject subject
state.append(tokenizeString(subject.getId()));
state.append('.');
// 3
- state.append(subject.getRoles().toString());
+ state.append(tokenizeList(subject.getRoles()));
state.append('.');
// 4
- state.append(subject.getProperties().toString());
+ state.append(tokenizeMap(subject.getProperties()));
} else {
state.append(' ');
}
}
+ /**
+ * Writes a single value. A null value is written as a single space, and
the separator
+ * characters {@code % | . , = [ ] { }} and the space character are
percent-encoded so
+ * that a value can never be confused with the structure around it.
+ */
public static String tokenizeString(String str) {
- return str != null ? str : " ";
+ if (str == null) {
+ return " ";
+ }
+ StringBuilder sb = new StringBuilder(str.length());
+ for (int i = 0; i < str.length(); i++) {
+ char c = str.charAt(i);
+ if (ESCAPED_CHARS.indexOf(c) >= 0) {
+ sb.append('%').append(HEX_DIGITS.charAt(c >>
4)).append(HEX_DIGITS.charAt(c & 0xF));
Review Comment:
I think we could use `HexFormat` (JDK-17) and drop `HEX_DIGITS`:
```suggestion
sb.append('%').append(HexFormat.of().toHexDigits((byte)c));
```
--
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]