Class AbstractCredentialCallback
- java.lang.Object
-
- org.wildfly.security.auth.callback.AbstractCredentialCallback
-
- All Implemented Interfaces:
Callback,ExtendedCallback
- Direct Known Subclasses:
CredentialCallback,ServerCredentialCallback
public abstract class AbstractCredentialCallback extends Object implements ExtendedCallback
Abstract base class for credential callbacks.- Author:
- David M. Lloyd
-
-
Field Summary
Fields Modifier and Type Field Description private Stringalgorithmprivate Credentialcredentialprivate Class<? extends Credential>credentialTypeprivate AlgorithmParameterSpecparameterSpec
-
Constructor Summary
Constructors Constructor Description AbstractCredentialCallback(Class<? extends Credential> credentialType, String algorithm, AlgorithmParameterSpec parameterSpec)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description <C extends Credential,R>
RapplyToCredential(Class<C> credentialType, String algorithmName, AlgorithmParameterSpec parameterSpec, Function<C,R> function)Apply the given function to the acquired credential, if it is set and of the given type and algorithm.<C extends Credential,R>
RapplyToCredential(Class<C> credentialType, String algorithmName, Function<C,R> function)Apply the given function to the acquired credential, if it is set and of the given type and algorithm.<C extends Credential,R>
RapplyToCredential(Class<C> credentialType, Function<C,R> function)Apply the given function to the acquired credential, if it is set and of the given type.StringgetAlgorithm()Get the algorithm name, if any.CredentialgetCredential()Get the acquired credential.<C extends Credential>
CgetCredential(Class<C> credentialType)Get the acquired credential, if it is set and of the given type, and if so, return the credential cast to the type.<C extends Credential>
CgetCredential(Class<C> credentialType, String algorithmName)Get the acquired credential, if it is set and of the given type and algorithm, and if so, return the credential cast to the type.<C extends Credential>
CgetCredential(Class<C> credentialType, String algorithmName, AlgorithmParameterSpec parameterSpec)Get the acquired credential, if it is set and of the given type, algorithm, and parameters, and if so, return the credential cast to the type.Class<? extends Credential>getCredentialType()Get the supported credential type.AlgorithmParameterSpecgetParameterSpec()Get the parameter specification, if any.booleanisCredentialSupported(Credential credential)Determine whether the given credential can be set on this callback.booleanisCredentialTypeSupported(Class<? extends Credential> credentialType)Determine whether the given credential type is supported.booleanisCredentialTypeSupported(Class<? extends Credential> credentialType, String algorithmName)Determine whether the given credential type is supported for the given algorithm name.booleanisCredentialTypeSupported(Class<? extends Credential> credentialType, String algorithmName, AlgorithmParameterSpec parameterSpec)Determine whether the given credential type is supported for the given algorithm name.booleanneedsInformation()Determine if this callback is requesting information.voidsetCredential(Credential credential)Set the credential.-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface org.wildfly.security.auth.callback.ExtendedCallback
isOptional
-
-
-
-
Field Detail
-
credentialType
private final Class<? extends Credential> credentialType
-
algorithm
private final String algorithm
-
parameterSpec
private final AlgorithmParameterSpec parameterSpec
-
credential
private Credential credential
-
-
Constructor Detail
-
AbstractCredentialCallback
AbstractCredentialCallback(Class<? extends Credential> credentialType, String algorithm, AlgorithmParameterSpec parameterSpec)
-
-
Method Detail
-
getCredential
public Credential getCredential()
Get the acquired credential.- Returns:
- the acquired credential, or
nullif it wasn't set yet.
-
getCredential
public <C extends Credential> C getCredential(Class<C> credentialType)
Get the acquired credential, if it is set and of the given type, and if so, return the credential cast to the type.- Type Parameters:
C- the credential type- Parameters:
credentialType- the credential type class (must not benull)- Returns:
- the credential, or
nullif the criteria wasn't met
-
getCredential
public <C extends Credential> C getCredential(Class<C> credentialType, String algorithmName)
Get the acquired credential, if it is set and of the given type and algorithm, and if so, return the credential cast to the type.- Type Parameters:
C- the credential type- Parameters:
credentialType- the credential type class (must not benull)algorithmName- the algorithm name- Returns:
- the credential, or
nullif the criteria are not met
-
getCredential
public <C extends Credential> C getCredential(Class<C> credentialType, String algorithmName, AlgorithmParameterSpec parameterSpec)
Get the acquired credential, if it is set and of the given type, algorithm, and parameters, and if so, return the credential cast to the type.- Type Parameters:
C- the credential type- Parameters:
credentialType- the credential type class (must not benull)algorithmName- the algorithm nameparameterSpec- the parameter specification to match, ornullif any parameters are allowed or parameters are not used by the credential type- Returns:
- the credential, or
nullif the criteria are not met
-
applyToCredential
public <C extends Credential,R> R applyToCredential(Class<C> credentialType, Function<C,R> function)
Apply the given function to the acquired credential, if it is set and of the given type. By calling this method, it is possible to apply transformations to the stored credential without failing if the credential was not set.- Type Parameters:
C- the credential typeR- the return type- Parameters:
credentialType- the credential type class (must not benull)function- the function to apply (must not benull)- Returns:
- the result of the function, or
nullif the criteria are not met
-
applyToCredential
public <C extends Credential,R> R applyToCredential(Class<C> credentialType, String algorithmName, Function<C,R> function)
Apply the given function to the acquired credential, if it is set and of the given type and algorithm. By calling this method, it is possible to apply transformations to the stored credential without failing if the credential was not set.- Type Parameters:
C- the credential typeR- the return type- Parameters:
credentialType- the credential type class (must not benull)algorithmName- the algorithm namefunction- the function to apply (must not benull)- Returns:
- the result of the function, or
nullif the criteria are not met
-
applyToCredential
public <C extends Credential,R> R applyToCredential(Class<C> credentialType, String algorithmName, AlgorithmParameterSpec parameterSpec, Function<C,R> function)
Apply the given function to the acquired credential, if it is set and of the given type and algorithm. By calling this method, it is possible to apply transformations to the stored credential without failing if the credential was not set.- Type Parameters:
C- the credential typeR- the return type- Parameters:
credentialType- the credential type class (must not benull)algorithmName- the algorithm nameparameterSpec- the parameter specification to match, ornullif any parameters are allowed or parameters are not used by the credential typefunction- the function to apply (must not benull)- Returns:
- the result of the function, or
nullif the criteria are not met
-
setCredential
public void setCredential(Credential credential)
Set the credential. The credential must be of the supported type and algorithm.- Parameters:
credential- the credential, ornullto indicate that no credential is available- Throws:
IllegalArgumentException- if the given credential is not supported
-
isCredentialTypeSupported
public boolean isCredentialTypeSupported(Class<? extends Credential> credentialType)
Determine whether the given credential type is supported. Will befalseif the credential type requires an algorithm name; in this case, useisCredentialTypeSupported(Class, String)instead.- Parameters:
credentialType- the credential type (must not benull)- Returns:
trueif the credential type is supported,falseotherwise
-
isCredentialTypeSupported
public boolean isCredentialTypeSupported(Class<? extends Credential> credentialType, String algorithmName)
Determine whether the given credential type is supported for the given algorithm name.- Parameters:
credentialType- the credential type (must not benull)algorithmName- the algorithm name, ornullto indicate that no algorithm name will be available- Returns:
trueif the credential type is supported,falseotherwise
-
isCredentialTypeSupported
public boolean isCredentialTypeSupported(Class<? extends Credential> credentialType, String algorithmName, AlgorithmParameterSpec parameterSpec)
Determine whether the given credential type is supported for the given algorithm name.- Parameters:
credentialType- the credential type (must not benull)algorithmName- the algorithm name, ornullto indicate that no algorithm name will be availableparameterSpec- the parameters, ornullif no parameters are present in the credential- Returns:
trueif the credential type is supported,falseotherwise
-
isCredentialSupported
public boolean isCredentialSupported(Credential credential)
Determine whether the given credential can be set on this callback.- Parameters:
credential- the credential (must not benull)- Returns:
trueif the credential matches the type and optional algorithm of this callback,falseotherwise
-
getCredentialType
public Class<? extends Credential> getCredentialType()
Get the supported credential type.- Returns:
- the supported credential type (not
null)
-
getAlgorithm
public String getAlgorithm()
Get the algorithm name, if any.- Returns:
- the algorithm name, or
nullif any algorithm is suitable or the credential type does not use algorithm names
-
getParameterSpec
public AlgorithmParameterSpec getParameterSpec()
Get the parameter specification, if any.- Returns:
- the parameter specification, or
nullif any parameters are suitable or the credential type does not use parameters
-
needsInformation
public boolean needsInformation()
Description copied from interface:ExtendedCallbackDetermine if this callback is requesting information.- Specified by:
needsInformationin interfaceExtendedCallback- Returns:
trueif the callback is requesting information,falseif it is only providing information
-
-