This is an automated email from the ASF dual-hosted git repository.
solomax pushed a commit to branch 4.0.x
in repository https://gitbox.apache.org/repos/asf/openmeetings.git
The following commit(s) were added to refs/heads/4.0.x by this push:
new 0fb23ad [OPENMEETINGS-2188] all levels of JSON are being checked
0fb23ad is described below
commit 0fb23ad31c755df689239d6bb9e3fdeec9cc33f0
Author: Maxim Solodovnik <[email protected]>
AuthorDate: Mon Mar 23 14:32:40 2020 +0700
[OPENMEETINGS-2188] all levels of JSON are being checked
---
.../apache/openmeetings/db/dto/user/OAuthUser.java | 18 ++++++---
.../openmeetings/db/dto/user/TestOAuthUser.java | 47 ++++++++++++++++++++++
2 files changed, 59 insertions(+), 6 deletions(-)
diff --git
a/openmeetings-db/src/main/java/org/apache/openmeetings/db/dto/user/OAuthUser.java
b/openmeetings-db/src/main/java/org/apache/openmeetings/db/dto/user/OAuthUser.java
index 9ce3355..7251bcf 100644
---
a/openmeetings-db/src/main/java/org/apache/openmeetings/db/dto/user/OAuthUser.java
+++
b/openmeetings-db/src/main/java/org/apache/openmeetings/db/dto/user/OAuthUser.java
@@ -97,7 +97,11 @@ public class OAuthUser implements Serializable {
}
private static JSONObject getJSON(String str, String prop) {
- JSONObject json = new JSONObject(str);
+ JSONObject res = getJSON(new JSONObject(str), prop);
+ return res == null ? new JSONObject() : res;
+ }
+
+ private static JSONObject getJSON(JSONObject json, String prop) {
if (json.has(prop)) {
return json;
}
@@ -109,17 +113,19 @@ public class OAuthUser implements Serializable {
//Assuming here array consist of objects
for (int i = 0; i < ja.length(); ++i) {
JSONObject jao = ja.getJSONObject(i);
- if (jao.has(prop)) {
- return jao;
+ JSONObject res = getJSON(jao, prop);
+ if (res != null) {
+ return res;
}
}
} else if (o instanceof JSONObject) {
JSONObject jo = (JSONObject)o;
- if (jo.has(prop)) {
- return jo;
+ JSONObject res = getJSON(jo, prop);
+ if (res != null) {
+ return res;
}
}
}
- return new JSONObject();
+ return null;
}
}
diff --git
a/openmeetings-db/src/test/java/org/apache/openmeetings/db/dto/user/TestOAuthUser.java
b/openmeetings-db/src/test/java/org/apache/openmeetings/db/dto/user/TestOAuthUser.java
index acc5ca9..c4e875c 100644
---
a/openmeetings-db/src/test/java/org/apache/openmeetings/db/dto/user/TestOAuthUser.java
+++
b/openmeetings-db/src/test/java/org/apache/openmeetings/db/dto/user/TestOAuthUser.java
@@ -93,6 +93,53 @@ public class TestOAuthUser {
}
@Test
+ public void thirdLevel() {
+ OAuthServer server = new OAuthServer()
+ .addMapping(PARAM_LOGIN, "id")
+ .addMapping(PARAM_EMAIL, "email")
+ .addMapping(PARAM_FNAME, "display-name");
+ OAuthUser user = new OAuthUser("{\n" +
+ " \"ocs\": {\n" +
+ " \"meta\": {\n" +
+ " \"status\": \"ok\",\n" +
+ " \"statuscode\": 200,\n" +
+ " \"message\": \"OK\"\n" +
+ " },\n" +
+ " \"data\": {\n" +
+ " \"storageLocation\": \"xxxxx\",\n"
+
+ " \"id\": \"xxxxx\",\n" +
+ " \"lastLogin\": 1584799957000,\n" +
+ " \"backend\": \"Database\",\n" +
+ " \"subadmin\": [],\n" +
+ " \"quota\": {\n" +
+ " \"free\": 183035547648,\n" +
+ " \"used\": 10244,\n" +
+ " \"total\": 183035557892,\n" +
+ " \"relative\": 0,\n" +
+ " \"quota\": -3\n" +
+ " },\n" +
+ " \"email\": \"[email protected]\",\n" +
+ " \"phone\": \"\",\n" +
+ " \"address\": \"\",\n" +
+ " \"website\": \"\",\n" +
+ " \"twitter\": \"\",\n" +
+ " \"groups\": [\n" +
+ " \"xxxxxx\"\n" +
+ " ],\n" +
+ " \"language\": \"en\",\n" +
+ " \"locale\": \"\",\n" +
+ " \"backendCapabilities\": {\n" +
+ " \"setDisplayName\": true,\n" +
+ " \"setPassword\": true\n" +
+ " },\n" +
+ " \"display-name\": \"xxxxx\"\n" +
+ " }\n" +
+ " }\n" +
+ "}", server);
+ assertEquals("xxxxx", user.getLogin(), "Login should be
correct");
+ }
+
+ @Test
public void map() {
Map<String, String> umap = new HashMap<>();
umap.put("login", "abc");