From 771ba2df0e894bdc230cb2c92e56a78a2ce9f6df Mon Sep 17 00:00:00 2001 From: Rahul Chekuri <89373036+rahul-chekuri@users.noreply.github.com> Date: Mon, 19 Sep 2022 16:01:17 +0530 Subject: [PATCH] OP-17098: serialisation issues are fixed. (#255) --- .../gate/audit/AuthenticationAuditListener.java | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/gate-web/src/main/java/com/opsmx/spinnaker/gate/audit/AuthenticationAuditListener.java b/gate-web/src/main/java/com/opsmx/spinnaker/gate/audit/AuthenticationAuditListener.java index 26f3b02649..3bf753bed6 100644 --- a/gate-web/src/main/java/com/opsmx/spinnaker/gate/audit/AuthenticationAuditListener.java +++ b/gate-web/src/main/java/com/opsmx/spinnaker/gate/audit/AuthenticationAuditListener.java @@ -49,7 +49,7 @@ public void onApplicationEvent(AbstractAuthenticationEvent event) { if (event.getAuthentication().isAuthenticated() && event instanceof InteractiveAuthenticationSuccessEvent) { log.debug("publishEvent InteractiveAuthenticationSuccessEvent"); - handleInteractiveAuthenticationSuccessEvent(event); + handleAuthenticationEvent(event, AuditEventType.AUTHENTICATION_SUCCESSFUL_AUDIT); return; } @@ -62,6 +62,15 @@ public void onApplicationEvent(AbstractAuthenticationEvent event) { log.debug("publishEvent AbstractAuthenticationFailureEvent"); auditHandler.publishEvent(AuditEventType.AUTHENTICATION_FAILURE_AUDIT, event); } else if (event instanceof LogoutSuccessEvent) { + if (event + .getAuthentication() + .getClass() + .getName() + .equals("org.springframework.security.providers.ExpiringUsernameAuthenticationToken")) { + log.debug("publishEvent LogoutSuccessEvent with ExpiringUsernameAuthenticationToken"); + handleAuthenticationEvent(event, AuditEventType.SUCCESSFUL_USER_LOGOUT_AUDIT); + return; + } log.debug("publishEvent LogoutSuccessEvent"); auditHandler.publishEvent(AuditEventType.SUCCESSFUL_USER_LOGOUT_AUDIT, event); } @@ -71,7 +80,8 @@ public void onApplicationEvent(AbstractAuthenticationEvent event) { } } - private void handleInteractiveAuthenticationSuccessEvent(AbstractAuthenticationEvent event) { + private void handleAuthenticationEvent( + AbstractAuthenticationEvent event, AuditEventType eventType) { AbstractAuthenticationToken auth = (AbstractAuthenticationToken) event.getAuthentication(); String name = auth.getName(); List roles = @@ -79,6 +89,6 @@ private void handleInteractiveAuthenticationSuccessEvent(AbstractAuthenticationE .map(GrantedAuthority::getAuthority) .collect(Collectors.toList()); AuditData data = new AuditData(name, roles); - auditHandler.publishEvent(AuditEventType.AUTHENTICATION_SUCCESSFUL_AUDIT, data); + auditHandler.publishEvent(eventType, data); } }