Package net.shibboleth.idp.authn
Class AbstractCredentialValidator
java.lang.Object
net.shibboleth.utilities.java.support.component.AbstractInitializableComponent
net.shibboleth.utilities.java.support.component.AbstractIdentifiedInitializableComponent
net.shibboleth.idp.authn.AbstractCredentialValidator
- All Implemented Interfaces:
CredentialValidator
,PrincipalSupportingComponent
,Component
,DestructableComponent
,IdentifiableComponent
,IdentifiedComponent
,InitializableComponent
- Direct Known Subclasses:
AbstractUsernamePasswordCredentialValidator
,X509CertificateCredentialValidator
public abstract class AbstractCredentialValidator
extends AbstractIdentifiedInitializableComponent
implements CredentialValidator, PrincipalSupportingComponent
An abstract
CredentialValidator
that handles some common behavior.- Since:
- 4.0.0
-
Nested Class Summary
Nested classes/interfaces inherited from interface net.shibboleth.idp.authn.CredentialValidator
CredentialValidator.ErrorHandler, CredentialValidator.WarningHandler
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate Predicate<ProfileRequestContext>
Activation condition.private Subject
Container that carries additionalPrincipal
objects.private final org.slf4j.Logger
Class logger.private String
Cached log prefix. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected abstract Subject
doValidate
(ProfileRequestContext profileRequestContext, AuthenticationContext authenticationContext, CredentialValidator.WarningHandler warningHandler, CredentialValidator.ErrorHandler errorHandler) Override method for subclasses to use to perform the actual validation.protected String
Return a prefix for logging messages for this component.getSupportedPrincipals
(Class<T> c) Get an immutable set of supported custom principals that the component produces, supports, contains, etc.protected boolean
isAcceptable
(RequestedPrincipalContext requestedPrincipalCtx, Subject subject, String configName) Checks a particular request and principal collection for suitability.protected Subject
populateSubject
(Subject subject) Decorate the subject with custom principals if needed.void
setActivationCondition
(Predicate<ProfileRequestContext> condition) Set the activation condition controlling use of validator.void
void
setSupportedPrincipals
(Collection<Principal> principals) Set supported non-user-specific principals that the validator will include in the subjects it generates.validate
(ProfileRequestContext profileRequestContext, AuthenticationContext authenticationContext, CredentialValidator.WarningHandler warningHandler, CredentialValidator.ErrorHandler errorHandler) Validate any credentials found in a supported form within the input context tree and produce aSubject
as the outcome.Methods inherited from class net.shibboleth.utilities.java.support.component.AbstractIdentifiedInitializableComponent
doInitialize, getId
Methods inherited from class net.shibboleth.utilities.java.support.component.AbstractInitializableComponent
destroy, doDestroy, initialize, isDestroyed, isInitialized
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface net.shibboleth.utilities.java.support.component.IdentifiedComponent
getId
-
Field Details
-
log
@Nonnull private final org.slf4j.Logger logClass logger. -
activationCondition
Activation condition. -
logPrefix
Cached log prefix. -
customPrincipals
Container that carries additionalPrincipal
objects.
-
-
Constructor Details
-
AbstractCredentialValidator
public AbstractCredentialValidator()Constructor.
-
-
Method Details
-
setId
- Specified by:
setId
in interfaceIdentifiableComponent
- Overrides:
setId
in classAbstractIdentifiedInitializableComponent
-
setActivationCondition
Set the activation condition controlling use of validator.- Parameters:
condition
- condition to use
-
getSupportedPrincipals
@Nonnull @NonnullElements @Unmodifiable @NotLive public <T extends Principal> Set<T> getSupportedPrincipals(@Nonnull Class<T> c) Get an immutable set of supported custom principals that the component produces, supports, contains, etc.- Specified by:
getSupportedPrincipals
in interfacePrincipalSupportingComponent
- Type Parameters:
T
- type of Principal to inquire on- Parameters:
c
- type of Principal to inquire on- Returns:
- a set of matching principals
-
setSupportedPrincipals
Set supported non-user-specific principals that the validator will include in the subjects it generates.- Parameters:
principals
- supported principals to include
-
validate
public Subject validate(@Nonnull ProfileRequestContext profileRequestContext, @Nonnull AuthenticationContext authenticationContext, @Nullable CredentialValidator.WarningHandler warningHandler, @Nullable CredentialValidator.ErrorHandler errorHandler) throws Exception Validate any credentials found in a supported form within the input context tree and produce aSubject
as the outcome.A null result is used to signal that validation was not attempted.
- Specified by:
validate
in interfaceCredentialValidator
- Parameters:
profileRequestContext
- profile request contextauthenticationContext
- authentication contextwarningHandler
- optional warning handler interfaceerrorHandler
- optional error handler interface- Returns:
- result of a successful validation, or null
- Throws:
Exception
- when validation is unsuccessful due to a failed attempt
-
doValidate
@Nullable protected abstract Subject doValidate(@Nonnull ProfileRequestContext profileRequestContext, @Nonnull AuthenticationContext authenticationContext, @Nullable CredentialValidator.WarningHandler warningHandler, @Nullable CredentialValidator.ErrorHandler errorHandler) throws Exception Override method for subclasses to use to perform the actual validation.- Parameters:
profileRequestContext
- profile request contextauthenticationContext
- authentication contextwarningHandler
- optional warning handler interfaceerrorHandler
- optional error handler interface- Returns:
- the validated result, or null if inapplicable
- Throws:
Exception
- if an error occurs
-
populateSubject
Decorate the subject with custom principals if needed.- Parameters:
subject
- the subject being returned- Returns:
- the decorated subject
-
getLogPrefix
Return a prefix for logging messages for this component.- Returns:
- a string for insertion at the beginning of any log messages
-
isAcceptable
protected boolean isAcceptable(@Nullable RequestedPrincipalContext requestedPrincipalCtx, @Nullable Subject subject, @Nonnull @NotEmpty String configName) Checks a particular request and principal collection for suitability.- Parameters:
requestedPrincipalCtx
- the relevant contextsubject
- collection of custom principals to check, embedded in a subjectconfigName
- name for logging- Returns:
- true iff the request does not specify requirements or the principal collection is empty or the combination is acceptable
-