Skip to content

Commit

Permalink
debugging participation issue
Browse files Browse the repository at this point in the history
  • Loading branch information
sealexan committed Feb 22, 2024
1 parent e96870c commit 40cf520
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
13 changes: 9 additions & 4 deletions src/main/kotlin/ch/uzh/ifi/access/config/SecurityConfig.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down
1 change: 1 addition & 0 deletions src/main/kotlin/ch/uzh/ifi/access/service/RoleService.kt
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,7 @@ class RoleService(
fun updateStudentRoles(course: Course, registrationIDs: Set<String>, 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)
Expand Down

0 comments on commit 40cf520

Please sign in to comment.