Class KeyMasterServlet

java.lang.Object
javax.servlet.GenericServlet
javax.servlet.http.HttpServlet
com.caplin.signon.KeyMasterServlet
All Implemented Interfaces:
Serializable, javax.servlet.Servlet, javax.servlet.ServletConfig

public class KeyMasterServlet extends javax.servlet.http.HttpServlet

Generates a KeyMaster token using session data saved by the signon servlet.

The servlet can be configured using the following servlet/JNDI parameters:

OptionRequired/OptionalDescription
caplin.keymaster.privatekeyOptionalThe PEM PKCS#8 formatted private key.
caplin.keymaster.privatekey.filenameOptionalThe location of the PEM PKCS#8 formatted private key file relative to the webapp.
caplin.keymaster.hashing.algorithmOptionalHashing algorithm name, see KeyMasterHashingAlgorithm for the possible values, default is SHA256
caplin.keymaster.security.provider.class.nameOptionalClass name of a security provider to add to those available.
caplin.keymaster.security.provider.nameOptionalName of security provider to use for the token generation.
caplin.keymaster.username.fieldOptionalName of the SessionData field that contains the username to generate a KeyMaster token for, default is SessionData.getUserName()

The keymaster token parameters are loaded from the SessionData object stored under the key "caplin.signon" in the servlet session data.

The following SessionData values are used:

 SessionData.getField([caplin.keymaster.username.field]) - or default SessionData.getUserName() - the user name (required)
 SessionData.getKeyMasterExtraDataToSign() - any extra data to sign (optional)
 SessionData.getKeyMasterMappingData() - mapping data to include in the token (optional)
 
See Also:
  • Field Details

    • CAPLIN_KEYMASTER_PRIVATEKEY

      protected static final String CAPLIN_KEYMASTER_PRIVATEKEY
      See Also:
    • CAPLIN_KEYMASTER_PRIVATEKEY_FILENAME

      protected static final String CAPLIN_KEYMASTER_PRIVATEKEY_FILENAME
      See Also:
    • CAPLIN_KEYMASTER_HASHING_ALGORITHM

      protected static final String CAPLIN_KEYMASTER_HASHING_ALGORITHM
      See Also:
    • CAPLIN_KEYMASTER_SECURITY_PROVIDER_CLASS_NAME

      protected static final String CAPLIN_KEYMASTER_SECURITY_PROVIDER_CLASS_NAME
      See Also:
    • CAPLIN_KEYMASTER_SECURITY_PROVIDER_NAME

      protected static final String CAPLIN_KEYMASTER_SECURITY_PROVIDER_NAME
      See Also:
    • CAPLIN_KEYMASTER_USERNAME_FIELD

      protected static final String CAPLIN_KEYMASTER_USERNAME_FIELD
      See Also:
    • keymaster

      protected com.caplin.keymaster.IKeyMaster keymaster
    • formatter

      protected com.caplin.keymaster.StandardFormatter formatter
    • hashingAlgorithm

      protected com.caplin.keymaster.KeyMasterHashingAlgorithm hashingAlgorithm
    • securityProviderName

      protected String securityProviderName
    • privateKeyFilename

      protected String privateKeyFilename
    • usernameField

      protected String usernameField
    • envContext

      protected Context envContext
    • privateKey

      protected String privateKey
  • Constructor Details

    • KeyMasterServlet

      public KeyMasterServlet()
  • Method Details

    • init

      public void init() throws javax.servlet.ServletException
      Overrides:
      init in class javax.servlet.GenericServlet
      Throws:
      javax.servlet.ServletException
    • createKeyMasterConfiguration

      protected com.caplin.keymaster.IKeyMasterConfiguration createKeyMasterConfiguration() throws Exception
      Create the KeyMaster configuration to be used by this servlet
      Returns:
      the KeyMaster configuration to use.
      Throws:
      Exception - thrown if creation fails.
    • createAuthenticationParameters

      protected com.caplin.keymaster.IAuthenticationParameters createAuthenticationParameters(javax.servlet.http.HttpServletRequest request) throws javax.servlet.ServletException
      Creates the authentication parameters from the signon servlet session data.
      Parameters:
      request - the servlet request to create authentication parameters from.
      Returns:
      Authentication parameters for the given request.
      Throws:
      javax.servlet.ServletException - if an error occurs
    • loadServletParameters

      protected void loadServletParameters() throws javax.servlet.ServletException
      Loads the servlet parameters
      Throws:
      javax.servlet.ServletException - if there is a problem loading
    • loadPrivateKey

      public void loadPrivateKey() throws javax.servlet.ServletException
      Throws:
      javax.servlet.ServletException
    • doPost

      protected void doPost(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response) throws IOException, javax.servlet.ServletException
      Overrides:
      doPost in class javax.servlet.http.HttpServlet
      Throws:
      IOException
      javax.servlet.ServletException
    • doGet

      protected void doGet(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response) throws IOException, javax.servlet.ServletException
      Overrides:
      doGet in class javax.servlet.http.HttpServlet
      Throws:
      IOException
      javax.servlet.ServletException
    • writeResponse

      protected void writeResponse(javax.servlet.http.HttpServletResponse response, String responseContent) throws IOException
      Writes servlet response as plain text with no cache headers.
      Parameters:
      response - the servlet response
      responseContent - the text to send
      Throws:
      IOException - if an error occurs
    • getWebappBaseDirectory

      public String getWebappBaseDirectory()
      Gets the base directory for this webapp.
      Returns:
      the base directory.
    • getParameterValue

      public String getParameterValue(String key, String defaultValue)
      Gets the value of a servlet/JNDI parameter or uses a default if the value is not present
      Parameters:
      key - the name of the servlet parameter
      defaultValue - the default value to use if no value is found
      Returns:
      the retrieved value
    • logPrefix

      public String logPrefix(javax.servlet.http.HttpServletRequest req)
      Gets the session id prefix added to all log messages.
      Parameters:
      req - the servlet request object
      Returns:
      the prefix to add to all log messages