javax.security.auth.message.config.AuthConfigFactory类的使用及代码示例

x33g5p2x  于2022-01-16 转载在 其他  
字(12.8k)|赞(0)|评价(0)|浏览(218)

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

AuthConfigFactory介绍

[英]This class is used to obtain AuthConfigProvider objects that can be used to obtain authentication context configuration objects, i.e., ClientAuthConfig and ServerAuthConfig objects.

Authentication context configuration objects are used to obtain authentication context objects. Authentication context objects, that is, ClientAuthContext and ServerAuthContex objects, encapsulate authentication modules. Authentication modules are pluggable components that perform security-related processing of request and response messages.

Callers do not operate on modules directly. Instead they rely on an authentication context to manage the invocation of modules. A caller obtains an authentication context by calling the getAuthContext method on a ClientAuthConfig or ServerAuthConfig obtained from an AuthConfigProvider.

The following represents a typical sequence of calls for obtaining a client authentication context, and then using it to secure a request.

  1. AuthConfigFactory factory = AuthConfigFactory.getFactory();
  2. AuthConfigProvider provider = factory.getConfigProvider(layer,appID,listener);
  3. ClientAuthConfig config = provider.getClientAuthConfig(layer,appID,cbh)
  4. String authContextID = config.getAuthContextID(messageInfo);
  5. ClientAuthContext context = config.getAuthContext(authContextID,subject,properties);
  6. context.secureRequest(messageInfo,subject);

A system-wide AuthConfigFactory implementation can be set by invoking setFactory, and retrieved via getFactory.

Every implementation of this abstract class must offer a public, zero argument constructor. This constructor must support the construction and registration (including self-registration) of AuthConfigProviders from a persistent declarative representation.

For example, a factory implementation class could interpret the contents of a file containing a sequence of configuration entries, with one entry per AuthConfigProvider, with each entry representing:

  • The fully qualified name of the provider implementation class (or null)
  • The list of the provider initialization properties (which could be empty)

Any provider initialization properties must be specified in a form that can be passed to the provider constructor within a Map of key, value pairs, and where all keys and values within the Map are of type String.

The entry syntax must also provide for the optional inclusion of information sufficient to define a RegistrationContext. This information would only be present when the factory will register the provider. For example, each entry could provide for the inclusion of one or more RegistrationContext objects of the following form:

  • The message layer name (or null)
  • The application context identifier (or null)
  • The registration description (or null)

When a RegistrationContext is not included, the factory must make it convenient for the provider to self-register with the factory during the provider construction (see registerConfigProvider(AuthConfigProvider provider, ...)).

