public interface JaccConfigurationFactory
PolicyConfigurationFactory
that allows to install
a local (per application) Jacc Provider (authorization module).
Note that this only works with Payara's default PolicyConfigurationFactory and not with any replacement global PolicyConfigurationFactory. It may be possible to make such replacement PolicyConfigurationFactory support installing local Jacc Providers by letting it implement this interface.
Installing a local Jacc provider is only supported for a web module, and thus not for an EJB module. A future version of this interface may support EJB modules.
A local Jacc provider can be installed using a ServletContextListener
as follows:
@WebListener
public class JaccInstaller implements ServletContextListener {
@Override
public void contextInitialized(ServletContextEvent sce) {
JaccConfigurationFactory.getJaccConfigurationFactory()
.registerContextProvider(
getAppContextId(sce.getServletContext()),
new TestPolicyConfigurationFactory(),
new TestPolicy());
}
private String getAppContextId(ServletContext servletContext) {
return servletContext.getVirtualServerName() + " " + servletContext.getContextPath();
}
}
Modifier and Type | Method and Description |
---|---|
void |
addContextIdMapping(String applicationContextId,
String policyContextId)
Makes the mapping from the Servlet based context ID to the JACC based context ID
known to the factory.
|
ContextProvider |
getContextProviderByPolicyContextId(String policyContextId)
Gets the context JACC provider that was set by registerContextProvider.
|
static JaccConfigurationFactory |
getJaccConfigurationFactory()
This static method tries to obtain the global JaccConfigurationFactory, which means
looking up the global PolicyConfigurationFactory and testing to see if its a
JaccConfigurationFactory.
|
javax.security.jacc.PolicyConfiguration |
getPolicyConfiguration(String policyContextId,
boolean remove) |
boolean |
inService(String policycontextId) |
void |
registerContextProvider(String applicationContextId,
javax.security.jacc.PolicyConfigurationFactory factory,
Policy policy)
Registers a context (local) Jacc provider, consisting of its two elements.
|
boolean |
removeContextIdMappingByPolicyContextId(String policyContextId)
Removes the mapping from the Servlet based context ID to the JACC based context ID
known to the factory.
|
ContextProvider |
removeContextProviderByPolicyContextId(String policyContextId)
Removes any context JACC provider that was set by registerContextProvider.
|
static JaccConfigurationFactory getJaccConfigurationFactory()
IllegalStateException
- if the underlying PolicyConfigurationFactory could not be obtained
or the PolicyConfigurationFactory is not a JaccConfigurationFactoryjavax.security.jacc.PolicyConfiguration getPolicyConfiguration(String policyContextId, boolean remove) throws javax.security.jacc.PolicyContextException
javax.security.jacc.PolicyContextException
PolicyConfigurationFactory.getPolicyConfiguration(String, boolean)
boolean inService(String policycontextId) throws javax.security.jacc.PolicyContextException
javax.security.jacc.PolicyContextException
PolicyConfigurationFactory.inService(String)
void registerContextProvider(String applicationContextId, javax.security.jacc.PolicyConfigurationFactory factory, Policy policy)
See the JACC spec for the requirements and behavior of the PolicyConfigurationFactory
and the Policy
.
Note that this uses an applicationContextId
for registration. This is a Servlet
based ID to identify the current application. It's defined as follows:
private String getAppContextId(ServletContext servletContext) {
return servletContext.getVirtualServerName() + " " + servletContext.getContextPath();
}
applicationContextId
- an ID identifying the application for which the Jacc provider is installedfactory
- the PolicyConfigurationFactory element of the Jacc Providerpolicy
- the Policy element of the Jacc ProviderSecurityException
- when the calling code has not been granted the "setPolicy" SecurityPermission.ContextProvider getContextProviderByPolicyContextId(String policyContextId)
Note that this uses the policyContextId
, which is a JACC native ID instead of the
Servlet based application ID that's used for registering. The mapping from the Servlet based ID to
the JACC based ID is made known to the factory by the addContextIdMapping
method.
policyContextId
- the identifier of the JACC policy contextContextProvider removeContextProviderByPolicyContextId(String policyContextId)
Note that this uses the policyContextId
, which is a JACC native ID instead of the
Servlet based application ID that's used for registering. The mapping from the Servlet based ID to
the JACC based ID is made known to the factory by the addContextIdMapping
method.
policyContextId
- the identifier of the JACC policy contextvoid addContextIdMapping(String applicationContextId, String policyContextId)
applicationContextId
- Servlet based identifier for an application contextpolicyContextId
- JACC based identifier for an application contextboolean removeContextIdMappingByPolicyContextId(String policyContextId)
policyContextId
- JACC based identifier for an application contextCopyright © 2018. All rights reserved.