Skip to content

Commit d132866

Browse files
committed
Fix WebPrincipal not serializable.
Because of a thread-local field in the securityContext field.
1 parent 3498ee1 commit d132866

File tree

2 files changed

+6
-4
lines changed

2 files changed

+6
-4
lines changed

appserver/security/webintegration/src/main/java/com/sun/web/security/RealmAdapter.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -440,14 +440,15 @@ public boolean invokeAuthenticateDelegate(HttpRequest request, HttpResponse resp
440440
LoginConfig config = context.getLoginConfig();
441441

442442
if (isJakartaAuthenticationEnabled()) {
443+
final SecurityContext securityContext = SecurityContext.getCurrent();
443444
// Jakarta Authentication is enabled for this application
444445
try {
445446
context.fireContainerEvent(BEFORE_AUTHENTICATION, null);
446447
RequestFacade requestFacade = (RequestFacade) request.getRequest();
447-
SecurityContext.getCurrent().setSessionPrincipal(requestFacade.getRequestPrincipal());
448+
securityContext.setSessionPrincipal(requestFacade.getRequestPrincipal());
448449
return validate(request, response, config, authenticator, calledFromAuthenticate);
449450
} finally {
450-
SecurityContext.getCurrent().setSessionPrincipal(null);
451+
securityContext.setSessionPrincipal(null);
451452
context.fireContainerEvent(AFTER_AUTHENTICATION, null);
452453
}
453454
}

nucleus/security/core/src/main/java/com/sun/enterprise/security/SecurityContext.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,11 +72,12 @@ public class SecurityContext extends AbstractSecurityContext {
7272

7373
private static AuthPermission doAsPrivilegedPerm = new AuthPermission("doAsPrivileged");
7474

75+
// this is static because it's a thread local, which isn't serializable
76+
private static ThreadLocal<Principal> sessionPrincipal = new ThreadLocal<>();
77+
7578
// Did the client log in as or did the server generate the context
7679
private boolean serverGeneratedSecurityContext;
7780

78-
private final ThreadLocal<Principal> sessionPrincipal = new ThreadLocal<>();
79-
8081
/*
8182
* This creates a new SecurityContext object. Note: that the docs for Subject state that the internal sets (eg. the
8283
* principal set) cannot be modified unless the caller has the modifyPrincipals AuthPermission. That said, there may be

0 commit comments

Comments
 (0)