@@ -29,9 +29,10 @@ class AuthenticatedRequest {
29
29
/**
30
30
* Ensure an appropriate MDC context is available when {@code closure } is executed.
31
31
*/
32
- public static final Closure propagate (Closure closure ,
33
- boolean restoreOriginalContext = true ,
34
- Object principal = SecurityContextHolder . context?. authentication?. principal) {
32
+ public static final Closure propagate (
33
+ Closure closure ,
34
+ boolean restoreOriginalContext = true ,
35
+ Object principal = SecurityContextHolder . context?. authentication?. principal) {
35
36
def spinnakerUser = getSpinnakerUser(principal). orElse(null )
36
37
if (! spinnakerUser) {
37
38
return {
@@ -54,17 +55,15 @@ class AuthenticatedRequest {
54
55
MDC . put(SPINNAKER_ACCOUNTS , spinnakerAccounts)
55
56
}
56
57
closure()
57
- } catch (Exception e) {
58
- log. error(" Error occurred propagating authentication context" , e)
59
- throw e
60
58
} finally {
61
59
MDC . clear()
62
60
63
61
try {
64
62
// force clear to avoid the potential for a memory leak if log4j is being used
65
63
def log4jMDC = Class . forName(" org.apache.log4j.MDC" )
66
64
log4jMDC. clear()
67
- } catch (Exception ignored) {}
65
+ } catch (Exception ignored) {
66
+ }
68
67
69
68
if (originalSpinnakerUser && restoreOriginalContext) {
70
69
MDC . put(SPINNAKER_USER , originalSpinnakerUser)
@@ -79,26 +78,24 @@ class AuthenticatedRequest {
79
78
80
79
public static Map<String , Optional<String > > getAuthenticationHeaders () {
81
80
return [
82
- (SPINNAKER_USER ) : getSpinnakerUser(),
83
- (SPINNAKER_ACCOUNTS ): getSpinnakerAccounts()
81
+ (SPINNAKER_USER ) : getSpinnakerUser(),
82
+ (SPINNAKER_ACCOUNTS ): getSpinnakerAccounts()
84
83
]
85
84
}
86
85
87
86
public static Optional<String > getSpinnakerUser (
88
- Object principal = SecurityContextHolder . context?. authentication?. principal
89
- ) {
87
+ Object principal = SecurityContextHolder . context?. authentication?. principal) {
90
88
def spinnakerUser = MDC . get(SPINNAKER_USER )
91
89
92
90
if (principal && principal instanceof User ) {
93
- spinnakerUser = principal. email
91
+ spinnakerUser = principal. username
94
92
}
95
93
96
94
return Optional . ofNullable(spinnakerUser)
97
95
}
98
96
99
97
public static Optional<String > getSpinnakerAccounts (
100
- Object principal = SecurityContextHolder . context?. authentication?. principal
101
- ) {
98
+ Object principal = SecurityContextHolder . context?. authentication?. principal) {
102
99
def spinnakerAccounts = MDC . get(SPINNAKER_ACCOUNTS )
103
100
104
101
if (principal && principal instanceof User && principal. allowedAccounts) {
0 commit comments