Package org.springframework.security.core.context

# Class SecurityContextChangedEvent

java.lang.Object
java.util.EventObject
org.springframework.context.ApplicationEvent
org.springframework.security.core.context.SecurityContextChangedEvent

All Implemented Interfaces:
  `Serializable`

public class SecurityContextChangedEvent extends org.springframework.context.ApplicationEvent
An event that represents a change in `SecurityContext`

Since:
  5.6
See Also:
  - Serialized Form

## Field Summary

Fields
Modifier and Type
Field
Description
`static final Supplier<SecurityContext>`
`NO_CONTEXT`

### Fields inherited from class java.util.EventObject

`source`

## Constructor Summary

Constructors
Constructor
Description
`SecurityContextChangedEvent(Supplier<SecurityContext> oldContext, Supplier<SecurityContext> newContext)`
Construct an event
`SecurityContextChangedEvent(SecurityContext oldContext, SecurityContext newContext)`
Construct an event

## Method Summary

Modifier and Type
Method
Description
`SecurityContext`
`getNewContext()`
Get the `SecurityContext` set on the `SecurityContextHolder` as of this event
`SecurityContext`
`getOldContext()`
Get the `SecurityContext` set on the `SecurityContextHolder` immediately previous to this event
`boolean`
`isCleared()`
Say whether the event is a context-clearing event.

### Methods inherited from class org.springframework.context.ApplicationEvent

`getTimestamp`

### Methods inherited from class java.util.EventObject

`getSource, toString`

### Methods inherited from class java.lang.Object

`clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait`

## Field Details

### NO_CONTEXT

public static final Supplier<SecurityContext> NO_CONTEXT

## Constructor Details

### SecurityContextChangedEvent

public SecurityContextChangedEvent(Supplier<SecurityContext> oldContext, Supplier<SecurityContext> newContext)
Construct an event

Parameters:
  `oldContext` - the old security context
  `newContext` - the new security context, use `NO_CONTEXT` for if the context is cleared
Since:
  5.8

### SecurityContextChangedEvent

public SecurityContextChangedEvent(SecurityContext oldContext, SecurityContext newContext)
Construct an event

Parameters:
  `oldContext` - the old security context
  `newContext` - the new security context

## Method Details

### getOldContext

public SecurityContext getOldContext()
Get the `SecurityContext` set on the `SecurityContextHolder` immediately previous to this event

Returns:
  the previous `SecurityContext`

### getNewContext

public SecurityContext getNewContext()
Get the `SecurityContext` set on the `SecurityContextHolder` as of this event

Returns:
  the current `SecurityContext`

### isCleared

public boolean isCleared()
Say whether the event is a context-clearing event.

This method is handy for avoiding looking up the new context to confirm it is a cleared event.

Returns:
  `true` if the new context is `NO_CONTEXT`
Since:
  5.8