privatevoidbindToThread() { // Expose current TransactionStatus, preserving any existing TransactionStatus // for restoration after this transaction is complete. this.oldTransactionInfo = transactionInfoHolder.get(); transactionInfoHolder.set(this); }
privatevoidrestoreThreadLocalStatus() { // Use stack to restore old transaction TransactionInfo. // Will be null if none was set. transactionInfoHolder.set(this.oldTransactionInfo); }
/** * Explicitly clears the context value from the current thread. */ publicstaticvoidclearContext() { strategy.clearContext(); }
/** * Obtain the current <code>SecurityContext</code>. * * @return the security context (never <code>null</code>) */ publicstatic SecurityContext getContext() { return strategy.getContext(); }
/** * Primarily for troubleshooting purposes, this method shows how many times the class * has re-initialized its <code>SecurityContextHolderStrategy</code>. * * @return the count (should be one unless you've called * {@link #setStrategyName(String)} to switch to an alternate strategy. */ publicstaticintgetInitializeCount() { return initializeCount; }
privatestaticvoidinitialize() { if (!StringUtils.hasText(strategyName)) { // Set default strategyName = MODE_THREADLOCAL; }
/** * Associates a new <code>SecurityContext</code> with the current thread of execution. * * @param context the new <code>SecurityContext</code> (may not be <code>null</code>) */ publicstaticvoidsetContext(SecurityContext context) { strategy.setContext(context); }
/** * Changes the preferred strategy. Do <em>NOT</em> call this method more than once for * a given JVM, as it will re-initialize the strategy and adversely affect any * existing threads using the old strategy. * * @param strategyName the fully qualified class name of the strategy that should be * used. */ publicstaticvoidsetStrategyName(String strategyName) { SecurityContextHolder.strategyName = strategyName; initialize(); }
/** * Allows retrieval of the context strategy. See SEC-1188. * * @return the configured strategy for storing the security context. */ publicstatic SecurityContextHolderStrategy getContextHolderStrategy() { return strategy; }
/** * Delegates the creation of a new, empty context to the configured strategy. */ publicstatic SecurityContext createEmptyContext() { return strategy.createEmptyContext(); }
/** * Create a new NamedThreadLocal with the given name. * @param name a descriptive name for this ThreadLocal */ publicNamedThreadLocal(String name) { Assert.hasText(name, "Name must not be empty"); this.name = name; }
@Override public String toString() { returnthis.name; }