org.apache.shiro.util.ThreadContext.remove()方法的使用及代码示例

x33g5p2x  于2022-01-29 转载在 其他  
字(5.7k)|赞(0)|评价(0)|浏览(171)

本文整理了Java中org.apache.shiro.util.ThreadContext.remove()方法的一些代码示例,展示了ThreadContext.remove()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。ThreadContext.remove()方法的具体详情如下:
包路径:org.apache.shiro.util.ThreadContext
类名称:ThreadContext
方法名:remove

ThreadContext.remove介绍

[英]ThreadLocal#removes the underlying ThreadLocal from the thread.

This method is meant to be the final 'clean up' operation that is called at the end of thread execution to prevent thread corruption in pooled thread environments.
[中]ThreadLocal#从线程中删除底层ThreadLocal。
此方法是在线程执行结束时调用的最终“清理”操作,以防止池线程环境中的线程损坏。

代码示例

代码示例来源:origin: apache/shiro

/**
   * Completely {@link ThreadContext#remove removes} the {@code ThreadContext} state.  Typically this method should
   * only be called in special cases - it is more 'correct' to {@link #restore restore} a thread to its previous
   * state than to clear it entirely.
   */
  public void clear() {
    ThreadContext.remove();
  }
}

代码示例来源:origin: apache/shiro

/**
 * Convenience method that simplifies removal of the application's SecurityManager instance from the thread.
 * <p/>
 * The implementation just helps reduce casting and remembering of the ThreadContext key name, i.e it is
 * merely a convenient wrapper for the following:
 * <p/>
 * <code>return (SecurityManager)remove( SECURITY_MANAGER_KEY );</code>
 * <p/>
 * If you wish to just retrieve the object from the thread without removing it (so it can be retrieved later
 * during thread execution), use the {@link #getSecurityManager() getSecurityManager()} method instead.
 *
 * @return the application's SecurityManager instance previously bound to the thread, or <tt>null</tt> if there
 *         was none bound.
 * @since 0.9
 */
public static SecurityManager unbindSecurityManager() {
  return (SecurityManager) remove(SECURITY_MANAGER_KEY);
}

代码示例来源:origin: apache/shiro

/**
 * Convenience method that simplifies removal of a thread-local Subject from the thread.
 * <p/>
 * The implementation just helps reduce casting and remembering of the ThreadContext key name, i.e it is
 * merely a convenient wrapper for the following:
 * <p/>
 * <code>return (Subject)remove( SUBJECT_KEY );</code>
 * <p/>
 * If you wish to just retrieve the object from the thread without removing it (so it can be retrieved later during
 * thread execution), you should use the {@link #getSubject() getSubject()} method for that purpose.
 *
 * @return the Subject object previously bound to the thread, or <tt>null</tt> if there was none bound.
 * @since 0.2
 */
public static Subject unbindSubject() {
  return (Subject) remove(SUBJECT_KEY);
}

代码示例来源:origin: apache/shiro

/**
 * {@link ThreadContext#remove Remove}s all thread-state that was bound by this instance.  If any previous
 * thread-bound resources existed prior to the {@link #bind bind} call, they are restored back to the
 * {@code ThreadContext} to ensure the thread state is exactly as it was before binding.
 */
public void restore() {
  ThreadContext.remove();
  if (!CollectionUtils.isEmpty(this.originalResources)) {
    ThreadContext.setResources(this.originalResources);
  }
}

代码示例来源:origin: apache/shiro

@Before
public void setUp() {
  ThreadContext.remove();
}

代码示例来源:origin: apache/shiro

@After
  public void teardown() {
    ThreadContext.remove();
  }
}

代码示例来源:origin: apache/shiro

@After
public void tearDown() {
  ThreadContext.remove();
}

代码示例来源:origin: apache/shiro

@Before
public void setup() {
  ThreadContext.remove();
}

代码示例来源:origin: apache/shiro

@After
public void tearDown() {
  ThreadContext.remove();
}

代码示例来源:origin: apache/shiro

@After
public void tearDown() {
  ThreadContext.remove();
}

代码示例来源:origin: apache/geode

@Override
public void close() {
 if (this.securityManager != null) {
  this.securityManager.close();
 }
 if (this.postProcessor != null) {
  this.postProcessor.close();
 }
 ThreadContext.remove();
 SecurityUtils.setSecurityManager(null);
}

代码示例来源:origin: apache/geode

@Override
public void logout() {
 Subject currentUser = getSubject();
 try {
  logger.debug("Logging out " + currentUser.getPrincipal());
  currentUser.logout();
 } catch (ShiroException e) {
  logger.info("error logging out: " + currentUser.getPrincipal());
  throw new GemFireSecurityException(e.getMessage(), e);
 }
 // clean out Shiro's thread local content
 ThreadContext.remove();
}

代码示例来源:origin: apache/shiro

@After
public void tearDown() {
  sm.destroy();
  ThreadContext.remove();
}

代码示例来源:origin: apache/shiro

@Before
public void setup() {
  ThreadContext.remove();
  sm = new DefaultSessionManager();
}

代码示例来源:origin: apache/shiro

@After
public void tearDown() {
  sm.destroy();
  ThreadContext.remove();
}

代码示例来源:origin: apache/shiro

@After
public void tearDown() {
  SecurityUtils.setSecurityManager(null);
  securityManager.destroy();
  ThreadContext.remove();
}

代码示例来源:origin: apache/shiro

@Before
public void setup() {
  ThreadContext.remove();
  realm = new TestActiveDirectoryRealm();
  securityManager = new DefaultSecurityManager(realm);
  SecurityUtils.setSecurityManager(securityManager);
}

代码示例来源:origin: apache/shiro

@After
public void tearDown() {
  final String testName = name.getMethodName();
  shutDown(testName);
  SecurityUtils.setSecurityManager(null);
  securityManager.destroy();
  ThreadContext.remove();
}

代码示例来源:origin: apache/shiro

@Before
public void setup() {
  ThreadContext.remove();
  sm = new DefaultSessionManager();
  this.session = new DelegatingSession(sm, new DefaultSessionKey(sm.start(null).getId()));
}

代码示例来源:origin: apache/shiro

@Before
public void setup() {
  ThreadContext.remove();
  Ini config = new Ini();
  config.setSectionProperty("main", "myRealm", "org.apache.shiro.realm.jdbc.JdbcRealm");
  config.setSectionProperty("main", "myRealmCredentialsMatcher", "org.apache.shiro.authc.credential.Sha256CredentialsMatcher");
  config.setSectionProperty("main", "myRealm.credentialsMatcher", "$myRealmCredentialsMatcher");
  config.setSectionProperty("main", "securityManager.sessionManager.sessionValidationSchedulerEnabled", "false");
  
  IniSecurityManagerFactory factory = new IniSecurityManagerFactory(config);
  securityManager = (DefaultSecurityManager) factory.createInstance();
  SecurityUtils.setSecurityManager(securityManager);
  
  // Create a database and realm for the test
  createRealm(name.getMethodName()); 
}

相关文章