SEBSERV-200 fixed wrong JWT token generation with moderator flag

This commit is contained in:
anhefti 2022-01-11 16:37:04 +01:00
parent d7c71ea930
commit 48f23ea7e4
2 changed files with 26 additions and 19 deletions

View file

@ -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;
}
}

View file

@ -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);
}