@Test public void testHandlesExceptionFromFiringProfileSelectionEvent() throws IOException, ServletException { SecurityContextHolder.createEmptyContext(); SecurityContextHolder.getContext().setAuthentication(auth); when(request.getServletPath()).thenReturn("/Login"); when(request.getParameter(LoginController.REQUESTED_PROFILE_KEY)) .thenReturn("someProfileKey"); final ProfileSelectionEvent expectedEvent = new ProfileSelectionEvent(filter, "someProfileKey", person, request); final RuntimeException rootCause = new RuntimeException(); final PropertyAccessException propertyAccessException = new PropertyAccessException( rootCause, "String message", false, PortalPreAuthenticatedProcessingFilterTest.class, "somePropertyName"); doThrow(propertyAccessException).when(this.eventPublisher).publishEvent(expectedEvent); filter.doFilter(request, response, filterChain); doThrow(rootCause).when(this.eventPublisher).publishEvent(expectedEvent); filter.doFilter(request, response, filterChain); }
@Override public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException { final HttpServletRequest httpServletRequest = (HttpServletRequest) request; final long timestamp = System.currentTimeMillis(); UUID uuid = null; if (logger.isDebugEnabled()) { uuid = UUID.randomUUID(); logger.debug( "STARTING [{}] for URI='{}' #milestone", uuid, httpServletRequest.getRequestURI()); } final String currentPath = httpServletRequest.getServletPath(); if (loginPath.equals(currentPath)) { final org.springframework.security.core.Authentication originalAuthentication = SecurityContextHolder.getContext().getAuthentication(); if (clearSecurityContextPriorToPortalAuthentication) { SecurityContextHolder.clearContext(); } logForLoginPath(currentPath); doPortalAuthentication((HttpServletRequest) request, originalAuthentication); chain.doFilter(request, response); } else if (logoutPath.equals(currentPath)) { SecurityContextHolder.clearContext(); logForLogoutPath(currentPath); chain.doFilter(request, response); } else { logForNonLoginOrLogoutPath(currentPath); super.doFilter(request, response, chain); } if (logger.isDebugEnabled()) { logger.debug( "FINISHED [{}] for URI='{}' in {}ms #milestone", uuid, httpServletRequest.getRequestURI(), Long.toString(System.currentTimeMillis() - timestamp)); } }
PortalPreAuthenticatedProcessingFilter extends AbstractPreAuthenticatedProcessingFilter { @Override public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException { final HttpServletRequest httpServletRequest = (HttpServletRequest) request; final long timestamp = System.currentTimeMillis(); UUID uuid = null; if (logger.isDebugEnabled()) { uuid = UUID.randomUUID(); logger.debug( "STARTING [{}] for URI='{}' #milestone", uuid, httpServletRequest.getRequestURI()); } final String currentPath = httpServletRequest.getServletPath(); if (loginPath.equals(currentPath)) { final org.springframework.security.core.Authentication originalAuthentication = SecurityContextHolder.getContext().getAuthentication(); if (clearSecurityContextPriorToPortalAuthentication) { SecurityContextHolder.clearContext(); } logForLoginPath(currentPath); doPortalAuthentication((HttpServletRequest) request, originalAuthentication); chain.doFilter(request, response); } else if (logoutPath.equals(currentPath)) { SecurityContextHolder.clearContext(); logForLogoutPath(currentPath); chain.doFilter(request, response); } else { logForNonLoginOrLogoutPath(currentPath); super.doFilter(request, response, chain); } if (logger.isDebugEnabled()) { logger.debug( "FINISHED [{}] for URI='{}' in {}ms #milestone", uuid, httpServletRequest.getRequestURI(), Long.toString(System.currentTimeMillis() - timestamp)); } } }
PortalPreAuthenticatedProcessingFilter extends AbstractPreAuthenticatedProcessingFilter { @Override public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException { final HttpServletRequest httpServletRequest = (HttpServletRequest) request; final long timestamp = System.currentTimeMillis(); UUID uuid = null; if (logger.isDebugEnabled()) { uuid = UUID.randomUUID(); logger.debug( "STARTING [{}] for URI='{}' #milestone", uuid, httpServletRequest.getRequestURI()); } final String currentPath = httpServletRequest.getServletPath(); if (loginPath.equals(currentPath)) { final org.springframework.security.core.Authentication originalAuthentication = SecurityContextHolder.getContext().getAuthentication(); if (clearSecurityContextPriorToPortalAuthentication) { SecurityContextHolder.clearContext(); } logForLoginPath(currentPath); doPortalAuthentication((HttpServletRequest) request, originalAuthentication); chain.doFilter(request, response); } else if (logoutPath.equals(currentPath)) { SecurityContextHolder.clearContext(); logForLogoutPath(currentPath); chain.doFilter(request, response); } else { logForNonLoginOrLogoutPath(currentPath); super.doFilter(request, response, chain); } if (logger.isDebugEnabled()) { logger.debug( "FINISHED [{}] for URI='{}' in {}ms #milestone", uuid, httpServletRequest.getRequestURI(), Long.toString(System.currentTimeMillis() - timestamp)); } }  }
PortalPreAuthenticatedProcessingFilter extends AbstractPreAuthenticatedProcessingFilter { @Override public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException { final HttpServletRequest httpServletRequest = (HttpServletRequest) request; final long timestamp = System.currentTimeMillis(); UUID uuid = null; if (logger.isDebugEnabled()) { uuid = UUID.randomUUID(); logger.debug( "STARTING [{}] for URI='{}' #milestone", uuid, httpServletRequest.getRequestURI()); } final String currentPath = httpServletRequest.getServletPath(); if (loginPath.equals(currentPath)) { final org.springframework.security.core.Authentication originalAuthentication = SecurityContextHolder.getContext().getAuthentication(); if (clearSecurityContextPriorToPortalAuthentication) { SecurityContextHolder.clearContext(); } logForLoginPath(currentPath); doPortalAuthentication((HttpServletRequest) request, originalAuthentication); chain.doFilter(request, response); } else if (logoutPath.equals(currentPath)) { SecurityContextHolder.clearContext(); logForLogoutPath(currentPath); chain.doFilter(request, response); } else { logForNonLoginOrLogoutPath(currentPath); super.doFilter(request, response, chain); } if (logger.isDebugEnabled()) { logger.debug( "FINISHED [{}] for URI='{}' in {}ms #milestone", uuid, httpServletRequest.getRequestURI(), Long.toString(System.currentTimeMillis() - timestamp)); } }  @Autowired void setIdentitySwapperManager(IdentitySwapperManager identitySwapperManager); @Autowired void setPersonManager(IPersonManager personManager); @Autowired void setPersonService(PersonService personService); @Autowired void setAuthenticationService(Authentication authenticationService); @Autowired void setIdTokenFactory(IdTokenFactory idTokenFactory); void setClearSecurityContextPriorToPortalAuthentication(boolean b); @Autowired void setSecurityContextFactories(Set<ISecurityContextFactory> securityContextFactories); @Override void afterPropertiesSet(); void setLoginPath(String loginPath); void setLogoutPath(String logoutPath); @Override void doFilter(ServletRequest request, ServletResponse response, FilterChain chain); @Override void setApplicationEventPublisher(
            ApplicationEventPublisher anApplicationEventPublisher); }
