diff --git a/src/main/kotlin/ch/uzh/ifi/access/config/SecurityConfig.kt b/src/main/kotlin/ch/uzh/ifi/access/config/SecurityConfig.kt index b304c81..b3a8c43 100644 --- a/src/main/kotlin/ch/uzh/ifi/access/config/SecurityConfig.kt +++ b/src/main/kotlin/ch/uzh/ifi/access/config/SecurityConfig.kt @@ -28,7 +28,9 @@ import org.springframework.web.filter.CommonsRequestLoggingFilter import java.nio.file.Path import java.time.Duration import java.time.Instant +import java.time.LocalDate import java.time.LocalDateTime +import java.time.ZoneId @AllArgsConstructor @@ -159,13 +161,16 @@ class AuthenticationSuccessListener( else { try { val lastSync = currentAttributes["roles_synced_at"]!!.first() - val timeStamp = lastSync.substring(0, Math.min(lastSync.length, lastSync.indexOf('.') + 4)) + "Z" - val dateTime = Instant.parse(timeStamp) - val now = Instant.now() - if (Duration.between(dateTime, now).toMinutes() > 10) { + val lastSyncInstant = LocalDateTime.parse(lastSync) + val now = LocalDateTime.now() + val diff = Duration.between(lastSyncInstant, now).toMinutes() + if (diff > 10) { logger.debug { "syncing $username to courses after more than 10min" } courseService.updateStudentRoles(username) } + else { + logger.debug { "only $diff minutes elapsed since last sync of $username at ${lastSync} (now: $now)" } + } } catch (e: Exception) { logger.debug { "problem ($e, ${e.stackTrace}) with sync calculation; syncing $username to courses anyway" } courseService.updateStudentRoles(username) diff --git a/src/main/kotlin/ch/uzh/ifi/access/service/RoleService.kt b/src/main/kotlin/ch/uzh/ifi/access/service/RoleService.kt index 2ec565d..ce94b94 100644 --- a/src/main/kotlin/ch/uzh/ifi/access/service/RoleService.kt +++ b/src/main/kotlin/ch/uzh/ifi/access/service/RoleService.kt @@ -144,6 +144,7 @@ class RoleService( fun updateStudentRoles(course: Course, registrationIDs: Set, username: String) { val role = accessRealm.roles()[Role.STUDENT.withCourse(course.slug)] val rolesToAdd = listOf(role.toRepresentation()) + logger.debug { "registered students for ${course.slug}: $registrationIDs"} logger.debug { "B: updating roles for ${username} (roles to add: ${rolesToAdd})"} logger.debug { "Searching if ${username} is in ${role.getUserMembers(0, -1).size} members of ${role} in keycloak" } role.getUserMembers(0, -1)