Skip to content

Commit 40d3b42

Browse files
Abner-Evanemoustaphahennawi
authored andcommitted
chore (Auth) : upadate refacto slo
1 parent 24e6756 commit 40d3b42

File tree

3 files changed

+33
-17
lines changed

3 files changed

+33
-17
lines changed

auth/src/main/java/org/entcore/auth/oauth/OAuthDataHandler.java

Lines changed: 32 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -830,7 +830,7 @@ public void getUserIdByAssertionJwt(String clientId, String assertion, Handler<T
830830
}
831831

832832
@Override
833-
public void getAuthorizationsBySessionId(String sessionId, Handler<List<JsonObject>> handler) {
833+
public void getAuthorizationsBySessionId(String sessionId, Handler<List<AuthInfo>> handler) {
834834
if (sessionId != null) {
835835
JsonObject queryData = new JsonObject()
836836
.put("sessionId", sessionId)
@@ -842,7 +842,7 @@ public void getAuthorizationsBySessionId(String sessionId, Handler<List<JsonObje
842842
handler.handle(Collections.emptyList());
843843
return;
844844
}
845-
handler.handle(filterList(results));
845+
handler.handle(filterAuth(results));
846846
} else {
847847
handler.handle(null);
848848
}
@@ -852,20 +852,25 @@ public void getAuthorizationsBySessionId(String sessionId, Handler<List<JsonObje
852852
}
853853
}
854854

855-
private List<JsonObject> filterList(JsonArray data) {
856-
List<JsonObject> array = new ArrayList<>();
855+
private List<AuthInfo> filterAuth(JsonArray data) {
856+
List<AuthInfo> array = new ArrayList<AuthInfo>();
857857
for (int i = 0; i < data.size(); i++) {
858-
JsonObject res = data.getJsonObject(i);
859-
res.put("id", res.getString("_id"));
860-
res.remove("_id");
861-
res.remove("createdAt");
862-
array.add(res);
858+
JsonObject o = data.getJsonObject(i);
859+
o.put("id", o.getString("_id"));
860+
o.remove("_id");
861+
o.remove("sessionId");
862+
o.remove("createdAt");
863+
ObjectMapper mapper = new ObjectMapper();
864+
try {
865+
array.add(mapper.readValue(o.encode(), AuthInfo.class));
866+
} catch (IOException e) {
867+
log.error(e);
868+
}
863869
}
864870
return array;
865871
}
866-
867872
@Override
868-
public void getTokensByAuthId(String authId, Handler<List<JsonObject>> handler) {
873+
public void getTokensByAuthId(String authId, Handler<List<AccessToken>> handler) {
869874
if (authId != null) {
870875
JsonObject query = new JsonObject().put("authId", authId);
871876
mongo.find(ACCESS_TOKEN_COLLECTION, query, res -> {
@@ -881,7 +886,23 @@ public void getTokensByAuthId(String authId, Handler<List<JsonObject>> handler)
881886
}
882887
});
883888
}
889+
}
884890

891+
private List<AccessToken> filterList(JsonArray data) {
892+
List<AccessToken> array = new ArrayList<>();
893+
for (int i = 0; i < data.size(); i++) {
894+
AccessToken res = new AccessToken();
895+
JsonObject o = data.getJsonObject(i);
896+
o.put("id", o.getString("_id"));
897+
o.remove("_id");
898+
res.setAuthId(o.getString("authId"));
899+
res.setCreatedOn(MongoDb.parseIsoDate(o.getJsonObject("createdOn")));
900+
res.setExpiresIn(o.getInteger("expiresIn"));
901+
res.setIdToken(o.getString("id_token"));
902+
res.setToken(o.getString("token"));
903+
array.add(res);
904+
}
905+
return array;
885906
}
886907

887908
@Override

auth/src/main/java/org/entcore/auth/services/OpenIdDataHandler.java

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,11 @@
11
package org.entcore.auth.services;
22

3-
import java.util.List;
43

54
import io.vertx.core.eventbus.Message;
65
import io.vertx.core.json.JsonObject;
76
import jp.eisbahn.oauth2.server.async.Handler;
87

98
public interface OpenIdDataHandler {
10-
void getAuthorizationsBySessionId(String sessionId, Handler<List<JsonObject>> handler);
11-
12-
void getTokensByAuthId(String authId, Handler<List<JsonObject>> handler);
139

1410
void deleteTokensByAuthId(String authId);
1511

gradle.properties

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,5 +46,4 @@ modMongoVersion=4.0-SNAPSHOT
4646
testContainerVersion=1.17.1
4747
micrometerMetricsVersion=3.9.5
4848
micrometerPrometheusVersion=1.1.0
49-
commonsCollectionsVersion=4.1
50-
oauth2ServerVersion=1.4.1-develop-wl-SNAPSHOT
49+
commonsCollectionsVersion=4.1

0 commit comments

Comments
 (0)