Class SecurityContextAwareExecutionListener

java.lang.Object
org.zkoss.spring.init.SecurityContextAwareExecutionListener
All Implemented Interfaces:
org.zkoss.zk.ui.util.ExecutionCleanup, org.zkoss.zk.ui.util.ExecutionInit

public class SecurityContextAwareExecutionListener extends Object implements org.zkoss.zk.ui.util.ExecutionInit, org.zkoss.zk.ui.util.ExecutionCleanup
ZK Listener to fill/cleanup Springs SecurityContextHolder for executions outside Spring's security filter chain. e.g. Websocket requests or executions activated from background threads (server push / eventqueues / manual activation).

This implementation will retrieve the current SecurityContext stored in the Http Session using Spring's default attribute name HttpSessionSecurityContextRepository.SPRING_SECURITY_CONTEXT_KEY
The listener can be enabled/disabled via the library property 'org.zkoss.spring.init.SecurityContextAwareExecutionListener.enabled'.
After disabling a custom implementation can be provided e.g. by overriding the loadSecurityContext(Execution) method.
Since:
4.0.0
Author:
Robert
See Also:
  • Constructor Details

    • SecurityContextAwareExecutionListener

      public SecurityContextAwareExecutionListener()
  • Method Details

    • init

      public void init(org.zkoss.zk.ui.Execution exec, org.zkoss.zk.ui.Execution parent) throws Exception
      Specified by:
      init in interface org.zkoss.zk.ui.util.ExecutionInit
      Throws:
      Exception
    • cleanup

      public void cleanup(org.zkoss.zk.ui.Execution exec, org.zkoss.zk.ui.Execution parent, List<Throwable> errs) throws Exception
      Specified by:
      cleanup in interface org.zkoss.zk.ui.util.ExecutionCleanup
      Throws:
      Exception
    • loadSecurityContext

      protected org.springframework.security.core.context.SecurityContext loadSecurityContext(org.zkoss.zk.ui.Execution execution)
      Retrieve the current SecurityContext from the session associated with the given execution
      Parameters:
      execution - the current execution
      Returns:
      a SecurityContext or null