org.apache.shiro.subject.Subject.associateWith()方法的使用及代码示例

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

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

Subject.associateWith介绍

[英]Returns a Runnable instance matching the given argument while additionally ensuring that it will retain and execute under this Subject's identity. The returned object can be used with an java.util.concurrent.Executor or another thread to execute as this Subject.

This will effectively ensure that any calls to SecurityUtils. SecurityUtils#getSubject() and related functionality will continue to function properly on any thread that executes the returned Runnable instance.

*Note that if you need a return value to be returned as a result of the runnable's execution or if you need to react to any Exceptions, it is highly recommended to use the #associateWith(java.util.concurrent.Callable) method instead of this one.
[中]返回一个与给定参数匹配的可运行实例,同时还要确保该实例将以该主题的身份保留和执行。返回的对象可以与java应用程序一起使用。util。同时发生的执行器或另一个线程作为此主题执行。
这将有效地确保对SecurityUtils的任何调用。SecurityUtils#getSubject()和相关功能将继续在执行返回的可运行实例的任何线程上正常运行。
*请注意,如果需要在执行runnable时返回返回值,或者需要对任何异常做出反应,强烈建议使用#associateWith(java.util.concurrent.Callable)方法,而不是此方法。

代码示例

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

protected <T> Callable<T> associateWithSubject(Callable<T> task) {
  Subject subject = getSubject();
  return subject.associateWith(task);
}

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

/**
 * Utility method for subclasses to associate the argument {@code Runnable} with the currently executing subject
 * and then return the associated Runnable.  The default implementation merely defaults to
 * <pre>
 * Subject subject = {@link #getSubject() getSubject()};
 * return subject.{@link Subject#associateWith(Runnable) associateWith(r)};
 * </pre>
 *
 * @param r the argument runnable to be associated with the current subject
 * @return the associated runnable instance reflecting the current subject
 */
protected Runnable associateWithSubject(Runnable r) {
  Subject subject = getSubject();
  return subject.associateWith(r);
}

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

@Override
public Callable associateWith(final Callable callable) {
 Subject currentUser = getSubject();
 return currentUser.associateWith(callable);
}

代码示例来源:origin: org.apache.shiro/shiro-core

protected <T> Callable<T> associateWithSubject(Callable<T> task) {
  Subject subject = getSubject();
  return subject.associateWith(task);
}

代码示例来源:origin: org.apache.shiro/shiro-core

/**
 * Utility method for subclasses to associate the argument {@code Runnable} with the currently executing subject
 * and then return the associated Runnable.  The default implementation merely defaults to
 * <pre>
 * Subject subject = {@link #getSubject() getSubject()};
 * return subject.{@link Subject#associateWith(Runnable) associateWith(r)};
 * </pre>
 *
 * @param r the argument runnable to be associated with the current subject
 * @return the associated runnable instance reflecting the current subject
 */
protected Runnable associateWithSubject(Runnable r) {
  Subject subject = getSubject();
  return subject.associateWith(r);
}

代码示例来源:origin: org.sonatype.sisu/sisu-charger

public void addAmmo( final Callable<? extends E> callable, final ExceptionHandler exceptionHandler )
  {
    super.addAmmo( subject.associateWith( callable ), exceptionHandler );
  }
}

代码示例来源:origin: org.apache.servicemix.bundles/org.apache.servicemix.bundles.shiro

protected <T> Callable<T> associateWithSubject(Callable<T> task) {
  Subject subject = getSubject();
  return subject.associateWith(task);
}

代码示例来源:origin: org.apache.servicemix.bundles/org.apache.servicemix.bundles.shiro

/**
 * Utility method for subclasses to associate the argument {@code Runnable} with the currently executing subject
 * and then return the associated Runnable.  The default implementation merely defaults to
 * <pre>
 * Subject subject = {@link #getSubject() getSubject()};
 * return subject.{@link Subject#associateWith(Runnable) associateWith(r)};
 * </pre>
 *
 * @param r the argument runnable to be associated with the current subject
 * @return the associated runnable instance reflecting the current subject
 */
protected Runnable associateWithSubject(Runnable r) {
  Subject subject = getSubject();
  return subject.associateWith(r);
}

代码示例来源:origin: org.sonatype.nexus/nexus-thread

@Override
protected <T> Callable<T> associateWithSubject(Callable<T> task) {
 Subject subject = getSubject();
 return subject.associateWith(new MDCAwareCallable<>(task));
}

代码示例来源:origin: org.sonatype.nexus/nexus-thread

@Override
protected Runnable associateWithSubject(Runnable r) {
 Subject subject = getSubject();
 return subject.associateWith(new MDCAwareRunnable(r));
}

代码示例来源:origin: sonia.scm/scm-test

subject.associateWith(tester);
new Thread(tester).start();

相关文章