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 String
algorithm
private Credential
credential
private Class<? extends Credential>
credentialType
private AlgorithmParameterSpec
parameterSpec
-
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.String
getAlgorithm()
Get the algorithm name, if any.Credential
getCredential()
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.AlgorithmParameterSpec
getParameterSpec()
Get the parameter specification, if any.boolean
isCredentialSupported(Credential credential)
Determine whether the given credential can be set on this callback.boolean
isCredentialTypeSupported(Class<? extends Credential> credentialType)
Determine whether the given credential type is supported.boolean
isCredentialTypeSupported(Class<? extends Credential> credentialType, String algorithmName)
Determine whether the given credential type is supported for the given algorithm name.boolean
isCredentialTypeSupported(Class<? extends Credential> credentialType, String algorithmName, AlgorithmParameterSpec parameterSpec)
Determine whether the given credential type is supported for the given algorithm name.boolean
needsInformation()
Determine if this callback is requesting information.void
setCredential(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
null
if 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
null
if 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
null
if 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, ornull
if any parameters are allowed or parameters are not used by the credential type- Returns:
- the credential, or
null
if 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
null
if 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
null
if 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, ornull
if 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
null
if 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, ornull
to 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 befalse
if the credential type requires an algorithm name; in this case, useisCredentialTypeSupported(Class, String)
instead.- Parameters:
credentialType
- the credential type (must not benull
)- Returns:
true
if the credential type is supported,false
otherwise
-
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, ornull
to indicate that no algorithm name will be available- Returns:
true
if the credential type is supported,false
otherwise
-
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, ornull
to indicate that no algorithm name will be availableparameterSpec
- the parameters, ornull
if no parameters are present in the credential- Returns:
true
if the credential type is supported,false
otherwise
-
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:
true
if the credential matches the type and optional algorithm of this callback,false
otherwise
-
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
null
if 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
null
if any parameters are suitable or the credential type does not use parameters
-
needsInformation
public boolean needsInformation()
Description copied from interface:ExtendedCallback
Determine if this callback is requesting information.- Specified by:
needsInformation
in interfaceExtendedCallback
- Returns:
true
if the callback is requesting information,false
if it is only providing information
-
-