Class RestAuthenticator

  • All Implemented Interfaces:
    org.pac4j.core.credentials.authenticator.Authenticator

    public class RestAuthenticator
    extends org.pac4j.core.profile.definition.ProfileDefinitionAware
    implements org.pac4j.core.credentials.authenticator.Authenticator
    Authenticates against a REST API. The username/password are passed as a basic auth via a POST request, the JSON response is a user profile.
    Since:
    2.1.0
    Author:
    Jerome Leleu
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      protected void buildProfile​(org.pac4j.core.credentials.UsernamePasswordCredentials credentials, java.lang.String body)  
      protected java.lang.String callRestApi​(java.lang.String username, java.lang.String password)
      Return the body from the REST API, passing the username/pasword auth.
      com.fasterxml.jackson.databind.ObjectMapper getMapper()  
      java.lang.String getUrl()  
      protected void internalInit()  
      void setMapper​(com.fasterxml.jackson.databind.ObjectMapper mapper)  
      void setUrl​(java.lang.String url)  
      java.lang.String toString()  
      void validate​(org.pac4j.core.credentials.Credentials cred, org.pac4j.core.context.WebContext context, org.pac4j.core.context.session.SessionStore sessionStore)  
      • Methods inherited from class org.pac4j.core.profile.definition.ProfileDefinitionAware

        defaultProfileDefinition, getProfileDefinition, setProfileDefinition
      • Methods inherited from class org.pac4j.core.util.InitializableObject

        afterInternalInit, beforeInternalInit, init, isInitialized
      • Methods inherited from class java.lang.Object

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

      • RestAuthenticator

        public RestAuthenticator()
      • RestAuthenticator

        public RestAuthenticator​(java.lang.String url)
    • Method Detail

      • internalInit

        protected void internalInit()
        Specified by:
        internalInit in class org.pac4j.core.util.InitializableObject
      • validate

        public void validate​(org.pac4j.core.credentials.Credentials cred,
                             org.pac4j.core.context.WebContext context,
                             org.pac4j.core.context.session.SessionStore sessionStore)
        Specified by:
        validate in interface org.pac4j.core.credentials.authenticator.Authenticator
      • buildProfile

        protected void buildProfile​(org.pac4j.core.credentials.UsernamePasswordCredentials credentials,
                                    java.lang.String body)
      • callRestApi

        protected java.lang.String callRestApi​(java.lang.String username,
                                               java.lang.String password)
        Return the body from the REST API, passing the username/pasword auth. To be overridden using another HTTP client if necessary.
        Parameters:
        username - the username
        password - the password
        Returns:
        the response body
      • getUrl

        public java.lang.String getUrl()
      • setUrl

        public void setUrl​(java.lang.String url)
      • getMapper

        public com.fasterxml.jackson.databind.ObjectMapper getMapper()
      • setMapper

        public void setMapper​(com.fasterxml.jackson.databind.ObjectMapper mapper)
      • toString

        public java.lang.String toString()
        Overrides:
        toString in class java.lang.Object