Skip to content

Commit 87b1ed4

Browse files
author
Travis Tomsu
authored
Pull User.username rather than email when dealing with the X-SPINNAKER-USER header. Fixes https://github.com/spinnaker/fiat/issues/93 (#48)
1 parent b1f7a89 commit 87b1ed4

File tree

2 files changed

+12
-15
lines changed

2 files changed

+12
-15
lines changed

kork-security/src/main/groovy/com/netflix/spinnaker/security/AuthenticatedRequest.groovy

+11-14
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,10 @@ class AuthenticatedRequest {
2929
/**
3030
* Ensure an appropriate MDC context is available when {@code closure} is executed.
3131
*/
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) {
3536
def spinnakerUser = getSpinnakerUser(principal).orElse(null)
3637
if (!spinnakerUser) {
3738
return {
@@ -54,17 +55,15 @@ class AuthenticatedRequest {
5455
MDC.put(SPINNAKER_ACCOUNTS, spinnakerAccounts)
5556
}
5657
closure()
57-
} catch (Exception e) {
58-
log.error("Error occurred propagating authentication context", e)
59-
throw e
6058
} finally {
6159
MDC.clear()
6260

6361
try {
6462
// force clear to avoid the potential for a memory leak if log4j is being used
6563
def log4jMDC = Class.forName("org.apache.log4j.MDC")
6664
log4jMDC.clear()
67-
} catch (Exception ignored) {}
65+
} catch (Exception ignored) {
66+
}
6867

6968
if (originalSpinnakerUser && restoreOriginalContext) {
7069
MDC.put(SPINNAKER_USER, originalSpinnakerUser)
@@ -79,26 +78,24 @@ class AuthenticatedRequest {
7978

8079
public static Map<String, Optional<String>> getAuthenticationHeaders() {
8180
return [
82-
(SPINNAKER_USER) : getSpinnakerUser(),
83-
(SPINNAKER_ACCOUNTS): getSpinnakerAccounts()
81+
(SPINNAKER_USER) : getSpinnakerUser(),
82+
(SPINNAKER_ACCOUNTS): getSpinnakerAccounts()
8483
]
8584
}
8685

8786
public static Optional<String> getSpinnakerUser(
88-
Object principal = SecurityContextHolder.context?.authentication?.principal
89-
) {
87+
Object principal = SecurityContextHolder.context?.authentication?.principal) {
9088
def spinnakerUser = MDC.get(SPINNAKER_USER)
9189

9290
if (principal && principal instanceof User) {
93-
spinnakerUser = principal.email
91+
spinnakerUser = principal.username
9492
}
9593

9694
return Optional.ofNullable(spinnakerUser)
9795
}
9896

9997
public static Optional<String> getSpinnakerAccounts(
100-
Object principal = SecurityContextHolder.context?.authentication?.principal
101-
) {
98+
Object principal = SecurityContextHolder.context?.authentication?.principal) {
10299
def spinnakerAccounts = MDC.get(SPINNAKER_ACCOUNTS)
103100

104101
if (principal && principal instanceof User && principal.allowedAccounts) {

kork-web/src/main/groovy/com/netflix/spinnaker/filters/AuthenticatedRequestFilter.groovy

+1-1
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ class AuthenticatedRequestFilter implements Filter {
8383
}
8484
def principal = securityContext?.authentication?.principal
8585
if (principal && principal instanceof User) {
86-
spinnakerUser = principal.email
86+
spinnakerUser = principal.username
8787
spinnakerAccounts = principal.allowedAccounts.join(",")
8888
}
8989
}

0 commit comments

Comments
 (0)