Package org.apache.shiro.crypto.hash
Class HashRequest.Builder
- java.lang.Object
-
- org.apache.shiro.crypto.hash.HashRequest.Builder
-
- Enclosing interface:
- HashRequest
public static class HashRequest.Builder extends Object
A Builder class representing the Builder design pattern for constructingHashRequest
instances.- Since:
- 1.2
- See Also:
SimpleHashRequest
-
-
Constructor Summary
Constructors Constructor Description Builder()
Default no-arg constructor.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description HashRequest
build()
Builds aHashRequest
instance reflecting the specified configuration.HashRequest.Builder
setAlgorithmName(String algorithmName)
Sets the name of the hash algorithm theHashService
should use when computing theHash
.HashRequest.Builder
setIterations(int iterations)
Sets the number of requested hash iterations to be performed when computing the finalHash
result.HashRequest.Builder
setSalt(Object salt)
Sets a salt to be used by theHashService
during hash computation.HashRequest.Builder
setSalt(ByteSource salt)
Sets a salt to be used by theHashService
during hash computation.HashRequest.Builder
setSource(Object source)
Sets the source data that will be hashed by aHashService
.HashRequest.Builder
setSource(ByteSource source)
Sets the source data that will be hashed by aHashService
.
-
-
-
Constructor Detail
-
Builder
public Builder()
Default no-arg constructor.
-
-
Method Detail
-
setSource
public HashRequest.Builder setSource(ByteSource source)
Sets the source data that will be hashed by aHashService
. For example, this might be aByteSource
representation of a password, or file, etc.- Parameters:
source
- the source data that will be hashed by aHashService
.- Returns:
- this
Builder
instance for method chaining. - See Also:
HashRequest.getSource()
,setSource(Object)
-
setSource
public HashRequest.Builder setSource(Object source) throws IllegalArgumentException
Sets the source data that will be hashed by aHashService
. This is a convenience alternative tosetSource(ByteSource)
: it will attempt to convert the argument into aByteSource
instance using Shiro's default conversion heuristics (as defined byByteSource.Util.isCompatible
. If the object cannot be heuristically converted to aByteSource
, anIllegalArgumentException
will be thrown.- Parameters:
source
- the byte-backed source data that will be hashed by aHashService
.- Returns:
- this
Builder
instance for method chaining. - Throws:
IllegalArgumentException
- if the argument cannot be heuristically converted to aByteSource
instance.- See Also:
HashRequest.getSource()
,setSource(ByteSource)
-
setSalt
public HashRequest.Builder setSalt(ByteSource salt)
Sets a salt to be used by theHashService
during hash computation. NOTE: not calling this method does not necessarily mean a salt won't be used at all - it just means that the request didn't include a salt. The servicingHashService
is free to provide a salting strategy for a request, even if the request did not specify one. You can always check the resultHash
getSalt()
method to see what the actual salt was (if any), which may or may not match this request salt.- Parameters:
salt
- a salt to be used by theHashService
during hash computation- Returns:
- this
Builder
instance for method chaining. - See Also:
HashRequest.getSalt()
-
setSalt
public HashRequest.Builder setSalt(Object salt) throws IllegalArgumentException
Sets a salt to be used by theHashService
during hash computation. This is a convenience alternative tosetSalt(ByteSource)
: it will attempt to convert the argument into aByteSource
instance using Shiro's default conversion heuristics (as defined byByteSource.Util.isCompatible
. If the object cannot be heuristically converted to aByteSource
, anIllegalArgumentException
will be thrown.- Parameters:
salt
- a salt to be used by theHashService
during hash computation.- Returns:
- this
Builder
instance for method chaining. - Throws:
IllegalArgumentException
- if the argument cannot be heuristically converted to aByteSource
instance.- See Also:
setSalt(ByteSource)
,HashRequest.getSalt()
-
setIterations
public HashRequest.Builder setIterations(int iterations)
Sets the number of requested hash iterations to be performed when computing the finalHash
result. Not calling this method or setting a non-positive value (0 or less) indicates that theHashService
's default iteration configuration should be used. A positive value overrides theHashService
's configuration for a single request. Note that aHashService
is free to ignore this number if it determines the number is not sufficient to meet a desired level of security. You can always check the resultHash
getIterations()
method to see what the actual number of iterations was, which may or may not match this request salt.- Parameters:
iterations
- the number of requested hash iterations to be performed when computing the finalHash
result.- Returns:
- this
Builder
instance for method chaining. - See Also:
HashRequest.getIterations()
-
setAlgorithmName
public HashRequest.Builder setAlgorithmName(String algorithmName)
Sets the name of the hash algorithm theHashService
should use when computing theHash
. Not calling this method or setting it tonull
indicates the the default algorithm configuration of theHashService
should be used. A non-null value overrides theHashService
's configuration for a single request. Note that aHashService
is free to ignore this value if it determines that the algorithm is not sufficient to meet a desired level of security. You can always check the resultHash
getAlgorithmName()
method to see what the actual algorithm was, which may or may not match this request salt.- Parameters:
algorithmName
- the name of the hash algorithm theHashService
should use when computing theHash
, ornull
if the default algorithm configuration of theHashService
should be used.- Returns:
- this
Builder
instance for method chaining. - See Also:
HashRequest.getAlgorithmName()
-
build
public HashRequest build()
Builds aHashRequest
instance reflecting the specified configuration.- Returns:
- a
HashRequest
instance reflecting the specified configuration.
-
-