Package com.exedio.cope.pattern
Class Hash
- java.lang.Object
-
- com.exedio.cope.Feature
-
- com.exedio.cope.Pattern
-
- com.exedio.cope.pattern.Hash
-
- All Implemented Interfaces:
HashInterface
,Settable<String>
,Serializable
- Direct Known Subclasses:
MD5Hash
,MessageDigestHash
,SHAHash
public class Hash extends Pattern implements HashInterface
- See Also:
- Serialized Form
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static interface
Hash.Algorithm
static class
Hash.InvalidPlainTextException
A plain text is either too short, too long or doesn't match the format requirementstatic class
Hash.PlainTextValidator
Validate plain text for potential limits, to be specified in sub classes
-
Constructor Summary
Constructors Constructor Description Hash(Hash.Algorithm algorithm)
Hash(Hash.Algorithm algorithm, String encoding)
Deprecated.UseHash(Algorithm, Charset)
insteadHash(Hash.Algorithm algorithm, Charset charset)
Hash(HashAlgorithm algorithm)
Hash(StringField storage, Hash.Algorithm algorithm)
Hash(StringField storage, Hash.Algorithm algorithm, String encoding)
Deprecated.UseHash(StringField, Algorithm, Charset)
insteadHash(StringField storage, Hash.Algorithm algorithm, Charset charset)
Hash(StringField storage, HashAlgorithm algorithm)
-
Method Summary
All Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description void
blind(Class<? extends Item> parentClass, String actualPlainText)
Deprecated.Useblind(String)
instead.void
blind(String actualPlainText)
Wastes (almost) as much cpu cycles, as a call tocheck(Item, String)
would have needed.boolean
check(Item item, String actualPlainText)
void
checkPlainText(String plainText)
SetValue<?>[]
execute(String value, Item exceptionItem)
Hash.Algorithm
getAlgorithm()
Deprecated.UsegetAlgorithm2()
instead.HashAlgorithm
getAlgorithm2()
String
getAlgorithmID()
String
getAlgorithmName()
Deprecated.UsegetAlgorithmID()
insteadString
getEncoding()
Deprecated.Throws exception if not initialized viaHash.Algorithm
.String
getHash(Item item)
Set<Class<? extends Throwable>>
getInitialExceptions()
Returns the exceptions possibly thrown, when setting a value for this settable.Class<?>
getInitialType()
int
getPlainTextLimit()
Hash.PlainTextValidator
getPlainTextValidator()
StringField
getStorage()
String
hash(String plainText)
boolean
isFinal()
Returns true, if a value for the settable can be specified on the creation of an item only, thus cannot be modified later.boolean
isInitial()
Returns true, if a value for the settable should be specified on the creation of an item.boolean
isMandatory()
Condition
isNotNull()
Condition
isNotNull(Join join)
Condition
isNull()
boolean
isNull(Item item)
Condition
isNull(Join join)
Hash
limit(int plainTextLimit)
Creates a new hash with a new plain text limit.String
newRandomPassword(SecureRandom random)
Hash
optional()
void
set(Item item, String plainText)
void
setHash(Item item, String hash)
Hash
toFinal()
Hash
validate(Hash.PlainTextValidator validator)
-
Methods inherited from class com.exedio.cope.Pattern
addSource, addSource, addSource, addSource, addSourceFeature, addSourceFeature, addSourceFeature, annotationField, equals, getGeneratedTypes, getSourceFeatures, getSourceFeaturesGather, getSourceFields, getSources, getSourceTypes, getType, hashCode, initialize, newSourceType, newSourceType, newSourceType, newSourceType, newSourceType, newSourceType, newType, newType, onMount, registerSource
-
Methods inherited from class com.exedio.cope.Feature
afterModelCreated, getAbstractType, getAnnotation, getID, getLocalizationKeys, getName, getPattern, isAnnotationPresent, isSourceAlready, mount, readResolve, requireMounted, toString, toString, writeReplace
-
-
-
-
Constructor Detail
-
Hash
public Hash(StringField storage, Hash.Algorithm algorithm, Charset charset)
-
Hash
public Hash(StringField storage, Hash.Algorithm algorithm)
-
Hash
public Hash(Hash.Algorithm algorithm, Charset charset)
-
Hash
public Hash(Hash.Algorithm algorithm)
-
Hash
public Hash(HashAlgorithm algorithm)
-
Hash
public Hash(StringField storage, HashAlgorithm algorithm)
-
Hash
@Deprecated public Hash(StringField storage, Hash.Algorithm algorithm, String encoding)
Deprecated.UseHash(StringField, Algorithm, Charset)
instead
-
Hash
@Deprecated public Hash(Hash.Algorithm algorithm, String encoding)
Deprecated.UseHash(Algorithm, Charset)
instead
-
-
Method Detail
-
getStorage
public final StringField getStorage()
-
getPlainTextLimit
public final int getPlainTextLimit()
- See Also:
limit(int)
-
getAlgorithm2
public final HashAlgorithm getAlgorithm2()
-
getAlgorithmID
public final String getAlgorithmID()
-
getEncoding
@Deprecated public final String getEncoding()
Deprecated.Throws exception if not initialized viaHash.Algorithm
.
-
getPlainTextValidator
public final Hash.PlainTextValidator getPlainTextValidator()
- See Also:
validate(PlainTextValidator)
-
isInitial
public final boolean isInitial()
Description copied from interface:Settable
Returns true, if a value for the settable should be specified on the creation of an item.
-
isFinal
public final boolean isFinal()
Description copied from interface:Settable
Returns true, if a value for the settable can be specified on the creation of an item only, thus cannot be modified later.
-
isMandatory
public final boolean isMandatory()
- Specified by:
isMandatory
in interfaceSettable<String>
-
getInitialType
public final Class<?> getInitialType()
- Specified by:
getInitialType
in interfaceSettable<String>
-
getInitialExceptions
public final Set<Class<? extends Throwable>> getInitialExceptions()
Description copied from interface:Settable
Returns the exceptions possibly thrown, when setting a value for this settable.- Specified by:
getInitialExceptions
in interfaceSettable<String>
-
toFinal
public final Hash toFinal()
-
optional
public final Hash optional()
-
limit
public final Hash limit(int plainTextLimit)
Creates a new hash with a new plain text limit. The default is 150. Setting hashes longer than the limit will cause anHash.InvalidPlainTextException
.Checking
for hashes longer than the limit will silently return false. This is a precaution against DOS attacks with very long plain texts.- See Also:
getPlainTextLimit()
-
validate
public final Hash validate(Hash.PlainTextValidator validator)
- See Also:
getPlainTextValidator()
-
set
public final void set(@Nonnull Item item, String plainText)
- Specified by:
set
in interfaceHashInterface
-
check
public final boolean check(@Nonnull Item item, @Nullable String actualPlainText)
- Specified by:
check
in interfaceHashInterface
-
isNull
public final boolean isNull(@Nonnull Item item)
- Specified by:
isNull
in interfaceHashInterface
-
blind
public final void blind(@Nullable String actualPlainText)
Wastes (almost) as much cpu cycles, as a call tocheck(Item, String)
would have needed. Needed to prevent Timing Attacks. See https://en.wikipedia.org/wiki/Timing_attack- Specified by:
blind
in interfaceHashInterface
-
execute
public final SetValue<?>[] execute(String value, Item exceptionItem) throws Hash.InvalidPlainTextException
- Specified by:
execute
in interfaceSettable<String>
- Throws:
Hash.InvalidPlainTextException
-
getHash
public final String getHash(@Nonnull Item item)
- Specified by:
getHash
in interfaceHashInterface
-
checkPlainText
public final void checkPlainText(String plainText)
-
isNull
public final Condition isNull()
-
isNotNull
public final Condition isNotNull()
-
newRandomPassword
public final String newRandomPassword(SecureRandom random)
- Specified by:
newRandomPassword
in interfaceHashInterface
-
getAlgorithmName
@Deprecated public final String getAlgorithmName()
Deprecated.UsegetAlgorithmID()
instead
-
getAlgorithm
@Deprecated public final Hash.Algorithm getAlgorithm()
Deprecated.UsegetAlgorithm2()
instead. Throws exception if not initialized viaHash.Algorithm
.
-
blind
@Deprecated public final void blind(Class<? extends Item> parentClass, String actualPlainText)
Deprecated.Useblind(String)
instead.
-
-