From fbba8200de285627cf86a678350a7a719abc68f0 Mon Sep 17 00:00:00 2001 From: Joze RIHTARSIC <Joze.RIHTARSIC@ext.ec.europa.eu> Date: Mon, 11 Oct 2021 11:23:15 +0200 Subject: [PATCH] Fix failed bamboo plans --- .../auth/SMPAuthenticationEventListener.java | 23 +++++++++++++++---- smp-webapp/src/main/webapp/WEB-INF/web.xml | 4 ++++ 2 files changed, 22 insertions(+), 5 deletions(-) diff --git a/smp-webapp/src/main/java/eu/europa/ec/edelivery/smp/auth/SMPAuthenticationEventListener.java b/smp-webapp/src/main/java/eu/europa/ec/edelivery/smp/auth/SMPAuthenticationEventListener.java index 017097f5c..69b04736a 100644 --- a/smp-webapp/src/main/java/eu/europa/ec/edelivery/smp/auth/SMPAuthenticationEventListener.java +++ b/smp-webapp/src/main/java/eu/europa/ec/edelivery/smp/auth/SMPAuthenticationEventListener.java @@ -45,10 +45,23 @@ public class SMPAuthenticationEventListener implements ApplicationListener<Authe public void onApplicationEvent (AuthenticationSuccessEvent event) { Collection<? extends GrantedAuthority> authorities = event.getAuthentication().getAuthorities(); boolean hasAdminRole = authorities.stream().anyMatch(grantedAuthority -> StringUtils.equalsIgnoreCase(grantedAuthority.getAuthority(), SMPAuthority.S_AUTHORITY_SYSTEM_ADMIN.getAuthority())); - ServletRequestAttributes attr = (ServletRequestAttributes) RequestContextHolder.currentRequestAttributes(); - HttpSession session = attr.getRequest().getSession(); - int idleTimeout =(hasAdminRole ? configurationService.getSessionIdleTimeoutForAdmin():configurationService.getSessionIdleTimeoutForUser()); - LOG.debug("Set session idle timeout [{}] for user [{}]", idleTimeout,event.getAuthentication().getName()); - session.setMaxInactiveInterval(idleTimeout); + ServletRequestAttributes attr = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes(); + if (attr!= null) { + HttpSession session = attr.getRequest().getSession(); + int idleTimeout = (hasAdminRole ? configurationService.getSessionIdleTimeoutForAdmin() : configurationService.getSessionIdleTimeoutForUser()); + LOG.debug("Set session idle timeout [{}] for user [{}]", idleTimeout, event.getAuthentication().getName()); + session.setMaxInactiveInterval(idleTimeout); + } else { + LOG.warn("Could not get ServletRequestAttributes attributes for authentication [{}]", event.getAuthentication() ); + } + /*try { + + HttpSession session = attr.getRequest().getSession(); + int idleTimeout = (hasAdminRole ? configurationService.getSessionIdleTimeoutForAdmin() : configurationService.getSessionIdleTimeoutForUser()); + LOG.debug("Set session idle timeout [{}] for user [{}]", idleTimeout, event.getAuthentication().getName()); + session.setMaxInactiveInterval(idleTimeout); + } catch (RuntimeException ex) { + LOG.error("Session error: " , ex); + }*/ } } \ No newline at end of file diff --git a/smp-webapp/src/main/webapp/WEB-INF/web.xml b/smp-webapp/src/main/webapp/WEB-INF/web.xml index c79b6f718..d6de09988 100644 --- a/smp-webapp/src/main/webapp/WEB-INF/web.xml +++ b/smp-webapp/src/main/webapp/WEB-INF/web.xml @@ -102,6 +102,10 @@ --> <listener> <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class> + + </listener> + <listener> + <listener-class>org.springframework.web.context.request.RequestContextListener</listener-class> </listener> </web-app> -- GitLab