An AuthConfigFactory implementation is free to choose is own persistent declarative syntax as long as it conforms to the requirements defined by this class.
[中]此类用于获取可用于获取身份验证上下文配置对象的AuthConfigProvider对象,即ClientAuthConfig和ServerAuthConfig对象。
身份验证上下文配置对象用于获取身份验证上下文对象。身份验证上下文对象,即ClientAuthContext和ServerAuthContex对象,封装了身份验证模块。身份验证模块是可插拔组件,用于执行请求和响应消息的安全相关处理。
呼叫者不直接操作模块。相反,它们依赖身份验证上下文来管理模块的调用。调用者通过调用从AuthConfigProvider获取的ClientAuthConfig或ServerAuthConfig上的getAuthContext方法来获取身份验证上下文。
下面是一个典型的调用序列,用于获取客户端身份验证上下文,然后使用它来保护请求。
1.AuthConfigFactory工厂=AuthConfigFactory。getFactory();
1.AuthConfigProvider提供程序=工厂。getConfigProvider(层、appID、侦听器);
1.ClientAuthConfig=provider。getClientAuthConfig(层、appID、cbh)
1.字符串authContextID=config。getAuthContextID(messageInfo);
1.ClientAuthContext=config。getAuthContext(authContextID、主题、属性);
1.背景。secureRequest(messageInfo,主题);
可以通过调用setFactory设置系统范围的AuthConfigFactory实现,并通过getFactory检索。
这个抽象类的每个实现都必须提供一个公共的零参数构造函数。此构造函数必须支持从持久声明性表示构建和注册AuthConfigProviders(包括自注册)。
例如,factory实现类可以解释包含一系列配置条目的文件内容,每个AuthConfigProvider有一个条目,每个条目表示:
*提供程序实现类的完全限定名(或null)
*提供程序初始化属性的列表(可以为空)
任何提供程序初始化属性都必须以可以传递给键、值对映射中的提供程序构造函数的形式指定,其中映射中的所有键和值都是字符串类型。
条目语法还必须提供足够定义RegistrationContext的信息的可选包含。此信息仅在工厂注册供应商时出现。例如,每个条目都可以包含以下形式的一个或多个RegistrationContext对象:
*消息层名称(或null)
*应用程序上下文标识符(或null)
*注册说明(或空)
如果未包含RegistrationContext,则工厂必须使提供程序在构造提供程序期间能够方便地向工厂进行自注册(请参阅registerConfigProvider(AuthConfigProvider provider,…)。
AuthConfigFactory实现可以自由选择自己的持久声明性语法,只要它符合此类定义的要求。

代码示例

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

/**
 * <p>
 * JASPIC 1.1 specification: if there is an {@code AuthConfigProvider} for the {@code HttpServlet} layer and
 * application context, then @{@code login} must throw a {@code ServletException} which may convey that the
 * exception was caused by an incompatibility between the {@code login} method and the configured authentication
 * mechanism. If there is no such provider, then the container must proceed with the regular {@code login} processing.
 * </p>
 *
 * @param username The username
 * @param password The password
 * @return <code>true</code> if the login succeeded, false otherwise
 * @throws SecurityException if login is called when JASPIC is enabled for application context and layer.
 */
@Override
public boolean login(final String username, final String password) {
  // if there is an AuthConfigProvider for the HttpServlet layer and appContext, this method must throw an exception.
  String appContext = this.buildAppContext();
  AuthConfigProvider provider = AuthConfigFactory.getFactory().getConfigProvider(layer, appContext, null);
  if (provider != null) {
    ServletException se = new ServletException("login is not supported by the JASPIC mechanism");
    throw new SecurityException(se);
  }
  return super.login(username, password);
}

代码示例来源:origin: javaee-samples/javaee7-samples

/**
 * Registers the given SAM using the standard JASPIC {@link AuthConfigFactory} but using a small set of wrappers that just
 * pass the calls through to the SAM.
 * 
 * @param serverAuthModule
 */
public static void registerSAM(ServletContext context, ServerAuthModule serverAuthModule) {
  AuthConfigFactory.getFactory().registerConfigProvider(new TestAuthConfigProvider(serverAuthModule), "HttpServlet",
    getAppContextID(context), "Test authentication config provider");
}

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

@Override
public boolean removeRegistration(String registrationID) {
  return elytronAuthConfigFactory.removeRegistration(registrationID) || backupAuthConfigFactory.removeRegistration(registrationID);
}

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

/**
 * Register the assembled configuration against the system wide {@link AuthConfigFactory}.
 *
 * @return The registration ID returned by the factory on registration.
 * @throws IllegalStateException if the configuration has already been registered.
 */
public String register() {
  return register(AuthConfigFactory.getFactory());
}

代码示例来源:origin: org.glassfish.soteria/javax.security.enterprise

public Boolean run() {
    return AuthConfigFactory.getFactory().removeRegistration(registrationId);
  }
});

代码示例来源:origin: javaee-samples/javaee7-samples

/**
 * Constructor with signature and implementation that's required by API.
 * 
 * @param properties
 * @param factory
 */
public TestAuthConfigProvider(Map<String, String> properties, AuthConfigFactory factory) {
  this.providerProperties = properties;
  // API requires self registration if factory is provided. Not clear
  // where the "layer" (2nd parameter)
  // and especially "appContext" (3rd parameter) values have to come from
  // at this place.
  if (factory != null) {
    factory.registerConfigProvider(this, null, null, "Auto registration");
  }
}

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

@Override
public AuthConfigProvider getConfigProvider(String layer, String appContext, RegistrationListener listener) {
  AuthConfigProvider authConfigProvider = elytronAuthConfigFactory.getConfigProvider(layer, appContext, listener);
  if (authConfigProvider != null || elytronAuthConfigFactory.matchesRegistration(layer, appContext) || !delegationAllowed.get()) {
    return authConfigProvider;
  }
  return backupAuthConfigFactory.getConfigProvider(layer, appContext, listener);
}

代码示例来源:origin: org.glassfish.main.security/jaspic.provider.framework

