Index: webapps/docs/changelog.xml =================================================================== --- webapps/docs/changelog.xml (revision 1785764) +++ webapps/docs/changelog.xml (revision 1785765) @@ -188,6 +188,11 @@ Ensure the ASF logo image is correctly displayed in docs and host-manager applications. (violetagg) + + 60824: Correctly cache the Subject in the + session - if there is a session - when running under a + SecurityManager. Patch provided by Jan Engehausen. (markt) + Index: java/org/apache/catalina/connector/Request.java =================================================================== --- java/org/apache/catalina/connector/Request.java (revision 1785764) +++ java/org/apache/catalina/connector/Request.java (revision 1785765) @@ -1985,24 +1985,35 @@ * * @param principal The user Principal */ - public void setUserPrincipal(Principal principal) { - - if (Globals.IS_SECURITY_ENABLED){ - HttpSession session = getSession(false); - if ( (subject != null) && - (!subject.getPrincipals().contains(principal)) ){ + public void setUserPrincipal(final Principal principal) { + if (Globals.IS_SECURITY_ENABLED) { + if (subject == null) { + final HttpSession session = getSession(false); + if (session == null) { + // Cache the subject in the request + subject = newSubject(principal); + } else { + // Cache the subject in the request and the session + subject = (Subject) session.getAttribute(Globals.SUBJECT_ATTR); + if (subject == null) { + subject = newSubject(principal); + session.setAttribute(Globals.SUBJECT_ATTR, subject); + } else { + subject.getPrincipals().add(principal); + } + } + } else { subject.getPrincipals().add(principal); - } else if (session != null && - session.getAttribute(Globals.SUBJECT_ATTR) == null) { - subject = new Subject(); - subject.getPrincipals().add(principal); } - if (session != null){ - session.setAttribute(Globals.SUBJECT_ATTR, subject); - } } + userPrincipal = principal; + } - this.userPrincipal = principal; + + private Subject newSubject(final Principal principal) { + final Subject result = new Subject(); + result.getPrincipals().add(principal); + return result; } Index: . =================================================================== --- . (revision 1785764) +++ . (revision 1785765) Property changes on: . ___________________________________________________________________ Modified: svn:mergeinfo Merged /tomcat/tc8.5.x/trunk:r1785763 Merged /tomcat/trunk:r1785762