Package org.wildfly.security.auth.client
Class AuthenticationContext
- java.lang.Object
-
- org.wildfly.security.auth.client.AuthenticationContext
-
- All Implemented Interfaces:
org.wildfly.common.context.Contextual<AuthenticationContext>
public final class AuthenticationContext extends Object implements org.wildfly.common.context.Contextual<AuthenticationContext>
A set of rules and authentication configurations to use with a client for establishing a connection.- Author:
- David M. Lloyd
-
-
Field Summary
Fields Modifier and Type Field Description (package private) RuleNode<AuthenticationConfiguration>
authRules
private static org.wildfly.common.context.ContextManager<AuthenticationContext>
CONTEXT_MANAGER
(package private) static AuthenticationContext
EMPTY
(package private) RuleNode<SecurityFactory<SSLContext>>
sslRules
private static Supplier<AuthenticationContext>
SUPPLIER
-
Constructor Summary
Constructors Modifier Constructor Description private
AuthenticationContext()
(package private)
AuthenticationContext(RuleNode<AuthenticationConfiguration> authRules, RuleNode<SecurityFactory<SSLContext>> sslRules)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description (package private) RuleNode<AuthenticationConfiguration>
authRuleMatching(URI uri, String abstractType, String abstractTypeAuthority)
static AuthenticationContext
captureCurrent()
Get the current thread's captured authentication context.static AuthenticationContext
empty()
Get a new, empty authentication context.static org.wildfly.common.context.ContextManager<AuthenticationContext>
getContextManager()
Get the context manager for authentication contexts.org.wildfly.common.context.ContextManager<AuthenticationContext>
getInstanceContextManager()
AuthenticationContext
replacing(int idx, MatchRule rule, AuthenticationConfiguration configuration)
Get a new authentication context which is the same as this one, but which replaces the rule and configuration at the given index with the given rule and configuration.private static <T> RuleNode<T>
replacing(RuleNode<T> node, MatchRule rule, T item, int idx)
AuthenticationContext
replacingSslContext(int idx, MatchRule rule, SecurityFactory<SSLContext> sslContext)
Get a new authentication context which is the same as this one, but which replaces the rule and SSL context at the given index with the given rule and SSL context.<T> T
run(PrivilegedAction<T> action)
Run a privileged action with this authentication context associated for the duration of the task.<T> T
run(PrivilegedExceptionAction<T> action)
Run a privileged action with this authentication context associated for the duration of the task.<T,P>
Trun(P parameter, ParametricPrivilegedAction<T,P> action)
Run a privileged action with this authentication context associated for the duration of the task.<T,P>
Trun(P parameter, ParametricPrivilegedExceptionAction<T,P> action)
Run a privileged action with this authentication context associated for the duration of the task.<T> void
runAsObjIntConsumer(ObjIntConsumer<T> action, T parameter1, int parameter2)
Run a privileged action with this authentication context associated for the duration of the task.<T,E extends Exception>
voidrunAsObjIntConsumerEx(org.wildfly.common.function.ExceptionObjIntConsumer<T,E> action, T parameter1, int parameter2)
Run a privileged action with this authentication context associated for the duration of the task.<T> T
runAsSupplier(Supplier<T> action)
Run a privileged action with this authentication context associated for the duration of the task.<T,E extends Exception>
TrunAsSupplierEx(org.wildfly.common.function.ExceptionSupplier<T,E> action)
Run a privileged action with this authentication context associated for the duration of the task.(package private) RuleNode<SecurityFactory<SSLContext>>
sslRuleMatching(URI uri, String abstractType, String abstractTypeAuthority)
AuthenticationContext
with(int idx, MatchRule rule, AuthenticationConfiguration configuration)
Get a new authentication context which is the same as this one, but which includes the given rule and configuration inserted at the position of its list indicated by theidx
parameter.AuthenticationContext
with(AuthenticationContext other)
Get a new authentication context which is the same as this one, but which includes the rules, configurations and SSL contexts of the given context at the end of its list.AuthenticationContext
with(MatchRule rule, AuthenticationConfiguration configuration)
Get a new authentication context which is the same as this one, but which includes the given rule and configuration at the end of its list.private static <T> RuleNode<T>
with(RuleNode<T> node, MatchRule rule, T item)
private static <T> RuleNode<T>
with(RuleNode<T> node, MatchRule rule, T item, int idx)
private static <T> RuleNode<T>
withAll(RuleNode<T> node, RuleNode<T> otherNode)
private static <T> RuleNode<T>
withAll(RuleNode<T> node, RuleNode<T> otherNode, int idx)
AuthenticationContext
without(int idx)
Get a new authentication context which is the same as this one, but without the rule and configuration at the index indicated by theidx
parameter.private static <T> RuleNode<T>
without(RuleNode<T> node, int idx)
AuthenticationContext
withoutSsl(int idx)
Get a new authentication context which is the same as this one, but without the rule and configuration at the index indicated by theidx
parameter.AuthenticationContext
withSsl(int idx, MatchRule rule, SecurityFactory<SSLContext> sslContext)
Get a new authentication context which is the same as this one, but which includes the given rule and SSL context inserted at the position of its list indicated by theidx
parameter.AuthenticationContext
withSsl(MatchRule rule, SecurityFactory<SSLContext> sslContext)
Get a new authentication context which is the same as this one, but which includes the given rule and SSL context at the end of its SSL context list.-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface org.wildfly.common.context.Contextual
run, runAction, runBiConsumer, runBiFunction, runBiPredicate, runCallable, runConsumer, runExBiConsumer, runExBiFunction, runExBiPredicate, runExceptionAction, runExConsumer, runExFunction, runExIntFunction, runExLongFunction, runExPredicate, runFunction, runIntFunction, runLongFunction, runPredicate
-
-
-
-
Field Detail
-
CONTEXT_MANAGER
private static final org.wildfly.common.context.ContextManager<AuthenticationContext> CONTEXT_MANAGER
-
SUPPLIER
private static final Supplier<AuthenticationContext> SUPPLIER
-
authRules
final RuleNode<AuthenticationConfiguration> authRules
-
sslRules
final RuleNode<SecurityFactory<SSLContext>> sslRules
-
EMPTY
static final AuthenticationContext EMPTY
-
-
Constructor Detail
-
AuthenticationContext
private AuthenticationContext()
-
AuthenticationContext
AuthenticationContext(RuleNode<AuthenticationConfiguration> authRules, RuleNode<SecurityFactory<SSLContext>> sslRules)
-
-
Method Detail
-
empty
public static AuthenticationContext empty()
Get a new, empty authentication context.- Returns:
- the new authentication context
-
captureCurrent
public static AuthenticationContext captureCurrent()
Get the current thread's captured authentication context.- Returns:
- the current thread's captured authentication context
-
replacing
private static <T> RuleNode<T> replacing(RuleNode<T> node, MatchRule rule, T item, int idx)
-
with
public AuthenticationContext with(MatchRule rule, AuthenticationConfiguration configuration)
Get a new authentication context which is the same as this one, but which includes the given rule and configuration at the end of its list.- Parameters:
rule
- the rule to matchconfiguration
- the configuration to select when the rule matches- Returns:
- the combined authentication context
-
withSsl
public AuthenticationContext withSsl(MatchRule rule, SecurityFactory<SSLContext> sslContext)
Get a new authentication context which is the same as this one, but which includes the given rule and SSL context at the end of its SSL context list.- Parameters:
rule
- the rule to matchsslContext
- the SSL context to select when the rule matches- Returns:
- the combined authentication context
-
with
public AuthenticationContext with(AuthenticationContext other)
Get a new authentication context which is the same as this one, but which includes the rules, configurations and SSL contexts of the given context at the end of its list.- Parameters:
other
- the other authentication context- Returns:
- the combined authentication context
-
with
public AuthenticationContext with(int idx, MatchRule rule, AuthenticationConfiguration configuration) throws IndexOutOfBoundsException
Get a new authentication context which is the same as this one, but which includes the given rule and configuration inserted at the position of its list indicated by theidx
parameter.- Parameters:
idx
- the index at which insertion should be donerule
- the rule to matchconfiguration
- the configuration to select when the rule matches- Returns:
- the combined authentication context
- Throws:
IndexOutOfBoundsException
- if the index is out of bounds
-
withSsl
public AuthenticationContext withSsl(int idx, MatchRule rule, SecurityFactory<SSLContext> sslContext) throws IndexOutOfBoundsException
Get a new authentication context which is the same as this one, but which includes the given rule and SSL context inserted at the position of its list indicated by theidx
parameter.- Parameters:
idx
- the index at which insertion should be donerule
- the rule to matchsslContext
- the SSL context to select when the rule matches- Returns:
- the combined authentication context
- Throws:
IndexOutOfBoundsException
- if the index is out of bounds
-
replacing
public AuthenticationContext replacing(int idx, MatchRule rule, AuthenticationConfiguration configuration) throws IndexOutOfBoundsException
Get a new authentication context which is the same as this one, but which replaces the rule and configuration at the given index with the given rule and configuration.- Parameters:
idx
- the index at which insertion should be donerule
- the rule to matchconfiguration
- the configuration to select when the rule matches- Returns:
- the combined authentication context
- Throws:
IndexOutOfBoundsException
- if the index is out of bounds
-
replacingSslContext
public AuthenticationContext replacingSslContext(int idx, MatchRule rule, SecurityFactory<SSLContext> sslContext) throws IndexOutOfBoundsException
Get a new authentication context which is the same as this one, but which replaces the rule and SSL context at the given index with the given rule and SSL context.- Parameters:
idx
- the index at which insertion should be donerule
- the rule to matchsslContext
- the SSL context to select when the rule matches- Returns:
- the combined authentication context
- Throws:
IndexOutOfBoundsException
- if the index is out of bounds
-
without
public AuthenticationContext without(int idx) throws IndexOutOfBoundsException
Get a new authentication context which is the same as this one, but without the rule and configuration at the index indicated by theidx
parameter.- Parameters:
idx
- the index at which removal should be done- Returns:
- the modified authentication context
- Throws:
IndexOutOfBoundsException
- if the index is out of bounds
-
withoutSsl
public AuthenticationContext withoutSsl(int idx) throws IndexOutOfBoundsException
Get a new authentication context which is the same as this one, but without the rule and configuration at the index indicated by theidx
parameter.- Parameters:
idx
- the index at which removal should be done- Returns:
- the modified authentication context
- Throws:
IndexOutOfBoundsException
- if the index is out of bounds
-
authRuleMatching
RuleNode<AuthenticationConfiguration> authRuleMatching(URI uri, String abstractType, String abstractTypeAuthority)
-
sslRuleMatching
RuleNode<SecurityFactory<SSLContext>> sslRuleMatching(URI uri, String abstractType, String abstractTypeAuthority)
-
run
public <T> T run(PrivilegedAction<T> action)
Run a privileged action with this authentication context associated for the duration of the task.- Type Parameters:
T
- the action return type- Parameters:
action
- the action to run under association- Returns:
- the action return value
-
run
public <T> T run(PrivilegedExceptionAction<T> action) throws PrivilegedActionException
Run a privileged action with this authentication context associated for the duration of the task.- Type Parameters:
T
- the action return type- Parameters:
action
- the action to run under association- Returns:
- the action return value
- Throws:
PrivilegedActionException
- if the action throws an exception
-
run
public <T,P> T run(P parameter, ParametricPrivilegedAction<T,P> action)
Run a privileged action with this authentication context associated for the duration of the task.- Type Parameters:
T
- the action return typeP
- the action parameter type- Parameters:
parameter
- the parameter to pass to the actionaction
- the action to run under association- Returns:
- the action return value
-
run
public <T,P> T run(P parameter, ParametricPrivilegedExceptionAction<T,P> action) throws PrivilegedActionException
Run a privileged action with this authentication context associated for the duration of the task.- Type Parameters:
T
- the action return typeP
- the action parameter type- Parameters:
parameter
- the parameter to pass to the actionaction
- the action to run under association- Returns:
- the action return value
- Throws:
PrivilegedActionException
- if the action throws an exception
-
runAsObjIntConsumer
public <T> void runAsObjIntConsumer(ObjIntConsumer<T> action, T parameter1, int parameter2)
Run a privileged action with this authentication context associated for the duration of the task.- Type Parameters:
T
- the action first parameter type- Parameters:
parameter1
- the first parameter to pass to the actionparameter2
- the second parameter to pass to the actionaction
- the action to run
-
runAsSupplier
public <T> T runAsSupplier(Supplier<T> action)
Run a privileged action with this authentication context associated for the duration of the task.- Type Parameters:
T
- the action return type- Parameters:
action
- the action to run- Returns:
- the action result (may be
null
)
-
runAsObjIntConsumerEx
public <T,E extends Exception> void runAsObjIntConsumerEx(org.wildfly.common.function.ExceptionObjIntConsumer<T,E> action, T parameter1, int parameter2) throws E extends Exception
Run a privileged action with this authentication context associated for the duration of the task.- Type Parameters:
T
- the action first parameter typeE
- the action exception type- Parameters:
parameter1
- the first parameter to pass to the actionparameter2
- the second parameter to pass to the actionaction
- the action to run- Throws:
E
- if the action throws this exceptionE extends Exception
-
runAsSupplierEx
public <T,E extends Exception> T runAsSupplierEx(org.wildfly.common.function.ExceptionSupplier<T,E> action) throws E extends Exception
Run a privileged action with this authentication context associated for the duration of the task.- Type Parameters:
T
- the action return typeE
- the action exception type- Parameters:
action
- the action to run- Returns:
- the action result (may be
null
) - Throws:
E
- if the action throws this exceptionE extends Exception
-
getInstanceContextManager
public org.wildfly.common.context.ContextManager<AuthenticationContext> getInstanceContextManager()
- Specified by:
getInstanceContextManager
in interfaceorg.wildfly.common.context.Contextual<AuthenticationContext>
-
getContextManager
public static org.wildfly.common.context.ContextManager<AuthenticationContext> getContextManager()
Get the context manager for authentication contexts.- Returns:
- the context manager for authentication contexts (not
null
)
-
-