javax.security.auth.message.config.AuthConfigFactory.getFactory()方法的使用及代码示例

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

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

AuthConfigFactory.getFactory介绍

[英]Get the system-wide AuthConfigFactory implementation.

If a non-null system-wide factory instance is defined at the time of the call, for example, with setFactory, it will be returned. Otherwise, an attempt will be made to construct an instance of the default AuthConfigFactory implementation class. The fully qualified class name of the default factory implementation class is obtained from the value of the DEFAULT_FACTORY_SECURITY_PROPERTY security property. When an instance of the default factory implementation class is successfully constructed by this method, this method will set it as the system-wide factory instance.

The absolute pathname of the Java security properties file is JAVA_HOME/lib/security/java.security, where JAVA_HOME refers to the directory where the JDK was installed.

When a SecurityManager is enabled, the getFactorySecurityPermission will be required to call this method. If at the time of the call, a system-wide factory instance has not already been defined, then the setFactorySecurityPermission will also be required.
[中]获取系统范围的AuthConfigFactory实现。
如果在调用时定义了非空的系统范围工厂实例,例如,使用setFactory,则将返回该实例。否则,将尝试构造默认AuthConfigFactory实现类的实例。默认工厂实现类的完全限定类名是从默认工厂安全属性安全属性的值中获取的。当使用此方法成功构造默认工厂实现类的实例时,此方法将其设置为系统范围的工厂实例。
Java安全属性文件的绝对路径名是Java_HOME/lib/security/Java。安全性,其中JAVA_HOME指安装JDK的目录。
启用SecurityManager时,需要getFactorySecurityPermission调用此方法。如果在调用时尚未定义系统范围的工厂实例,则还需要setFactorySecurityPermission。

代码示例

代码示例来源: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: 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

/**
 * <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: wildfly/wildfly

/**
 * <p>
 * JASPIC 1.1 specification: if there is an {@code AuthConfigProvider} for the {@code HttpServlet} layer and
 * application context, then @{@code logout} must acquire a {@code ServerAuthContext} and call {@code cleanSubject}
 * on the acquired context.
 * </p>
 * <p>
 * The specified {@code Subject} should be non-null and should be the {@code Subject} returning from the most recent
 * call to {@code validateRequest}. In our case, that {@code Subject} is set in the underlying security context, so
 * we must retrieve it from there before calling {@code cleanSubject}.
 * </p>
 * <p>
 * Once {@code cleanSubject} returns, {@code logout} must perform the regular (non-JASPIC) {@code logout} processing.
 * </p>
 */
@Override
public void logout() {
  if (!isAuthenticated())
    return;
  // call cleanSubject() if there is an AuthConfigProvider for the HttpServlet layer and appContext.
  String appContext = this.buildAppContext();
  if (AuthConfigFactory.getFactory().getConfigProvider(layer, appContext, null) != null) {
    Subject authenticatedSubject = this.getAuthenticatedSubject();
    MessageInfo messageInfo = this.buildMessageInfo();
    this.manager.cleanSubject(messageInfo, authenticatedSubject, layer, appContext, handler);
  }
  // following the return from cleanSubject(), logout must perform the regular logout processing.
  super.logout();
}

代码示例来源: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: org.apache.tomcat/tomcat-catalina

private Optional<AuthConfigProvider> findJaspicProvider() {
  AuthConfigFactory factory = AuthConfigFactory.getFactory();
  Optional<AuthConfigProvider> provider;
  if (factory == null) {
    provider = Optional.empty();
  } else {
    provider = Optional.ofNullable(
        factory.getConfigProvider("HttpServlet", jaspicAppContextID, this));
  }
  jaspicProvider = provider;
  return provider;
}

代码示例来源:origin: org.ops4j.pax.tipi/org.ops4j.pax.tipi.tomcat-embed-core

private Optional<AuthConfigProvider> findJaspicProvider() {
  AuthConfigFactory factory = AuthConfigFactory.getFactory();
  Optional<AuthConfigProvider> provider;
  if (factory == null) {
    provider = Optional.empty();
  } else {
    provider = Optional.ofNullable(
        factory.getConfigProvider("HttpServlet", jaspicAppContextID, this));
  }
  jaspicProvider = provider;
  return provider;
}

代码示例来源:origin: org.wildfly.security/wildfly-elytron

