Skip to content

Commit e699ab1

Browse files
committed
Improved logic for setting actor in revisions.
1 parent aba3fc6 commit e699ab1

File tree

1 file changed

+19
-20
lines changed

1 file changed

+19
-20
lines changed

src/main/kotlin/no/nav/klage/oppgave/eventlisteners/OurRevisionListener.kt

Lines changed: 19 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -26,40 +26,39 @@ class OurRevisionListener(
2626
override fun newRevision(revisionEntity: Any?) {
2727
revisionEntity as OurRevision
2828

29+
var actor: String? = null
30+
2931
val request = try {
3032
val requestAttributes = RequestContextHolder.getRequestAttributes()
3133
if (requestAttributes != null) {
3234
val request = (requestAttributes as ServletRequestAttributes).request
3335
request.method + " " + request.requestURI
3436
} else {
37+
//no exception occurred, we just don't have a request
38+
actor = systembrukerIdent
3539
null
3640
}
3741
} catch (e: Exception) {
3842
logger.debug("No request found to set on revision entity. Setting to null.", e)
3943
null
4044
}
4145

42-
val actor = if (request == null) {
43-
systembrukerIdent
44-
} else {
45-
val navIdentFromToken = try {
46-
tokenUtil.getIdent()
47-
} catch (e: Exception) {
48-
logger.debug("No NAVIdent found in token.", e)
49-
null
50-
}
51-
val callingApplication = try {
52-
tokenUtil.getCallingApplication()
53-
} catch (e: Exception) {
54-
logger.warn("Failed to get calling application from token.", e)
55-
null
56-
}
46+
val navIdentFromToken = try {
47+
tokenUtil.getIdent()
48+
} catch (e: Exception) {
49+
logger.debug("No NAVIdent found in token.", e)
50+
null
51+
}
5752

58-
if (navIdentFromToken == null && callingApplication == null) {
59-
logger.warn("Neither NAVIdent nor calling application could be found from token. Setting 'unknown'.")
60-
}
53+
val callingApplication = try {
54+
tokenUtil.getCallingApplication()
55+
} catch (e: Exception) {
56+
logger.warn("Failed to get calling application from token.", e)
57+
null
58+
}
6159

62-
navIdentFromToken ?: callingApplication ?: "unknown"
60+
if (navIdentFromToken != null || callingApplication != null) {
61+
actor = navIdentFromToken ?: callingApplication
6362
}
6463

6564
val traceId = try {
@@ -70,7 +69,7 @@ class OurRevisionListener(
7069
}
7170

7271
revisionEntity.request = request
73-
revisionEntity.actor = actor
72+
revisionEntity.actor = actor ?: "unknown"
7473
revisionEntity.traceId = traceId
7574
}
7675
}

0 commit comments

Comments
 (0)