Class MongoSessionSecret

java.lang.Object
dev.getelements.elements.dao.mongo.model.MongoSessionSecret

public class MongoSessionSecret extends Object
A type used to wrap up a securely generated key to use as an ID for a MongoSession.
  • Field Details

    • SESSION_ID_LENGTH

      public static final int SESSION_ID_LENGTH
      The number of bytes that make up a session secret.
      See Also:
    • SESSION_CHECKSUM_LENGTH

      public static final int SESSION_CHECKSUM_LENGTH
      The number of bytes that make up the session secret checksum header.
      See Also:
    • SECRET_HEADER_LENGTH

      public static final int SECRET_HEADER_LENGTH
      Represents the secret total length.
      See Also:
  • Constructor Details

    • MongoSessionSecret

      public MongoSessionSecret(org.bson.types.ObjectId objectId)
      Initializes a context-based MongoSessionSecret using an ObjectId as a context. The supplied ObjectId may be retrieved later to be used as a means to identify what created the MongoSessionSecret.
      Parameters:
      objectId - the ObjectId.
    • MongoSessionSecret

      public MongoSessionSecret(byte[] context)
      Initializes a context-based MongoSessionSecret. The context is an extra set of bytes used to append some sort if identity to a particular MongoSessionSecret. This can be, for example, an ObjectId for a MongoUser.
      Parameters:
      context -
    • MongoSessionSecret

      public MongoSessionSecret(String sessionSecret)
  • Method Details

    • getSessionSecret

      public String getSessionSecret()
      Gets the raw secret value as determined suitable for use in SessionCreation.setSessionSecret(String). Take care that the returned value is a secret and should not be logged or transmitted over an untrusted network in plain text.
      Returns:
      the secret token
    • getContext

      public byte[] getContext()
      Returns the context used to create this MongoSessionSecret. See the notes on MongoSessionSecret(byte[]) for what a context is.
      Returns:
      the context bytes
    • getContextAsObjectId

      public org.bson.types.ObjectId getContextAsObjectId()
      Reads the context of this MongoSessionSecret and parses it as an ObjectId using ObjectId(byte[]).
      Returns:
      the context as ObjectId
    • getSecretDigest

      public byte[] getSecretDigest(MessageDigest messageDigest, byte[] salt)
      Gets a digest version of this MongoSessionSecret using the provided MessageDigest. This allows the MongoSessionSecret to be stored as a hash key in the database.
      Parameters:
      messageDigest - the MessageDigest used to calcualte the hash
      salt - a value to prepend to the digest before generation
      Returns:
      the secret hash
    • getSecretDigestEncoded

      public String getSecretDigestEncoded(MessageDigest messageDigest, byte[] salt)
      Base64 encodes the secret digest using getSecretDigestEncoded(MessageDigest, byte[]) and returns the result.
      Parameters:
      messageDigest - the MessageDigest instance.
      salt - a value to prepend to the digest before generation
      Returns:
      the secret hash