クラス 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 実装で使用するために、新しい空のコンテキスト実装を作成します。現在のコンテキストを取得します。現在のコンテキストを返すSupplierSE を取得します。voidsetContext(SecurityContext context) 現在のコンテキストを設定します。voidsetDeferredContext(SupplierSE<SecurityContext> deferredContext) 現在のコンテキストを返すSupplierSE を設定します。
コンストラクターの詳細
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
現在のコンテキストを返すSupplierSE を取得します。- 次で指定:
- インターフェース
SecurityContextHolderStrategyのgetDeferredContext - 戻り値:
- 現在のコンテキストを返す
SupplierSE (決してnull- 必要に応じてデフォルトの実装を作成します)
setContext
現在のコンテキストを設定します。- 次で指定:
- インターフェース
SecurityContextHolderStrategyのsetContext - パラメーター:
context- 新しい引数に (nullにしないでください。実装では、nullが渡されたかどうかを確認し、そのような場合はIllegalArgumentExceptionをスローする必要があります。)
setDeferredContext
現在のコンテキストを返すSupplierSE を設定します。実装は、デフォルトをオーバーライドして、Supplier.get()の呼び出しを回避できます。- 次で指定:
- インターフェース
SecurityContextHolderStrategyのsetDeferredContext - パラメーター:
deferredContext-SecurityContextを返すSupplierSE
createEmptyContext
初めて新しいコンテキストを作成するときに、 SecurityContextRepository 実装で使用するために、新しい空のコンテキスト実装を作成します。- 次で指定:
- インターフェース
SecurityContextHolderStrategyのcreateEmptyContext - 戻り値:
- 空のコンテキスト。