Skip to content

Commit

Permalink
Create new SecurityContext when the Authentication is changed during …
Browse files Browse the repository at this point in the history
…login
  • Loading branch information
markpatton committed Apr 4, 2024
1 parent 99ba262 commit 3338fa0
Showing 1 changed file with 6 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -321,15 +321,18 @@ private String get(Map<String, List<Object>> attributes, Attribute attr, boolean
@Override
protected void doFilterInternal(HttpServletRequest request, HttpServletResponse response, FilterChain chain)
throws ServletException, IOException {
SecurityContext context = this.securityContextHolderStrategy.getContext();
Authentication auth = context.getAuthentication();
Authentication auth = securityContextHolderStrategy.getContext().getAuthentication();

if (auth != null && auth.isAuthenticated() && auth.getPrincipal() instanceof Saml2AuthenticatedPrincipal) {
try {
SecurityContext context = securityContextHolderStrategy.createEmptyContext();

context.setAuthentication(authenticate((Saml2AuthenticatedPrincipal) auth.getPrincipal()));

securityContextHolderStrategy.setContext(context);
securityContextRepository.saveContext(context, request, response);

LOG.debug("Shib user logged in {}", auth.getName());
LOG.debug("User logged in {}", auth.getName());
} catch (AuthenticationException e) {
// This should not happen
LOG.error("Login failed", e);
Expand Down

0 comments on commit 3338fa0

Please sign in to comment.