クラス ListeningSecurityContextHolderStrategy

  • 実装されたすべてのインターフェース:
    SecurityContextHolderStrategy

    public final class ListeningSecurityContextHolderStrategy
    extends java.lang.Object
    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