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 abstractCredentialValidatorthat 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
Fields Modifier and Type Field Description private Predicate<ProfileRequestContext>activationConditionActivation condition.private SubjectcustomPrincipalsContainer that carries additionalPrincipalobjects.private org.slf4j.LoggerlogClass logger.private StringlogPrefixCached log prefix.
-
Constructor Summary
Constructors Constructor Description AbstractCredentialValidator()Constructor.
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description protected abstract SubjectdoValidate(ProfileRequestContext profileRequestContext, AuthenticationContext authenticationContext, CredentialValidator.WarningHandler warningHandler, CredentialValidator.ErrorHandler errorHandler)Override method for subclasses to use to perform the actual validation.protected StringgetLogPrefix()Return a prefix for logging messages for this component.<T extends Principal>
Set<T>getSupportedPrincipals(Class<T> c)Get an immutable set of supported custom principals that the component produces, supports, contains, etc.protected booleanisAcceptable(RequestedPrincipalContext requestedPrincipalCtx, Subject subject, String configName)Checks a particular request and principal collection for suitability.protected SubjectpopulateSubject(Subject subject)Decorate the subject with custom principals if needed.voidsetActivationCondition(Predicate<ProfileRequestContext> condition)Set the activation condition controlling use of validator.voidsetId(String id)voidsetSupportedPrincipals(Collection<Principal> principals)Set supported non-user-specific principals that the validator will include in the subjects it generates.Subjectvalidate(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 aSubjectas 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 Detail
-
log
@Nonnull private final org.slf4j.Logger log
Class logger.
-
activationCondition
@Nonnull private Predicate<ProfileRequestContext> activationCondition
Activation condition.
-
logPrefix
@Nullable private String logPrefix
Cached log prefix.
-
-
Method Detail
-
setId
public void setId(String id)
- Specified by:
setIdin interfaceIdentifiableComponent- Overrides:
setIdin classAbstractIdentifiedInitializableComponent
-
setActivationCondition
public void setActivationCondition(@Nonnull Predicate<ProfileRequestContext> condition)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:
getSupportedPrincipalsin 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
public void setSupportedPrincipals(@Nullable @NonnullElements Collection<Principal> principals)
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 aSubjectas the outcome.A null result is used to signal that validation was not attempted.
- Specified by:
validatein 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
@Nonnull protected Subject populateSubject(@Nonnull Subject subject)
Decorate the subject with custom principals if needed.- Parameters:
subject- the subject being returned- Returns:
- the decorated subject
-
getLogPrefix
@Nonnull @NotEmpty protected String 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
-
-