From 48f23ea7e41c002f941d8a47da17767253c04c73 Mon Sep 17 00:00:00 2001 From: anhefti Date: Tue, 11 Jan 2022 16:37:04 +0100 Subject: [PATCH] SEBSERV-200 fixed wrong JWT token generation with moderator flag --- .../proctoring/JitsiProctoringService.java | 39 +++++++++++-------- .../ExamJITSIProctoringServiceTest.java | 6 +-- 2 files changed, 26 insertions(+), 19 deletions(-) diff --git a/src/main/java/ch/ethz/seb/sebserver/webservice/servicelayer/session/impl/proctoring/JitsiProctoringService.java b/src/main/java/ch/ethz/seb/sebserver/webservice/servicelayer/session/impl/proctoring/JitsiProctoringService.java index df4b3fc8..aa469d6a 100644 --- a/src/main/java/ch/ethz/seb/sebserver/webservice/servicelayer/session/impl/proctoring/JitsiProctoringService.java +++ b/src/main/java/ch/ethz/seb/sebserver/webservice/servicelayer/session/impl/proctoring/JitsiProctoringService.java @@ -431,12 +431,17 @@ public class JitsiProctoringService implements ExamProctoringService { clientKey, appKey, host, - new Context(new User(clientName, clientName, String.valueOf(moderator))), + new Context(new User(clientName, clientName)), roomName, - expTime); + expTime, + moderator); final String content = this.jsonMapper.writeValueAsString(jwtContext); + if (log.isDebugEnabled()) { + log.debug("Jitsi Meet JWT payload: {}", content); + } + return content; } catch (final Exception e) { throw new RuntimeException("Unexpected error while trying to create JWT payload: ", e); @@ -464,16 +469,25 @@ public class JitsiProctoringService implements ExamProctoringService { @JsonIgnoreProperties(ignoreUnknown = true) @JsonInclude(Include.NON_NULL) private class JWTContext { + + @JsonProperty final Context context; + @JsonProperty final Boolean moderator; @JsonProperty final String aud; @JsonProperty final String iss; @JsonProperty final String sub; - @JsonProperty final Context context; + @JsonProperty final String room; @JsonProperty final Long exp; @JsonProperty final Long nbf; - @JsonProperty final String room; - @JsonProperty final Boolean moderator; - public JWTContext(final String aud, final String iss, final String sub, final Context context, final String room, final Long exp) { + public JWTContext( + final String aud, + final String iss, + final String sub, + final Context context, + final String room, + final Long exp, + final Boolean moderator) { + this.aud = aud; this.iss = iss; this.sub = sub; @@ -481,7 +495,7 @@ public class JitsiProctoringService implements ExamProctoringService { this.room = room; this.exp = exp; this.nbf = null; - this.moderator = BooleanUtils.toBooleanObject(context.user.moderator); + this.moderator = moderator; } } @@ -505,31 +519,24 @@ public class JitsiProctoringService implements ExamProctoringService { @JsonIgnoreProperties(ignoreUnknown = true) @JsonInclude(Include.NON_NULL) private class User { - @JsonProperty final String id; @JsonProperty final String name; @JsonProperty final String avatar; @JsonProperty final String email; - @JsonProperty final String moderator; @SuppressWarnings("unused") - public User(final String id, final String name, final String avatar, final String email, final String moderator) { - this.id = id; + public User(final String name, final String avatar, final String email) { this.name = name; this.avatar = avatar; this.email = email; - this.moderator = moderator; } public User( final String id, - final String name, - final String moderator) { + final String name) { - this.id = id; this.name = name; this.avatar = null; this.email = null; - this.moderator = moderator; } } diff --git a/src/test/java/ch/ethz/seb/sebserver/webservice/servicelayer/session/impl/proctoring/ExamJITSIProctoringServiceTest.java b/src/test/java/ch/ethz/seb/sebserver/webservice/servicelayer/session/impl/proctoring/ExamJITSIProctoringServiceTest.java index 2ddbc7d5..37798fef 100644 --- a/src/test/java/ch/ethz/seb/sebserver/webservice/servicelayer/session/impl/proctoring/ExamJITSIProctoringServiceTest.java +++ b/src/test/java/ch/ethz/seb/sebserver/webservice/servicelayer/session/impl/proctoring/ExamJITSIProctoringServiceTest.java @@ -41,7 +41,7 @@ public class ExamJITSIProctoringServiceTest { false); assertEquals( - "{\"aud\":\"test-client\",\"iss\":\"test-app\",\"sub\":\"https://test.ch\",\"context\":{\"user\":{\"id\":\"Test Name\",\"name\":\"Test Name\",\"moderator\":\"false\"}},\"exp\":1609459200,\"room\":\"SomeRoom\",\"moderator\":false}", + "{\"context\":{\"user\":{\"name\":\"Test Name\"}},\"moderator\":false,\"aud\":\"test-client\",\"iss\":\"test-app\",\"sub\":\"https://test.ch\",\"room\":\"SomeRoom\",\"exp\":1609459200}", accessToken); accessToken = examJITSIProctoringService.createPayload( @@ -54,7 +54,7 @@ public class ExamJITSIProctoringServiceTest { true); assertEquals( - "{\"aud\":\"test-client\",\"iss\":\"test-app\",\"sub\":\"https://test.ch\",\"context\":{\"user\":{\"id\":\"Test Name\",\"name\":\"Test Name\",\"moderator\":\"true\"}},\"exp\":1609459200,\"room\":\"SomeRoom\",\"moderator\":true}", + "{\"context\":{\"user\":{\"name\":\"Test Name\"}},\"moderator\":true,\"aud\":\"test-client\",\"iss\":\"test-app\",\"sub\":\"https://test.ch\",\"room\":\"SomeRoom\",\"exp\":1609459200}", accessToken); } @@ -83,7 +83,7 @@ public class ExamJITSIProctoringServiceTest { data.serverURL); assertEquals( - "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJhdWQiOiJ0ZXN0LWNsaWVudCIsImlzcyI6InRlc3QtYXBwIiwic3ViIjoic2ViLWppdHNpLmV4YW1wbGUuY2giLCJjb250ZXh0Ijp7InVzZXIiOnsiaWQiOiJUZXN0IE5hbWUiLCJuYW1lIjoiVGVzdCBOYW1lIiwibW9kZXJhdG9yIjoidHJ1ZSJ9fSwiZXhwIjoxNjA5NDU5MjAwLCJyb29tIjoiU29tZVJvb20iLCJtb2RlcmF0b3IiOnRydWV9.cqLcM-XjKkTfDjujJAwE2CqiJMQggRVlz2mL4fT5PuE", + "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJjb250ZXh0Ijp7InVzZXIiOnsibmFtZSI6IlRlc3QgTmFtZSJ9fSwibW9kZXJhdG9yIjp0cnVlLCJhdWQiOiJ0ZXN0LWNsaWVudCIsImlzcyI6InRlc3QtYXBwIiwic3ViIjoic2ViLWppdHNpLmV4YW1wbGUuY2giLCJyb29tIjoiU29tZVJvb20iLCJleHAiOjE2MDk0NTkyMDB9.47qoBCXG34ITeMmrwxlTmDcc6JLSVVF1HAOlcSkCvqw", data.accessToken); }