/**
 * 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.wildfly.security/wildfly-elytron-jaspi

/**
 * 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: wildfly/wildfly-core

private static AuthConfigFactory getAuthConfigFactory() {
  ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
  try {
    Thread.currentThread().setContextClassLoader(ElytronDefinition.class.getClassLoader());
    return AuthConfigFactory.getFactory();
  } catch (Exception e) {
    ROOT_LOGGER.trace("Unable to load default AuthConfigFactory.", e);
    return null;
  } finally {
    Thread.currentThread().setContextClassLoader(classLoader);
  }
}

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

private static void removeRegistration(final OperationContext context) {
  final String registrationId = REGISTRATION_MAP.remove(context.getCurrentAddressValue());
  if (registrationId != null) {
    AuthConfigFactory authConfigFactory = AuthConfigFactory.getFactory();
    authConfigFactory.removeRegistration(registrationId);
  }
}

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

public String run() {
    return AuthConfigFactory.getFactory().registerConfigProvider(
        new DefaultAuthConfigProvider(serverAuthModule),
        "HttpServlet", 
        getAppContextID(servletContext), 
        "Default single SAM authentication config provider");
  }
});

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

public String run() {
    return AuthConfigFactory.getFactory().registerConfigProvider(
        new DefaultAuthConfigProvider(serverAuthModule),
        "HttpServlet", 
        getAppContextID(servletContext), 
        "Default single SAM authentication config provider");
  }
});

代码示例来源:origin: org.apache.geronimo.components/geronimo-jaspi

public static String registerAuthConfigProvider(Reader config, String messageLayer, String appContext) throws ConfigException {
  try {
    ConfigProviderType configProviderType = JaspiXmlUtil.loadConfigProvider(config);
    AuthConfigProvider authConfigProvider = JaspiUtil.wrapAuthConfigProvider(configProviderType);
    return AuthConfigFactory.getFactory().registerConfigProvider(authConfigProvider, messageLayer, appContext, null);
  } catch (Exception e) {
    throw new ConfigException(e);
  }
}

代码示例来源:origin: org.apache.geronimo.components/geronimo-jaspi

public static String registerClientAuthModule(String messageLayer, String appContext, String authenticationContextID, Reader config, boolean _protected) throws ConfigException {
  try {
    AuthModuleType<ClientAuthModule> clientAuthModuleType = JaspiXmlUtil.loadClientAuthModule(config);
    AuthConfigProvider authConfigProvider = JaspiUtil.wrapClientAuthModule(messageLayer, appContext, authenticationContextID, clientAuthModuleType, _protected);
    return AuthConfigFactory.getFactory().registerConfigProvider(authConfigProvider, messageLayer, appContext, null);
  } catch (Exception e) {
    throw new ConfigException(e);
  }
}

代码示例来源:origin: org.apache.geronimo.components/geronimo-jaspi

public static String registerServerAuthModule(String messageLayer, String appContext, String authenticationContextID, Reader config, boolean _protected) throws ConfigException {
  try {
    AuthModuleType<ServerAuthModule> serverAuthModuleType = JaspiXmlUtil.loadServerAuthModule(config);
    AuthConfigProvider authConfigProvider = JaspiUtil.wrapServerAuthModule(messageLayer, appContext, authenticationContextID, serverAuthModuleType, _protected);
    return AuthConfigFactory.getFactory().registerConfigProvider(authConfigProvider, messageLayer, appContext, null);
  } catch (Exception e) {
    throw new ConfigException(e);
  }
}

代码示例来源:origin: org.apache.geronimo.components/geronimo-jaspi

public static String registerClientAuthConfig(Reader config) throws ConfigException {
  try {
    ClientAuthConfigType clientAuthConfigType = JaspiXmlUtil.loadClientAuthConfig(config);
    AuthConfigProvider authConfigProvider = JaspiUtil.wrapClientAuthConfig(clientAuthConfigType);
    return AuthConfigFactory.getFactory().registerConfigProvider(authConfigProvider, clientAuthConfigType.getMessageLayer(), clientAuthConfigType.getAppContext(), null);
  } catch (Exception e) {
    throw new ConfigException(e);
  }
}

代码示例来源:origin: org.apache.geronimo.components/geronimo-jaspi

public static String registerServerAuthContext(Reader config, boolean _protected) throws ConfigException {
  try {
    ServerAuthContextType serverAuthContextType = JaspiXmlUtil.loadServerAuthContext(config);
    AuthConfigProvider authConfigProvider = JaspiUtil.wrapServerAuthContext(serverAuthContextType, _protected);
    return AuthConfigFactory.getFactory().registerConfigProvider(authConfigProvider, serverAuthContextType.getMessageLayer(), serverAuthContextType.getAppContext(), null);
  } catch (Exception e) {
    throw new ConfigException(e);
  }
}

代码示例来源:origin: org.apache.geronimo.components/geronimo-jaspi

public static String registerClientAuthContext(Reader config, boolean _protected) throws ConfigException {
  try {
    ClientAuthContextType clientAuthContextType = JaspiXmlUtil.loadClientAuthContext(config);
    AuthConfigProvider authConfigProvider = JaspiUtil.wrapClientAuthContext(clientAuthContextType, _protected);
    return AuthConfigFactory.getFactory().registerConfigProvider(authConfigProvider, clientAuthContextType.getMessageLayer(), clientAuthContextType.getAppContext(), null);
  } catch (Exception e) {
    throw new ConfigException(e);
  }
}

代码示例来源:origin: org.apache.geronimo.components/geronimo-jaspi

public static String registerServerAuthConfig(Reader config) throws ConfigException {
  try {
    ServerAuthConfigType serverAuthConfigType = JaspiXmlUtil.loadServerAuthConfig(config);
    AuthConfigProvider authConfigProvider = JaspiUtil.wrapServerAuthConfig(serverAuthConfigType);
    return AuthConfigFactory.getFactory().registerConfigProvider(authConfigProvider, serverAuthConfigType.getMessageLayer(), serverAuthConfigType.getAppContext(), null);
  } catch (Exception e) {
    throw new ConfigException(e);
  }
}

相关文章