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 1872810
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 5 deletions.
14 changes: 10 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 @@ -149,6 +151,7 @@ class AuthenticationSuccessListener(

override fun onApplicationEvent(event: AuthenticationSuccessEvent) {
val username = event.authentication.name
logger.debug { "USER [$username] LOGGED IN" }
roleService.getUserRepresentationForUsername(username)?.let { user ->
// TODO: clean up this horrible mess
val currentAttributes = user.attributes ?: mutableMapOf()
Expand All @@ -159,13 +162,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
6 changes: 5 additions & 1 deletion src/main/kotlin/ch/uzh/ifi/access/service/RoleService.kt
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,11 @@ class RoleService(
}

fun getUserRepresentationForUsername(username: String): UserRepresentation? {
return accessRealm.users().search(username, true).firstOrNull()
val res = accessRealm.users().search(username, true).firstOrNull()
if (res == null) {
logger.debug { "RoleService: Could not find user $username" }
}
return res
}

fun createCourseRoles(courseSlug: String?): String? {
Expand Down

0 comments on commit 1872810

Please sign in to comment.