java.security.AccessController.getContext()方法的使用及代码示例

x33g5p2x  于2022-01-15 转载在 其他  
字(6.6k)|赞(0)|评价(0)|浏览(156)

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

AccessController.getContext介绍

[英]This method takes a "snapshot" of the current calling context, which includes the current Thread's inherited AccessControlContext, and places it in an AccessControlContext object. This context may then be checked at a later point, possibly in another thread.
[中]此方法获取当前调用上下文的“快照”,其中包括当前线程继承的AccessControlContext,并将其放置在AccessControlContext对象中。然后可能会在稍后的某个点(可能是在另一个线程中)检查此上下文。

代码示例

代码示例来源:origin: spring-projects/spring-framework

/**
 * Return the security context for this bean factory. If a security manager
 * is set, interaction with the user code will be executed using the privileged
 * of the security context returned by this method.
 * @see AccessController#getContext()
 */
protected AccessControlContext getAccessControlContext() {
  return AccessController.getContext();
}

代码示例来源:origin: spring-projects/spring-framework

@Override
public AccessControlContext getAccessControlContext() {
  return (this.acc != null ? this.acc : AccessController.getContext());
}

代码示例来源:origin: org.springframework/spring-beans

/**
 * Return the security context for this bean factory. If a security manager
 * is set, interaction with the user code will be executed using the privileged
 * of the security context returned by this method.
 * @see AccessController#getContext()
 */
protected AccessControlContext getAccessControlContext() {
  return AccessController.getContext();
}

代码示例来源:origin: org.springframework/spring-beans

@Override
public AccessControlContext getAccessControlContext() {
  return (this.acc != null ? this.acc : AccessController.getContext());
}

代码示例来源:origin: wildfly/wildfly

public ServiceLoaderSupplier(final Class<E> service, final ClassLoader classLoader) {
  this.service = service;
  this.classLoader = classLoader;
  this.acc = AccessController.getContext() ;
}

代码示例来源:origin: wildfly/wildfly

/**
 * Construct a new instance of {@code PrivilegedServerMechanismFactory} using the current {@link AccessControlContext} for
 * calls to the wrapped factory
 *
 * @param delegate the {@link HttpServerAuthenticationMechanismFactory} to delegate to.
 */
public PrivilegedServerMechanismFactory(final HttpServerAuthenticationMechanismFactory delegate) {
  this(delegate, AccessController.getContext());
}

代码示例来源:origin: wildfly/wildfly

/**
 * Construct a new instance.
 *
 * @param delegate the delegate SASL client factory
 */
public PrivilegedSaslClientFactory(final SaslClientFactory delegate) {
  this(delegate, AccessController.getContext());
}

代码示例来源:origin: wildfly/wildfly

/**
 * Construct a new instance.
 *
 * @param delegate the delegate SASL server factory
 */
public PrivilegedSaslServerFactory(final SaslServerFactory delegate) {
  this(delegate, AccessController.getContext());
}

代码示例来源:origin: spring-projects/spring-framework

/**
 * Delegate the creation of the access control context to the
 * {@link #setSecurityContextProvider SecurityContextProvider}.
 */
@Override
public AccessControlContext getAccessControlContext() {
  return (this.securityContextProvider != null ?
      this.securityContextProvider.getAccessControlContext() :
      AccessController.getContext());
}

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

@Override
  public Subject run() {
    return Subject.getSubject(AccessController.getContext());
  }
});

代码示例来源:origin: alibaba/jstorm

@Override
  protected ReqContext initialValue() {
    return new ReqContext(AccessController.getContext());
  }
};

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

private void handleCallback(OAuthBearerTokenCallback callback) throws IOException {
  if (callback.token() != null)
    throw new IllegalArgumentException("Callback had a token already");
  Subject subject = Subject.getSubject(AccessController.getContext());
  Set<OAuthBearerToken> privateCredentials = subject != null
    ? subject.getPrivateCredentials(OAuthBearerToken.class)
    : Collections.emptySet();
  if (privateCredentials.size() != 1)
    throw new IOException(
        String.format("Unable to find OAuth Bearer token in Subject's private credentials (size=%d)",
            privateCredentials.size()));
  callback.token(privateCredentials.iterator().next());
}

代码示例来源:origin: org.springframework/spring-beans

/**
 * Delegate the creation of the access control context to the
 * {@link #setSecurityContextProvider SecurityContextProvider}.
 */
@Override
public AccessControlContext getAccessControlContext() {
  return (this.securityContextProvider != null ?
      this.securityContextProvider.getAccessControlContext() :
      AccessController.getContext());
}

代码示例来源:origin: wildfly/wildfly

/**
 * Perform a permission check.
 *
 * @param perm the permission to check
 * @throws SecurityException if the check fails
 */
public void checkPermission(final Permission perm) throws SecurityException {
  checkPermission(perm, AccessController.getContext());
}

代码示例来源:origin: wildfly/wildfly

CommandCredentialSource(final Builder builder) throws GeneralSecurityException {
  builderProcessor = builder.builderProcessor;
  this.passwordFactory = builder.passwordFactoryFactory.create();
  context = AccessController.getContext();
  outputCharset = builder.outputCharset;
}

代码示例来源:origin: wildfly/wildfly

/**
 * Create a new configuration which is the same as this configuration, but which captures the caller's access
 * control context to be used in authentication decisions.
 *
 * @return the new configuration
 */
public AuthenticationConfiguration withCapturedAccessControlContext() {
  return new AuthenticationConfiguration(this, SET_ACCESS_CTXT, getContext());
}

代码示例来源:origin: spring-projects/spring-framework

private static String getCurrentSubjectName() {
  final AccessControlContext acc = AccessController.getContext();
  return AccessController.doPrivileged(new PrivilegedAction<String>() {
    @Override
    public String run() {
      Subject subject = Subject.getSubject(acc);
      if (subject == null) {
        return null;
      }
      Set<Principal> principals = subject.getPrincipals();
      if (principals == null) {
        return null;
      }
      for (Principal p : principals) {
        return p.getName();
      }
      return null;
    }
  });
}

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

@Override
public void handle(Callback[] callbacks) throws IOException, UnsupportedCallbackException {
  if (!configured())
    throw new IllegalStateException("Callback handler not configured");
  for (Callback callback : callbacks) {
    if (callback instanceof OAuthBearerTokenCallback)
      handleCallback((OAuthBearerTokenCallback) callback);
    else if (callback instanceof SaslExtensionsCallback)
      handleCallback((SaslExtensionsCallback) callback, Subject.getSubject(AccessController.getContext()));
    else
      throw new UnsupportedCallbackException(callback);
  }
}

代码示例来源:origin: spring-projects/spring-framework

public void init() {
  AccessControlContext acc = AccessController.getContext();
  Subject subject = Subject.getSubject(acc);
  if (subject == null) {
    return;
  }
  setNameFromPrincipal(subject.getPrincipals());
}

代码示例来源:origin: spring-projects/spring-security

@GetMapping("/username")
  public String username() {
    Subject subject = Subject.getSubject(AccessController.getContext());
    return subject.getPrincipals().iterator().next().getName();
  }
}

相关文章

微信公众号

最新文章

更多