Skip to content

Commit

Permalink
rename same params and do only add reasons that should be analyzed
Browse files Browse the repository at this point in the history
  • Loading branch information
tobias-lippert committed Oct 8, 2023
1 parent c0a78ba commit dff11e0
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 36 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}

Expand Down Expand Up @@ -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<ExamSession> examSessions, long examId, BiFunction<Long, ExamSession, Set<ExamSession>> criteriaFilter,
Set<SuspiciousExamSessions> suspiciousExamSessions) {
Set<SuspiciousExamSessions> suspiciousExamSessions, boolean analyzeDifferentStudentExamsSameIp, boolean analyzeDifferentStudentExamsSameBrowserFingerprint) {
for (var examSession : examSessions) {
Set<ExamSession> 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));
}
Expand Down Expand Up @@ -390,10 +392,14 @@ private static Set<SuspiciousExamSessionsDTO> 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<ExamSession> relatedExamSessions) {
private static ExamSession addSuspiciousReasons(ExamSession session, Set<ExamSession> relatedExamSessions, boolean analyzeDifferentStudentExamsSameIp,
boolean analyzeDifferentStudentExamsSameBrowserFingerprint) {
ExamSession sessionCopy = new ExamSession();
sessionCopy.setId(session.getId());
sessionCopy.setSuspiciousReasons(new HashSet<>());
Expand All @@ -407,11 +413,12 @@ private static ExamSession addSuspiciousReasons(ExamSession session, Set<ExamSes

for (var relatedExamSession : relatedExamSessions) {
relatedExamSession.setSuspiciousReasons(new HashSet<>());
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);
}
Expand Down
34 changes: 17 additions & 17 deletions src/main/webapp/app/entities/exam-session.model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@ export class SuspiciousSessionsService {

getSuspiciousSessions(courseId: number, examId: number, options: SuspiciousSessionsAnalysisOptions): Observable<SuspiciousExamSessions[]> {
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) {
Expand Down

0 comments on commit dff11e0

Please sign in to comment.