@@ -26,19 +26,51 @@ class OurRevisionListener(
26
26
override fun newRevision (revisionEntity : Any? ) {
27
27
revisionEntity as OurRevision
28
28
29
- try {
29
+ val request = try {
30
30
val requestAttributes = RequestContextHolder .getRequestAttributes()
31
31
if (requestAttributes != null ) {
32
32
val request = (requestAttributes as ServletRequestAttributes ).request
33
- revisionEntity.actor = tokenUtil.getIdent()
34
- revisionEntity.request = request.method + " " + request.requestURI
33
+ request.method + " " + request.requestURI
35
34
} else {
36
- revisionEntity.actor = systembrukerIdent
35
+ null
37
36
}
38
- revisionEntity.traceId = Span .current().spanContext.traceId
39
37
} catch (e: Exception ) {
40
- logger.warn( " Failed to set correct actor and/or request on revision entity. Setting 'unknown' ." , e)
41
- revisionEntity.actor = " unknown "
38
+ logger.debug( " No request found to set on revision entity. Setting to null ." , e)
39
+ null
42
40
}
41
+
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
+ }
57
+
58
+ if (navIdentFromToken == null && callingApplication == null ) {
59
+ logger.warn(" Neither NAVIdent nor calling application could be found from token. Setting 'unknown'." )
60
+ }
61
+
62
+ navIdentFromToken ? : callingApplication ? : " unknown"
63
+ }
64
+
65
+ val traceId = try {
66
+ Span .current().spanContext.traceId
67
+ } catch (e: Exception ) {
68
+ logger.warn(" Failed to set traceId on revision entity. Setting 'unknown'." , e)
69
+ " unknown"
70
+ }
71
+
72
+ revisionEntity.request = request
73
+ revisionEntity.actor = actor
74
+ revisionEntity.traceId = traceId
43
75
}
44
76
}
0 commit comments