From dff11e01174f95f66699c994d49d49564d9b5f17 Mon Sep 17 00:00:00 2001 From: Tobias Lippert Date: Sun, 8 Oct 2023 15:48:32 +0200 Subject: [PATCH] rename same params and do only add reasons that should be analyzed --- .../service/exam/ExamSessionService.java | 35 +++++++++++-------- .../webapp/app/entities/exam-session.model.ts | 34 +++++++++--------- .../suspicious-sessions.service.ts | 10 +++--- 3 files changed, 43 insertions(+), 36 deletions(-) diff --git a/src/main/java/de/tum/in/www1/artemis/service/exam/ExamSessionService.java b/src/main/java/de/tum/in/www1/artemis/service/exam/ExamSessionService.java index 3527e8a78f4f..b548978b4a1f 100644 --- a/src/main/java/de/tum/in/www1/artemis/service/exam/ExamSessionService.java +++ b/src/main/java/de/tum/in/www1/artemis/service/exam/ExamSessionService.java @@ -166,17 +166,17 @@ private void analyzeSessionsOfDifferentStudentExams(long examId, SuspiciousSessi if (analysisOptions.sameIpAddressDifferentStudentExams() && analysisOptions.sameBrowserFingerprintDifferentStudentExams()) { // first step find all sessions that have matching browser fingerprint and ip address findSuspiciousSessionsForGivenCriteria(filteredSessions, examId, - examSessionRepository::findAllExamSessionsWithTheSameIpAddressAndBrowserFingerprintByExamIdAndExamSession, suspiciousExamSessions); + examSessionRepository::findAllExamSessionsWithTheSameIpAddressAndBrowserFingerprintByExamIdAndExamSession, suspiciousExamSessions, true, true); } if (analysisOptions.sameBrowserFingerprintDifferentStudentExams()) { // second step find all sessions that have only matching browser fingerprint findSuspiciousSessionsForGivenCriteria(filteredSessions, examId, examSessionRepository::findAllExamSessionsWithTheSameBrowserFingerprintByExamIdAndExamSession, - suspiciousExamSessions); + suspiciousExamSessions, false, true); } if (analysisOptions.sameIpAddressDifferentStudentExams()) { // third step find all sessions that have only matching ip address findSuspiciousSessionsForGivenCriteria(filteredSessions, examId, examSessionRepository::findAllExamSessionsWithTheSameIpAddressByExamIdAndExamSession, - suspiciousExamSessions); + suspiciousExamSessions, true, false); } } @@ -283,19 +283,21 @@ private static boolean checkIfSubnetAndAddressHaveTheSameVersion(String ipSubnet /** * Finds suspicious exam sessions according to the criteria given and adds them to the set of suspicious exam sessions * - * @param examSessions set of exam sessions to be processed - * @param examId id of the exam for which suspicious exam sessions shall be retrieved - * @param criteriaFilter function that returns a set of exam sessions that match the given criteria - * @param suspiciousExamSessions set of suspicious exam sessions to which the found suspicious exam sessions shall be added + * @param examSessions set of exam sessions to be processed + * @param examId id of the exam for which suspicious exam sessions shall be retrieved + * @param criteriaFilter function that returns a set of exam sessions that match the given criteria + * @param suspiciousExamSessions set of suspicious exam sessions to which the found suspicious exam sessions shall be added + * @param analyzeDifferentStudentExamsSameIp true if the ip addresses shall be compared, otherwise false + * @param analyzeDifferentStudentExamsSameBrowserFingerprint true if the browser fingerprints shall be compared, otherwise false */ private static void findSuspiciousSessionsForGivenCriteria(Set examSessions, long examId, BiFunction> criteriaFilter, - Set suspiciousExamSessions) { + Set suspiciousExamSessions, boolean analyzeDifferentStudentExamsSameIp, boolean analyzeDifferentStudentExamsSameBrowserFingerprint) { for (var examSession : examSessions) { Set relatedExamSessions = criteriaFilter.apply(examId, examSession); relatedExamSessions = filterEqualRelatedExamSessionsOfSameStudentExam(relatedExamSessions); if (!relatedExamSessions.isEmpty() && !isSubsetOfFoundSuspiciousSessions(relatedExamSessions, suspiciousExamSessions)) { - var session = addSuspiciousReasons(examSession, relatedExamSessions); + var session = addSuspiciousReasons(examSession, relatedExamSessions, analyzeDifferentStudentExamsSameIp, analyzeDifferentStudentExamsSameBrowserFingerprint); relatedExamSessions.add(session); suspiciousExamSessions.add(new SuspiciousExamSessions(relatedExamSessions)); } @@ -390,10 +392,14 @@ private static Set convertSuspiciousSessionsToDTO(Set * Adds suspicious reasons to exam session we compare with and the related exam sessions. * We already know that the exam sessions are suspicious, but we still have to determine what's the reason for that. * - * @param session exam session we compare with - * @param relatedExamSessions related exam sessions + * @param session exam session we compare with + * @param relatedExamSessions related exam sessions + * @param analyzeDifferentStudentExamsSameIp true if the ip addresses shall be compared, otherwise false + * @param analyzeDifferentStudentExamsSameBrowserFingerprint true if the browser fingerprints shall be compared, otherwise false + * @return exam session we compare with suspicious reasons added */ - private static ExamSession addSuspiciousReasons(ExamSession session, Set relatedExamSessions) { + private static ExamSession addSuspiciousReasons(ExamSession session, Set relatedExamSessions, boolean analyzeDifferentStudentExamsSameIp, + boolean analyzeDifferentStudentExamsSameBrowserFingerprint) { ExamSession sessionCopy = new ExamSession(); sessionCopy.setId(session.getId()); sessionCopy.setSuspiciousReasons(new HashSet<>()); @@ -407,11 +413,12 @@ private static ExamSession addSuspiciousReasons(ExamSession session, Set()); - if (relatedExamSession.hasSameBrowserFingerprint(session)) { + // if we do not check the analysis criteria, we might add reasons that should not be analyzed + if (relatedExamSession.hasSameBrowserFingerprint(session) && analyzeDifferentStudentExamsSameBrowserFingerprint) { relatedExamSession.addSuspiciousReason(SuspiciousSessionReason.DIFFERENT_STUDENT_EXAMS_SAME_BROWSER_FINGERPRINT); sessionCopy.addSuspiciousReason(SuspiciousSessionReason.DIFFERENT_STUDENT_EXAMS_SAME_BROWSER_FINGERPRINT); } - if (relatedExamSession.hasSameIpAddress(session)) { + if (relatedExamSession.hasSameIpAddress(session) && analyzeDifferentStudentExamsSameIp) { relatedExamSession.addSuspiciousReason(SuspiciousSessionReason.DIFFERENT_STUDENT_EXAMS_SAME_IP_ADDRESS); sessionCopy.addSuspiciousReason(SuspiciousSessionReason.DIFFERENT_STUDENT_EXAMS_SAME_IP_ADDRESS); } diff --git a/src/main/webapp/app/entities/exam-session.model.ts b/src/main/webapp/app/entities/exam-session.model.ts index 017b83ec2fa2..feb4670ac5c9 100644 --- a/src/main/webapp/app/entities/exam-session.model.ts +++ b/src/main/webapp/app/entities/exam-session.model.ts @@ -31,24 +31,24 @@ export class SuspiciousExamSessions { } export class SuspiciousSessionsAnalysisOptions { constructor( - diffStudentExamsSameIPAddress: boolean, - diffStudentExamsSameBrowserFingerprint: boolean, - sameStudentExamDifferentIPAddresses: boolean, - sameStudentExamDifferentBrowserFingerprints: boolean, - ipOutsideOfASpecificRange: boolean, - ipSubnet?: string, + sameIpAddressDifferentStudentExams: boolean, + sameBrowserFingerprintDifferentStudentExams: boolean, + differentIpAddressesSameStudentExam: boolean, + differentBrowserFingerprintsSameStudentExam: boolean, + ipAddressOutsideOfRange: boolean, + subnet?: string, ) { - this.differentStudentExamsSameIPAddress = diffStudentExamsSameIPAddress; - this.differentStudentExamsSameBrowserFingerprint = diffStudentExamsSameBrowserFingerprint; - this.sameStudentExamDifferentIPAddresses = sameStudentExamDifferentIPAddresses; - this.sameStudentExamDifferentBrowserFingerprints = sameStudentExamDifferentBrowserFingerprints; - this.ipOutsideOfRange = ipOutsideOfASpecificRange; - this.ipSubnet = ipSubnet; + this.sameIpAddressDifferentStudentExams = sameIpAddressDifferentStudentExams; + this.sameBrowserFingerprintDifferentStudentExams = sameBrowserFingerprintDifferentStudentExams; + this.differentIpAddressesSameStudentExam = differentIpAddressesSameStudentExam; + this.differentBrowserFingerprintsSameStudentExam = differentBrowserFingerprintsSameStudentExam; + this.ipAddressOutsideOfRange = ipAddressOutsideOfRange; + this.ipSubnet = subnet; } - differentStudentExamsSameIPAddress = false; - differentStudentExamsSameBrowserFingerprint = false; - sameStudentExamDifferentIPAddresses = false; - sameStudentExamDifferentBrowserFingerprints = false; - ipOutsideOfRange = false; + sameIpAddressDifferentStudentExams = false; + sameBrowserFingerprintDifferentStudentExams = false; + differentIpAddressesSameStudentExam = false; + differentBrowserFingerprintsSameStudentExam = false; + ipAddressOutsideOfRange = false; ipSubnet?: string; } diff --git a/src/main/webapp/app/exam/manage/suspicious-behavior/suspicious-sessions.service.ts b/src/main/webapp/app/exam/manage/suspicious-behavior/suspicious-sessions.service.ts index df2df9b9db99..4f104cb23de8 100644 --- a/src/main/webapp/app/exam/manage/suspicious-behavior/suspicious-sessions.service.ts +++ b/src/main/webapp/app/exam/manage/suspicious-behavior/suspicious-sessions.service.ts @@ -11,11 +11,11 @@ export class SuspiciousSessionsService { getSuspiciousSessions(courseId: number, examId: number, options: SuspiciousSessionsAnalysisOptions): Observable { let params = new HttpParams() - .set('differentStudentExamsSameIPAddress', options.differentStudentExamsSameIPAddress.toString()) - .set('differentStudentExamsSameBrowserFingerprint', options.differentStudentExamsSameBrowserFingerprint.toString()) - .set('sameStudentExamDifferentIPAddresses', options.sameStudentExamDifferentIPAddresses.toString()) - .set('sameStudentExamDifferentBrowserFingerprints', options.sameStudentExamDifferentBrowserFingerprints.toString()) - .set('ipOutsideOfRange', options.ipOutsideOfRange.toString()); + .set('differentStudentExamsSameIPAddress', options.sameIpAddressDifferentStudentExams.toString()) + .set('differentStudentExamsSameBrowserFingerprint', options.sameBrowserFingerprintDifferentStudentExams.toString()) + .set('sameStudentExamDifferentIPAddresses', options.differentIpAddressesSameStudentExam.toString()) + .set('sameStudentExamDifferentBrowserFingerprints', options.differentIpAddressesSameStudentExam.toString()) + .set('ipOutsideOfRange', options.ipAddressOutsideOfRange.toString()); // If subnet is provided, add it to the params if (options.ipSubnet) {