From 9a63f3790d96e3ae44b9211cb4288203dd411a80 Mon Sep 17 00:00:00 2001 From: MaxKey Date: Sat, 6 Aug 2022 11:00:52 +0800 Subject: [PATCH] Update HttpSessionListenerAdapter.java cast Error --- .../authn/web/HttpSessionListenerAdapter.java | 30 ++++++++++++++----- 1 file changed, 23 insertions(+), 7 deletions(-) diff --git a/maxkey-authentications/maxkey-authentication-core/src/main/java/org/maxkey/authn/web/HttpSessionListenerAdapter.java b/maxkey-authentications/maxkey-authentication-core/src/main/java/org/maxkey/authn/web/HttpSessionListenerAdapter.java index 599039d3..55bcd60e 100644 --- a/maxkey-authentications/maxkey-authentication-core/src/main/java/org/maxkey/authn/web/HttpSessionListenerAdapter.java +++ b/maxkey-authentications/maxkey-authentication-core/src/main/java/org/maxkey/authn/web/HttpSessionListenerAdapter.java @@ -28,6 +28,7 @@ import org.maxkey.web.WebConstants; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.security.core.Authentication; +import org.springframework.security.core.userdetails.User; @WebListener public class HttpSessionListenerAdapter implements HttpSessionListener { @@ -53,20 +54,35 @@ public class HttpSessionListenerAdapter implements HttpSessionListener { public void sessionDestroyed(HttpSessionEvent sessionEvent) { HttpSession session = sessionEvent.getSession(); Authentication authentication = (Authentication ) session.getAttribute(WebConstants.AUTHENTICATION); - SignPrincipal principal = AuthorizationUtils.getPrincipal(authentication); - if(principal != null && principal.getUserInfo() !=null) { - _logger.debug("{} HttpSession Id {} for userId {} , username {} @Ticket {} Destroyed" , + Object principal = authentication == null ? null : authentication.getPrincipal(); + + if(principal != null ) { + if(principal instanceof SignPrincipal) { + SignPrincipal signPrincipal = (SignPrincipal)principal; + _logger.trace("{} HttpSession Id {} for userId {} , username {} @Ticket {} Destroyed" , + DateUtils.formatDateTime(new Date()), + session.getId(), + signPrincipal.getUserInfo().getId(), + signPrincipal.getUserInfo().getUsername(), + signPrincipal.getSession().getId()); + }else if(principal instanceof User) { + User user = (User)principal; + _logger.trace("{} HttpSession Id {} for username {} password {} Destroyed" , DateUtils.formatDateTime(new Date()), session.getId(), - principal.getUserInfo().getId(), - principal.getUserInfo().getUsername(), - principal.getSession().getId()); + user.getUsername(), + user.getPassword()); + }else{ + _logger.trace("{} HttpSession Id {} for principal {} Destroyed" , + DateUtils.formatDateTime(new Date()), + session.getId(), + principal); + } }else { _logger.trace("{} HttpSession Id {} Destroyed" , DateUtils.formatDateTime(new Date()), session.getId()); } - } } -- GitLab