クラス ListeningSecurityContextHolderStrategy
java.lang.ObjectSE
org.springframework.security.core.context.ListeningSecurityContextHolderStrategy
- 実装されたすべてのインターフェース:
SecurityContextHolderStrategy
public final class ListeningSecurityContextHolderStrategy
extends ObjectSE
implements SecurityContextHolderStrategy
SecurityContext
が変更されたときに通知するための API。これは、基礎となる認証が変更されたときに通知されないことに注意してください。認証の変更に関する通知を受け取るには、次のように認証を変更するときに setContext(org.springframework.security.core.context.SecurityContext)
を使用していることを確認してください。SecurityContext context = SecurityContextHolder.createEmptyContext(); context.setAuthentication(authentication); SecurityContextHolder.setContext(context);既存の
SecurityContextHolder
にリスナーを追加するには、次のようにします。SecurityContextHolderStrategy original = SecurityContextHolder.getContextHolderStrategy(); SecurityContextChangedListener listener = new YourListener(); SecurityContextHolderStrategy strategy = new ListeningSecurityContextHolderStrategy(original, listener); SecurityContextHolder.setContextHolderStrategy(strategy);NOTE:
SecurityContextHolder
に提供するオブジェクトはすべて静的コンテキストの一部になり、ガベージコレクションは行われません。参照を削除するには、reset the strategy
は次のようになります。SecurityContextHolder.setContextHolderStrategy(original);これにより、
YourListener
とそのメンバーをガベージコレクションできるようになります。- 導入:
- 5.6
コンストラクターのサマリー
コンストラクターコンストラクター説明ThreadLocalSecurityContextHolderStrategy
に基づいてListeningSecurityContextHolderStrategy
を構築しますThreadLocalSecurityContextHolderStrategy
に基づいてListeningSecurityContextHolderStrategy
を構築しますListeningSecurityContextHolderStrategy
(SecurityContextHolderStrategy delegate, CollectionSE<SecurityContextChangedListener> listeners) ListeningSecurityContextHolderStrategy
(SecurityContextHolderStrategy delegate, SecurityContextChangedListener... listeners) メソッドのサマリー
修飾子と型メソッド説明void
現在のコンテキストをクリアします。初めて新しいコンテキストを作成するときに、 SecurityContextRepository 実装で使用するために、新しい空のコンテキスト実装を作成します。現在のコンテキストを取得します。現在のコンテキストを返すSupplier
SE を取得します。void
setContext
(SecurityContext context) 現在のコンテキストを設定します。void
setDeferredContext
(SupplierSE<SecurityContext> deferredContext) 現在のコンテキストを返すSupplier
SE を設定します。
コンストラクターの詳細
ListeningSecurityContextHolderStrategy
public ListeningSecurityContextHolderStrategy(CollectionSE<SecurityContextChangedListener> listeners) ThreadLocalSecurityContextHolderStrategy
に基づいてListeningSecurityContextHolderStrategy
を構築します- パラメーター:
listeners
-SecurityContext
がset
またはcleared
のときに通知する必要があるリスナー- 導入:
- 5.7
ListeningSecurityContextHolderStrategy
ThreadLocalSecurityContextHolderStrategy
に基づいてListeningSecurityContextHolderStrategy
を構築します- パラメーター:
listeners
-SecurityContext
がset
またはcleared
のときに通知する必要があるリスナー- 導入:
- 5.7
ListeningSecurityContextHolderStrategy
public ListeningSecurityContextHolderStrategy(SecurityContextHolderStrategy delegate, CollectionSE<SecurityContextChangedListener> listeners) - パラメーター:
listeners
-SecurityContext
がset
またはcleared
のときに通知する必要があるリスナーdelegate
- 基礎となるSecurityContextHolderStrategy
ListeningSecurityContextHolderStrategy
public ListeningSecurityContextHolderStrategy(SecurityContextHolderStrategy delegate, SecurityContextChangedListener... listeners) - パラメーター:
listeners
-SecurityContext
がset
またはcleared
のときに通知する必要があるリスナーdelegate
- 基礎となるSecurityContextHolderStrategy
メソッドの詳細
clearContext
public void clearContext()現在のコンテキストをクリアします。- 次で指定:
- インターフェース
SecurityContextHolderStrategy
のclearContext
getContext
現在のコンテキストを取得します。- 次で指定:
- インターフェース
SecurityContextHolderStrategy
のgetContext
- 戻り値:
- コンテキスト (
null
になることはありません - 必要に応じてデフォルトの実装を作成します)
getDeferredContext
現在のコンテキストを返すSupplier
SE を取得します。- 次で指定:
- インターフェース
SecurityContextHolderStrategy
のgetDeferredContext
- 戻り値:
- 現在のコンテキストを返す
Supplier
SE (決してnull
- 必要に応じてデフォルトの実装を作成します)
setContext
現在のコンテキストを設定します。- 次で指定:
- インターフェース
SecurityContextHolderStrategy
のsetContext
- パラメーター:
context
- 新しい引数に (null
にしないでください。実装では、null
が渡されたかどうかを確認し、そのような場合はIllegalArgumentException
をスローする必要があります。)
setDeferredContext
現在のコンテキストを返すSupplier
SE を設定します。実装は、デフォルトをオーバーライドして、Supplier.get()
の呼び出しを回避できます。- 次で指定:
- インターフェース
SecurityContextHolderStrategy
のsetDeferredContext
- パラメーター:
deferredContext
-SecurityContext
を返すSupplier
SE
createEmptyContext
初めて新しいコンテキストを作成するときに、 SecurityContextRepository 実装で使用するために、新しい空のコンテキスト実装を作成します。- 次で指定:
- インターフェース
SecurityContextHolderStrategy
のcreateEmptyContext
- 戻り値:
- 空のコンテキスト。