Class MongoSessionSecret
java.lang.Object
dev.getelements.elements.dao.mongo.model.MongoSessionSecret
A type used to wrap up a securely generated key to use as an ID for a
MongoSession
.-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final int
Represents the secret total length.static final int
The number of bytes that make up the session secret checksum header.static final int
The number of bytes that make up a session secret. -
Constructor Summary
ConstructorsConstructorDescriptionMongoSessionSecret
(byte[] context) Initializes a context-basedMongoSessionSecret
.MongoSessionSecret
(String sessionSecret) MongoSessionSecret
(org.bson.types.ObjectId objectId) Initializes a context-basedMongoSessionSecret
using anObjectId
as a context. -
Method Summary
Modifier and TypeMethodDescriptionbyte[]
Returns the context used to create thisMongoSessionSecret
.org.bson.types.ObjectId
byte[]
getSecretDigest
(MessageDigest messageDigest, byte[] salt) Gets a digest version of thisMongoSessionSecret
using the providedMessageDigest
.getSecretDigestEncoded
(MessageDigest messageDigest, byte[] salt) Base64 encodes the secret digest usinggetSecretDigestEncoded(MessageDigest, byte[])
and returns the result.Gets the raw secret value as determined suitable for use inSessionCreation.setSessionSecret(String)
.
-
Field Details
-
SESSION_ID_LENGTH
public static final int SESSION_ID_LENGTHThe number of bytes that make up a session secret.- See Also:
-
SESSION_CHECKSUM_LENGTH
public static final int SESSION_CHECKSUM_LENGTHThe number of bytes that make up the session secret checksum header.- See Also:
-
SECRET_HEADER_LENGTH
public static final int SECRET_HEADER_LENGTHRepresents the secret total length.- See Also:
-
-
Constructor Details
-
MongoSessionSecret
public MongoSessionSecret(org.bson.types.ObjectId objectId) Initializes a context-basedMongoSessionSecret
using anObjectId
as a context. The suppliedObjectId
may be retrieved later to be used as a means to identify what created theMongoSessionSecret
.- Parameters:
objectId
- theObjectId
.
-
MongoSessionSecret
public MongoSessionSecret(byte[] context) Initializes a context-basedMongoSessionSecret
. The context is an extra set of bytes used to append some sort if identity to a particularMongoSessionSecret
. This can be, for example, anObjectId
for aMongoUser
.- Parameters:
context
-
-
MongoSessionSecret
-
-
Method Details
-
getSessionSecret
Gets the raw secret value as determined suitable for use inSessionCreation.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 thisMongoSessionSecret
. See the notes onMongoSessionSecret(byte[])
for what a context is.- Returns:
- the context bytes
-
getContextAsObjectId
public org.bson.types.ObjectId getContextAsObjectId()- Returns:
- the context as
ObjectId
-
getSecretDigest
Gets a digest version of thisMongoSessionSecret
using the providedMessageDigest
. This allows theMongoSessionSecret
to be stored as a hash key in the database.- Parameters:
messageDigest
- theMessageDigest
used to calcualte the hashsalt
- a value to prepend to the digest before generation- Returns:
- the secret hash
-
getSecretDigestEncoded
Base64 encodes the secret digest usinggetSecretDigestEncoded(MessageDigest, byte[])
and returns the result.- Parameters:
messageDigest
- theMessageDigest
instance.salt
- a value to prepend to the digest before generation- Returns:
- the secret hash
-