Class DefaultAuthenticationBuilder

  • All Implemented Interfaces:
    java.io.Serializable, org.apereo.cas.authentication.AuthenticationBuilder

    public class DefaultAuthenticationBuilder
    extends java.lang.Object
    implements org.apereo.cas.authentication.AuthenticationBuilder
    Constructs immutable Authentication objects using the builder pattern.
    Since:
    4.0.0
    See Also:
    Serialized Form
    • Constructor Summary

      Constructors 
      Constructor Description
      DefaultAuthenticationBuilder()
      Creates a new instance using the current date for the authentication date.
      DefaultAuthenticationBuilder​(org.apereo.cas.authentication.principal.Principal p)
      Creates a new instance using the current date for the authentication date and the given principal for the authenticated principal.
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      org.apereo.cas.authentication.AuthenticationBuilder addAttribute​(java.lang.String key, java.lang.Object value)
      Adds an authentication metadata attribute key-value pair.
      org.apereo.cas.authentication.AuthenticationBuilder addCredential​(org.apereo.cas.authentication.CredentialMetaData credential)
      Adds metadata about a credential presented for authentication.
      org.apereo.cas.authentication.AuthenticationBuilder addCredentials​(java.util.List<org.apereo.cas.authentication.CredentialMetaData> credentials)  
      org.apereo.cas.authentication.AuthenticationBuilder addFailure​(java.lang.String key, java.lang.Throwable value)
      Adds an authentication failure to the map of handler names to the authentication handler failures.
      org.apereo.cas.authentication.AuthenticationBuilder addFailures​(java.util.Map<java.lang.String,java.lang.Throwable> failures)  
      org.apereo.cas.authentication.AuthenticationBuilder addSuccess​(java.lang.String key, org.apereo.cas.authentication.AuthenticationHandlerExecutionResult value)
      Adds an authentication success to the map of handler names to successful authentication handler results.
      org.apereo.cas.authentication.AuthenticationBuilder addSuccesses​(java.util.Map<java.lang.String,org.apereo.cas.authentication.AuthenticationHandlerExecutionResult> successes)  
      org.apereo.cas.authentication.Authentication build()
      Creates an immutable authentication instance from builder data.
      boolean hasAttribute​(java.lang.String name, java.util.function.Predicate<java.lang.Object> predicate)  
      org.apereo.cas.authentication.AuthenticationBuilder mergeAttribute​(java.lang.String key, java.lang.Object value)  
      static org.apereo.cas.authentication.AuthenticationBuilder newInstance()
      Creates a new builder.
      static org.apereo.cas.authentication.AuthenticationBuilder newInstance​(org.apereo.cas.authentication.Authentication source)
      Creates a new builder initialized with data from the given authentication source.
      org.apereo.cas.authentication.AuthenticationBuilder setAttributes​(java.util.Map<java.lang.String,java.lang.Object> attributes)
      Sets the authentication metadata attributes.
      org.apereo.cas.authentication.AuthenticationBuilder setAuthenticationDate​(java.time.ZonedDateTime d)
      Sets the authentication date and returns this instance.
      org.apereo.cas.authentication.AuthenticationBuilder setCredentials​(java.util.List<org.apereo.cas.authentication.CredentialMetaData> credentials)
      Sets the list of metadata about credentials presented for authentication.
      org.apereo.cas.authentication.AuthenticationBuilder setFailures​(java.util.Map<java.lang.String,java.lang.Throwable> failures)
      Sets the authentication handler failure map.
      org.apereo.cas.authentication.AuthenticationBuilder setPrincipal​(org.apereo.cas.authentication.principal.Principal p)
      Sets the principal returns this instance.
      org.apereo.cas.authentication.AuthenticationBuilder setSuccesses​(java.util.Map<java.lang.String,org.apereo.cas.authentication.AuthenticationHandlerExecutionResult> successes)
      Sets the authentication handler success map.
      • Methods inherited from interface org.apereo.cas.authentication.AuthenticationBuilder

        getFailures, getPrincipal, getSuccesses, hasAttribute
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • DefaultAuthenticationBuilder

        public DefaultAuthenticationBuilder()
        Creates a new instance using the current date for the authentication date.
      • DefaultAuthenticationBuilder

        public DefaultAuthenticationBuilder​(org.apereo.cas.authentication.principal.Principal p)
        Creates a new instance using the current date for the authentication date and the given principal for the authenticated principal.
        Parameters:
        p - Authenticated principal.
    • Method Detail

      • newInstance

        public static org.apereo.cas.authentication.AuthenticationBuilder newInstance​(org.apereo.cas.authentication.Authentication source)
        Creates a new builder initialized with data from the given authentication source.
        Parameters:
        source - Authentication source.
        Returns:
        New builder instance initialized with all fields in the given authentication source.
      • newInstance

        public static org.apereo.cas.authentication.AuthenticationBuilder newInstance()
        Creates a new builder.
        Returns:
        New builder instance
      • setAuthenticationDate

        public org.apereo.cas.authentication.AuthenticationBuilder setAuthenticationDate​(java.time.ZonedDateTime d)
        Sets the authentication date and returns this instance.
        Specified by:
        setAuthenticationDate in interface org.apereo.cas.authentication.AuthenticationBuilder
        Parameters:
        d - Authentication date.
        Returns:
        This builder instance.
      • addCredentials

        public org.apereo.cas.authentication.AuthenticationBuilder addCredentials​(java.util.List<org.apereo.cas.authentication.CredentialMetaData> credentials)
        Specified by:
        addCredentials in interface org.apereo.cas.authentication.AuthenticationBuilder
      • setPrincipal

        public org.apereo.cas.authentication.AuthenticationBuilder setPrincipal​(org.apereo.cas.authentication.principal.Principal p)
        Sets the principal returns this instance.
        Specified by:
        setPrincipal in interface org.apereo.cas.authentication.AuthenticationBuilder
        Parameters:
        p - Authenticated principal.
        Returns:
        This builder instance.
      • setCredentials

        public org.apereo.cas.authentication.AuthenticationBuilder setCredentials​(@NonNull
                                                                                  java.util.List<org.apereo.cas.authentication.CredentialMetaData> credentials)
        Sets the list of metadata about credentials presented for authentication.
        Parameters:
        credentials - Non-null list of credential metadata.
        Returns:
        This builder instance.
      • addCredential

        public org.apereo.cas.authentication.AuthenticationBuilder addCredential​(org.apereo.cas.authentication.CredentialMetaData credential)
        Adds metadata about a credential presented for authentication.
        Specified by:
        addCredential in interface org.apereo.cas.authentication.AuthenticationBuilder
        Parameters:
        credential - Credential metadata.
        Returns:
        This builder instance.
      • setAttributes

        public org.apereo.cas.authentication.AuthenticationBuilder setAttributes​(java.util.Map<java.lang.String,java.lang.Object> attributes)
        Sets the authentication metadata attributes.
        Specified by:
        setAttributes in interface org.apereo.cas.authentication.AuthenticationBuilder
        Parameters:
        attributes - Non-null map of authentication metadata attributes.
        Returns:
        This builder instance.
      • mergeAttribute

        public org.apereo.cas.authentication.AuthenticationBuilder mergeAttribute​(java.lang.String key,
                                                                                  java.lang.Object value)
        Specified by:
        mergeAttribute in interface org.apereo.cas.authentication.AuthenticationBuilder
      • hasAttribute

        public boolean hasAttribute​(java.lang.String name,
                                    java.util.function.Predicate<java.lang.Object> predicate)
        Specified by:
        hasAttribute in interface org.apereo.cas.authentication.AuthenticationBuilder
      • addAttribute

        public org.apereo.cas.authentication.AuthenticationBuilder addAttribute​(java.lang.String key,
                                                                                java.lang.Object value)
        Adds an authentication metadata attribute key-value pair.
        Specified by:
        addAttribute in interface org.apereo.cas.authentication.AuthenticationBuilder
        Parameters:
        key - Authentication attribute key.
        value - Authentication attribute value.
        Returns:
        This builder instance.
      • setSuccesses

        public org.apereo.cas.authentication.AuthenticationBuilder setSuccesses​(@NonNull
                                                                                java.util.Map<java.lang.String,org.apereo.cas.authentication.AuthenticationHandlerExecutionResult> successes)
        Sets the authentication handler success map.
        Specified by:
        setSuccesses in interface org.apereo.cas.authentication.AuthenticationBuilder
        Parameters:
        successes - Non-null map of handler names to successful handler authentication results.
        Returns:
        This builder instance.
      • addSuccesses

        public org.apereo.cas.authentication.AuthenticationBuilder addSuccesses​(java.util.Map<java.lang.String,org.apereo.cas.authentication.AuthenticationHandlerExecutionResult> successes)
        Specified by:
        addSuccesses in interface org.apereo.cas.authentication.AuthenticationBuilder
      • addSuccess

        public org.apereo.cas.authentication.AuthenticationBuilder addSuccess​(java.lang.String key,
                                                                              org.apereo.cas.authentication.AuthenticationHandlerExecutionResult value)
        Adds an authentication success to the map of handler names to successful authentication handler results.
        Specified by:
        addSuccess in interface org.apereo.cas.authentication.AuthenticationBuilder
        Parameters:
        key - Authentication handler name.
        value - Successful authentication handler result produced by handler of given name.
        Returns:
        This builder instance.
      • setFailures

        public org.apereo.cas.authentication.AuthenticationBuilder setFailures​(@NonNull
                                                                               java.util.Map<java.lang.String,java.lang.Throwable> failures)
        Sets the authentication handler failure map.
        Specified by:
        setFailures in interface org.apereo.cas.authentication.AuthenticationBuilder
        Parameters:
        failures - Non-null map of handler name to authentication failures.
        Returns:
        This builder instance.
      • addFailures

        public org.apereo.cas.authentication.AuthenticationBuilder addFailures​(java.util.Map<java.lang.String,java.lang.Throwable> failures)
        Specified by:
        addFailures in interface org.apereo.cas.authentication.AuthenticationBuilder
      • addFailure

        public org.apereo.cas.authentication.AuthenticationBuilder addFailure​(java.lang.String key,
                                                                              java.lang.Throwable value)
        Adds an authentication failure to the map of handler names to the authentication handler failures.
        Specified by:
        addFailure in interface org.apereo.cas.authentication.AuthenticationBuilder
        Parameters:
        key - Authentication handler name.
        value - Exception raised on handler failure to authenticate credential.
        Returns:
        This builder instance.
      • build

        public org.apereo.cas.authentication.Authentication build()
        Creates an immutable authentication instance from builder data.
        Specified by:
        build in interface org.apereo.cas.authentication.AuthenticationBuilder
        Returns:
        Immutable authentication.