org.pfsw.security.oauth.pkce
Class AbstractPKCEGenerator

java.lang.Object
  extended by org.pfsw.security.oauth.pkce.AbstractPKCEGenerator
All Implemented Interfaces:
PKCEGenerator
Direct Known Subclasses:
PlainPKCEGenerator, S256PKCEGenerator

public abstract class AbstractPKCEGenerator
extends java.lang.Object
implements PKCEGenerator

A customizable generic implementation of a PKCEGenerator where subclasses determine what code challenge method to be used and how to generate that data.


Constructor Summary
AbstractPKCEGenerator(CodeChallengeMethod codeChallengeMethod)
          Creates a new instance for the given code challenge method and a default random string generator and true for createBase64EncodedCodeVerifiers.
AbstractPKCEGenerator(CodeChallengeMethod codeChallengeMethod, org.pfsw.text.StringGenerator randomStringGenerator)
          Creates a new instance with the given arguments.
 
Method Summary
protected abstract  java.lang.String createCodeChallenge(java.lang.String codeVerifier)
          Returns the derived code challenge string for the given code verifier by applying the getCodeChallengeMethod().
 ProofKeyForCodeExchange generate()
          Generates a new random ProofKeyForCodeExchange.
protected  java.lang.String generateRandomCodeVerifier()
          Returns a new random string to be used as code verifier.
 CodeChallengeMethod getCodeChallengeMethod()
          Returns the code challenge method this generator is using to create the code challenge.
protected  org.pfsw.text.StringGenerator getRandomStringGenerator()
          Returns the generator for random strings.
 java.lang.String toString()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

AbstractPKCEGenerator

public AbstractPKCEGenerator(CodeChallengeMethod codeChallengeMethod)
Creates a new instance for the given code challenge method and a default random string generator and true for createBase64EncodedCodeVerifiers.

Parameters:
codeChallengeMethod - The mechanism to be used for deriving the code challenge from the code verifier (must not be null).

AbstractPKCEGenerator

public AbstractPKCEGenerator(CodeChallengeMethod codeChallengeMethod,
                             org.pfsw.text.StringGenerator randomStringGenerator)
Creates a new instance with the given arguments.

Parameters:
codeChallengeMethod - The mechanism to be used for deriving the code challenge from the code verifier (must not be null).
randomStringGenerator - A string generator that produces a different string for each invocation (must not be null). It will be used to generate new code verifier strings.
Method Detail

generate

public ProofKeyForCodeExchange generate()
Description copied from interface: PKCEGenerator
Generates a new random ProofKeyForCodeExchange. The mechanism how the random code verifier gets generated and the used code challenge method is up to the implementor of this method.

Specified by:
generate in interface PKCEGenerator

getCodeChallengeMethod

public CodeChallengeMethod getCodeChallengeMethod()
Returns the code challenge method this generator is using to create the code challenge.


toString

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

generateRandomCodeVerifier

protected java.lang.String generateRandomCodeVerifier()
Returns a new random string to be used as code verifier. The generated string must conform to the specification https://tools.ietf.org/html/rfc7636#section-4.1

This method provides a default string generation mechanism that can be overridden by subclasses if needed, but usually the better approach for customization is providing a different StringGenerator during instance creation.


getRandomStringGenerator

protected org.pfsw.text.StringGenerator getRandomStringGenerator()
Returns the generator for random strings.


createCodeChallenge

protected abstract java.lang.String createCodeChallenge(java.lang.String codeVerifier)
Returns the derived code challenge string for the given code verifier by applying the getCodeChallengeMethod().

Parameters:
codeVerifier - The newly created random code verifier.
Returns:
The calculated code challenge.