HashSet<String> toBeUnregistered = new HashSet<String>();
String[] regID = getFactory().getRegistrationIDs(this);
for (String i : regID) {
  if (selfRegistered.contains(i)) {
    RegistrationContext c = getFactory().getRegistrationContext(i);
    if (c != null && !c.isPersistent()) {
      toBeUnregistered.add(i);
  RegistrationContext r = getFactory().getRegistrationContext(i);
  for (int j = 0; j < contexts.length; j++) {
    if (contextsAreEqual(contexts[j], r)) {
  getFactory().removeRegistration(i);
  String id = getFactory().registerConfigProvider(this,
      r.getMessageLayer(), r.getAppContext(),
      r.getDescription());

代码示例来源:origin: org.glassfish.security/security

/**
 * Check if there is a provider register for a given layer and appCtxt.
 */
protected boolean hasExactMatchAuthProvider() {
  boolean exactMatch = false;
  // XXX this may need to be optimized
  AuthConfigProvider p = 
      factory.getConfigProvider(layer, appCtxt, null);
  if (p != null) {
    String[] IDs = factory.getRegistrationIDs(p);
    for (String i : IDs) {
      RegistrationContext c = factory.getRegistrationContext(i);
      if (layer.equals(c.getMessageLayer()) && 
          appCtxt.equals(c.getAppContext())) {
        exactMatch = true;
        break;
      }
    }
  }
  return exactMatch;
}

代码示例来源:origin: org.fabric3/fabric3-binding-ws-metro

public Object run() {
    /*String defaultFactory = Security.getProperty(AuthConfigFactory.DEFAULT_FACTORY_SECURITY_PROPERTY);
    if (defaultFactory == null || !(JMACAuthConfigFactory.class.getName().equals(defaultFactory))) {
    Security.setProperty(AuthConfigFactory.DEFAULT_FACTORY_SECURITY_PROPERTY,
    JMACAuthConfigFactory.class.getName());
    }*/
    AuthConfigFactory factory = AuthConfigFactory.getFactory();
    if (factory == null || !(factory instanceof JMACAuthConfigFactory)) {
      AuthConfigFactory.setFactory(new JMACAuthConfigFactory(loader));
    }
    return null; // nothing to return
  }
});

代码示例来源:origin: org.glassfish.main.security/security-ee

if (!layerSet.contains(layer)) {
  String regisID = layerDefaultRegisIDMap.remove(layer);
  aFactory.removeRegistration(regisID);
  String regisID = aFactory.registerConfigProvider
  (aProvider, layer, null,
"GFServerConfigProvider: self registration");

代码示例来源:origin: org.glassfish.main.security/jaspic.provider.framework

/**
 * to be called by refresh on provider subclass, and after subclass impl.
 * has reloaded its underlying configuration system.
 * Note: Spec is silent as to whether self-registrations should be reprocessed.
 */
public void oldRefresh() {
  if (getFactory() != null) {
    String[] regID = getFactory().getRegistrationIDs(this);
    for (String i : regID) {
      if (selfRegistered.contains(i)) {
        RegistrationContext c = getFactory().getRegistrationContext(i);
        if (c != null && !c.isPersistent()) {
          getFactory().removeRegistration(i);
        }
      }
    }
  }
  epochCarrier.increment();
  selfRegister();
}

代码示例来源:origin: org.apache.tomcat/tomcat-jaspic-api

public static synchronized void setFactory(AuthConfigFactory factory) {
  checkPermission(setFactorySecurityPermission);
  AuthConfigFactory.factory = factory;
}

代码示例来源:origin: org.glassfish.security/security

public void disable() {
      this.wLock.lock();
      try {
        setEnabled(false);
      } finally {
        data = null;
        this.wLock.unlock();
      }
      if (factory != null) {
        String[] ids = factory.detachListener(this.listener,layer,appCtxt);
//                if (ids != null) {
//                    for (int i=0; i < ids.length; i++) {
//                        factory.removeRegistration(ids[i]);
//                    }
//                }
        if (getJmacProviderRegisID() != null) {
          factory.removeRegistration(getJmacProviderRegisID());
        }
      }
    }

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

@Override
public RegistrationContext getRegistrationContext(String registrationID) {
  RegistrationContext registrationContext = elytronAuthConfigFactory.getRegistrationContext(registrationID);
  if (registrationContext == null) {
    registrationContext = backupAuthConfigFactory.getRegistrationContext(registrationID);
  }
  return registrationContext;
}

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

@Override
public String[] getRegistrationIDs(AuthConfigProvider provider) {
  String[] elytronRegistrationIds = elytronAuthConfigFactory.getRegistrationIDs(provider);
  String[] backupRegistrationIds = backupAuthConfigFactory.getRegistrationIDs(provider);
  return combine(elytronRegistrationIds, backupRegistrationIds);
}

代码示例来源:origin: org.apache.tomcat/tomcat-jaspic-api

public static AuthConfigFactory getFactory() {
  checkPermission(getFactorySecurityPermission);
  if (factory != null) {
    return factory;
      final String className = getFactoryClassName();
      try {
        factory = AccessController.doPrivileged(

代码示例来源:origin: org.wildfly.security.elytron-web/undertow-server-servlet

private static AuthConfigFactory getAuthConfigFactory() {
  try {
    // TODO - PermissionCheck
    return AuthConfigFactory.getFactory();
  } catch (Exception e) {
    // Logged at TRACE as this will be per request.
    log.trace("Unable to get AuthConfigFactory", e);
  }
  return null;
}

代码示例来源:origin: javaee/security-soteria

public Boolean run() {
    return AuthConfigFactory.getFactory().removeRegistration(registrationId);
  }
});

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

/**
 * Register the assembled configuration against the supplied {@link AuthConfigFactory}.
 *
 * @param authConfigFactory the {@link AuthConfigFactory} to register the configuration against.
 * @return The registration ID returned by the factory on registration.
 * @throws IllegalStateException if the configuration has already been registered.
 */
public String register(AuthConfigFactory authConfigFactory) {
  assertNotRegistered();
  registered = true;
  return authConfigFactory.registerConfigProvider(
      new ElytronAuthConfigProvider(messageLayer, applicationContext, serverAuthModules),
      messageLayer, applicationContext, description);
}

相关文章