Merge remote-tracking branch 'origin/dev-1.2' into development

Conflicts:
	.github/workflows/buildReporting.yml
	src/main/java/ch/ethz/seb/sebserver/webservice/servicelayer/session/impl/SEBClientConnectionServiceImpl.java
This commit is contained in:
anhefti 2021-09-23 11:05:10 +02:00
commit 2fd3850186

View file

@ -185,22 +185,7 @@ public class SEBClientConnectionServiceImpl implements SEBClientConnectionServic
final String clientId) { final String clientId) {
return Result.tryCatch(() -> { return Result.tryCatch(() -> {
if (log.isDebugEnabled()) {
log.debug(
"SEB client connection, update ClientConnection for "
+ "connectionToken {} "
+ "institutionId: {}"
+ "exam: {} "
+ "client address: {} "
+ "userSessionId: {}"
+ "clientId: {}",
connectionToken,
institutionId,
examId,
clientAddress,
userSessionId,
clientId);
}
final ClientConnection clientConnection = getClientConnection(connectionToken); final ClientConnection clientConnection = getClientConnection(connectionToken);
@ -218,6 +203,23 @@ public class SEBClientConnectionServiceImpl implements SEBClientConnectionServic
if (examId != null) { if (examId != null) {
checkExamIntegrity(examId); checkExamIntegrity(examId);
} }
if (log.isDebugEnabled()) {
log.debug(
"SEB client connection, update ClientConnection for "
+ "connectionToken {} "
+ "institutionId: {}"
+ "exam: {} "
+ "client address: {} "
+ "userSessionId: {}"
+ "clientId: {}",
connectionToken,
institutionId,
examId,
clientAddress,
userSessionId,
clientId);
}
updateUserSessionId(userSessionId, clientConnection, examId); updateUserSessionId(userSessionId, clientConnection, examId);
final ClientConnection updatedClientConnection = this.clientConnectionDAO final ClientConnection updatedClientConnection = this.clientConnectionDAO
@ -265,6 +267,34 @@ public class SEBClientConnectionServiceImpl implements SEBClientConnectionServic
return Result.tryCatch(() -> { return Result.tryCatch(() -> {
ClientConnection clientConnection = getClientConnection(connectionToken);
// connection integrity check
if (clientConnection.status == ConnectionStatus.ACTIVE) {
if (clientConnection.clientAddress != null && clientConnection.clientAddress.equals(clientAddress)) {
// It seems that this is the same SEB that tries to establish the connection once again.
// Just log this and return already established connection
if (log.isDebugEnabled()) {
log.debug(
"SEB retired to establish an already established client connection. Client adress: {} : {}",
clientConnection.clientAddress,
clientAddress);
}
return clientConnection;
} else {
// It seems that this is a request from an other device then the original
log.error("ClientConnection integrity violation: client connection mismatch: {}",
clientConnection);
throw new IllegalArgumentException(
"ClientConnection integrity violation: client connection mismatch");
}
} else if (!clientConnection.status.clientActiveStatus) {
log.error("ClientConnection integrity violation: client connection is not in expected state: {}",
clientConnection);
throw new IllegalArgumentException(
"ClientConnection integrity violation: client connection is not in expected state");
}
if (log.isDebugEnabled()) { if (log.isDebugEnabled()) {
log.debug( log.debug(
"SEB client connection, establish ClientConnection for " "SEB client connection, establish ClientConnection for "
@ -281,8 +311,7 @@ public class SEBClientConnectionServiceImpl implements SEBClientConnectionServic
userSessionId, userSessionId,
clientId); clientId);
} }
ClientConnection clientConnection = getClientConnection(connectionToken);
checkInstitutionalIntegrity(institutionId, clientConnection); checkInstitutionalIntegrity(institutionId, clientConnection);
checkExamIntegrity(examId, clientConnection); checkExamIntegrity(examId, clientConnection);
clientConnection = updateUserSessionId(userSessionId, clientConnection, examId); clientConnection = updateUserSessionId(userSessionId, clientConnection, examId);
@ -672,15 +701,17 @@ public class SEBClientConnectionServiceImpl implements SEBClientConnectionServic
ClientConnection clientConnection, ClientConnection clientConnection,
final Long examId) { final Long examId) {
if (StringUtils.isNotBlank(userSessionId)) { if (StringUtils.isNoneBlank(userSessionId)) {
if (StringUtils.isNoneBlank(clientConnection.userSessionId)) {
if (StringUtils.isNoneBlank(clientConnection.userSessionId) if (clientConnection.userSessionId.contains(userSessionId)) {
&& clientConnection.userSessionId.contains(userSessionId)) { if (log.isDebugEnabled()) {
log.debug("SEB sent LMS userSessionId but clientConnection has already a userSessionId");
if (log.isDebugEnabled()) { }
log.debug("SEB sent LMS userSessionId but clientConnection has already a userSessionId"); } else {
log.warn(
"Possible client integrity violation: clientConnection has already a userSessionId: {} : {}",
userSessionId, clientConnection.userSessionId);
} }
return clientConnection; return clientConnection;
} }