Class ThreadLocalSubjectStore

java.lang.Object
com.svenruppert.jsentinel.standalone.ThreadLocalSubjectStore
All Implemented Interfaces:
com.svenruppert.jsentinel.authorization.api.SubjectStore

public final class ThreadLocalSubjectStore extends Object implements com.svenruppert.jsentinel.authorization.api.SubjectStore
SubjectStore that keeps the current subject in a thread-local map keyed by subject class. The default for standalone (single-user desktop / CLI) applications.

Background-thread propagation is the caller's responsibility: pass the subject (or a Runnable wrapper that re-binds it) when handing work off to executors, JavaFX Tasks, etc. The store does not inherit across threads — by design, so a fork of a JVM process never silently leaks a security context.

  • Constructor Details

    • ThreadLocalSubjectStore

      public ThreadLocalSubjectStore()
      Creates an empty store. Registered via META-INF/services.
  • Method Details

    • currentSubject

      public <T> Optional<T> currentSubject(Class<T> subjectType)
      Specified by:
      currentSubject in interface com.svenruppert.jsentinel.authorization.api.SubjectStore
    • setCurrentSubject

      public <T> void setCurrentSubject(T subject, Class<T> subjectType)
      Specified by:
      setCurrentSubject in interface com.svenruppert.jsentinel.authorization.api.SubjectStore
    • deleteCurrentSubject

      public <T> void deleteCurrentSubject(Class<T> subjectType)
      Specified by:
      deleteCurrentSubject in interface com.svenruppert.jsentinel.authorization.api.SubjectStore
    • clear

      public void clear()
      Clears every binding on the current thread. Intended for tests and for application shutdown paths.