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 intRepresents the secret total length.static final intThe number of bytes that make up the session secret checksum header.static final intThe 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-basedMongoSessionSecretusing anObjectIdas a context. -
Method Summary
Modifier and TypeMethodDescriptionbyte[]Returns the context used to create thisMongoSessionSecret.org.bson.types.ObjectIdbyte[]getSecretDigest(MessageDigest messageDigest, byte[] salt) Gets a digest version of thisMongoSessionSecretusing 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-basedMongoSessionSecretusing anObjectIdas a context. The suppliedObjectIdmay 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, anObjectIdfor 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 thisMongoSessionSecretusing the providedMessageDigest. This allows theMongoSessionSecretto be stored as a hash key in the database.- Parameters:
messageDigest- theMessageDigestused 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- theMessageDigestinstance.salt- a value to prepend to the digest before generation- Returns:
- the secret hash
-