PortalPreAuthenticatedProcessingFilter extends AbstractPreAuthenticatedProcessingFilter { @Override public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException { final HttpServletRequest httpServletRequest = (HttpServletRequest) request; final long timestamp = System.currentTimeMillis(); UUID uuid = null; if (logger.isDebugEnabled()) { uuid = UUID.randomUUID(); logger.debug( "STARTING [{}] for URI='{}' #milestone", uuid, httpServletRequest.getRequestURI()); } final String currentPath = httpServletRequest.getServletPath(); if (loginPath.equals(currentPath)) { final org.springframework.security.core.Authentication originalAuthentication = SecurityContextHolder.getContext().getAuthentication(); if (clearSecurityContextPriorToPortalAuthentication) { SecurityContextHolder.clearContext(); } logForLoginPath(currentPath); doPortalAuthentication((HttpServletRequest) request, originalAuthentication); chain.doFilter(request, response); } else if (logoutPath.equals(currentPath)) { SecurityContextHolder.clearContext(); logForLogoutPath(currentPath); chain.doFilter(request, response); } else { logForNonLoginOrLogoutPath(currentPath); super.doFilter(request, response, chain); } if (logger.isDebugEnabled()) { logger.debug( "FINISHED [{}] for URI='{}' in {}ms #milestone", uuid, httpServletRequest.getRequestURI(), Long.toString(System.currentTimeMillis() - timestamp)); } }  @Autowired void setIdentitySwapperManager(IdentitySwapperManager identitySwapperManager); @Autowired void setPersonManager(IPersonManager personManager); @Autowired void setPersonService(PersonService personService); @Autowired void setAuthenticationService(Authentication authenticationService); @Autowired void setIdTokenFactory(IdTokenFactory idTokenFactory); void setClearSecurityContextPriorToPortalAuthentication(boolean b); @Autowired void setSecurityContextFactories(Set<ISecurityContextFactory> securityContextFactories); @Override void afterPropertiesSet(); void setLoginPath(String loginPath); void setLogoutPath(String logoutPath); @Override void doFilter(ServletRequest request, ServletResponse response, FilterChain chain); @Override void setApplicationEventPublisher(
            ApplicationEventPublisher anApplicationEventPublisher);  }