References
2018-10-03 AAI Meeting Notes - open for agenda items
- AAI-628Getting issue details... STATUS
Jackson Replacement
Security subcommittee has recommended teams move away from jackson, and will be presenting alternatives and asking for an assessment from each project. Our team will need to do an analysis - this would not be trivial, especially given how many of our repos are impacted. As of now, this would be a very high LOE for the team, we need to understand what the recommendation from the SECCOM is before we can provide better details on what the LOE would be.
Code Analysis
Search on AAI source code shows:
- approx 661 hits in 227 files for "fasterxml", which includes pom.xml and Java imports
- approx 978 hits in 215 files for "gson", which includes pom.xml and Java imports and initialising Java object
Code Examples
- aai\aai-common\aai-auth\src\main\java\org\onap\aaiauth\auth\AuthCore.java
- aai\aai-common\aai-core\src\main\java\org\onap\aai\auth\AAIAuthCore.java
Side-by-side comparison
FasterXML Jackson version | Google gson version | Comments |
---|---|---|
mapper = new ObjectMapper(); | JsonParser parser = new JsonParser(); | |
JsonNode rootNode = mapper.readTree(new File(authFilename)); JsonNode rolesNode = rootNode.path(AuthConstants.ROLES_NODE_PATH); | JsonObject authObject = parser.parse(authFile).getAsJsonObject(); JsonArray roles = authObject.getAsJsonArray("roles"); | |
String function = functionNode.path(AuthConstants.FUNCTION_NAME_PATH).asText(); | String roleName = roleObject.get("name").getAsString(); | Code structure differs at this point (function name vs role name) but the general intent of the code is equivalent (get the element name as a string). |
public synchronized void loadUsers(String authFilename) throws Exception (no exception handling in this method) | } catch (JsonProcessingException e) { ErrorLogHelper.logError("AAI_4001", globalAuthFileName + ". Not valid JSON: " + e); | For some reason, this version still catches com.fasterxml.jackson.core.JsonProcessingException even though it uses Google gson for parsing. Not a good idea to defer exception handling to the caller since the caller has no idea why/how/when/where the parsing failed and might be left with an invalid data structure as well. |
boolean hasMethods = handleMethodNode(methodsNode, role, function); | usrs.forEach((key, value) -> { ... }); | Method call vs Java lambda call is not really relevant to the Jackson replacement, but consistency of style could be an overall goal if the code is being re-factored anyway. |
Suggestions
Article https://blog.takipi.com/the-ultimate-json-library-json-simple-vs-gson-vs-jackson-vs-json/
links to benchmark in comments: https://github.com/fabienrenaud/java-json-benchmark
which links to about 20 libraries as options to be explored, including:
- https://github.com/alibaba/fastjson
- https://github.com/google/gson
- https://github.com/square/moshi
- http://genson.io/
Quick CVE comparison:
- https://cve.mitre.org/cgi-bin/cvekey.cgi?keyword=fastjson+or+gson+or+moshi+or+genson
- https://cve.mitre.org/cgi-bin/cvekey.cgi?keyword=fasterxml+or+jackson