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 constructingHashRequestinstances.- 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 HashRequestbuild()Builds aHashRequestinstance reflecting the specified configuration.HashRequest.BuildersetAlgorithmName(String algorithmName)Sets the name of the hash algorithm theHashServiceshould use when computing theHash.HashRequest.BuildersetIterations(int iterations)Sets the number of requested hash iterations to be performed when computing the finalHashresult.HashRequest.BuildersetSalt(Object salt)Sets a salt to be used by theHashServiceduring hash computation.HashRequest.BuildersetSalt(org.apache.shiro.util.ByteSource salt)Sets a salt to be used by theHashServiceduring hash computation.HashRequest.BuildersetSource(Object source)Sets the source data that will be hashed by aHashService.HashRequest.BuildersetSource(org.apache.shiro.util.ByteSource source)Sets the source data that will be hashed by aHashService.
-
-
-
Method Detail
-
setSource
public HashRequest.Builder setSource(org.apache.shiro.util.ByteSource source)
Sets the source data that will be hashed by aHashService. For example, this might be aByteSourcerepresentation of a password, or file, etc.- Parameters:
source- the source data that will be hashed by aHashService.- Returns:
- this
Builderinstance 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 aByteSourceinstance using Shiro's default conversion heuristics (as defined byByteSource.Util.isCompatible. If the object cannot be heuristically converted to aByteSource, anIllegalArgumentExceptionwill be thrown.- Parameters:
source- the byte-backed source data that will be hashed by aHashService.- Returns:
- this
Builderinstance for method chaining. - Throws:
IllegalArgumentException- if the argument cannot be heuristically converted to aByteSourceinstance.- See Also:
HashRequest.getSource(),setSource(ByteSource)
-
setSalt
public HashRequest.Builder setSalt(org.apache.shiro.util.ByteSource salt)
Sets a salt to be used by theHashServiceduring 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 servicingHashServiceis free to provide a salting strategy for a request, even if the request did not specify one. You can always check the resultHashgetSalt()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 theHashServiceduring hash computation- Returns:
- this
Builderinstance for method chaining. - See Also:
HashRequest.getSalt()
-
setSalt
public HashRequest.Builder setSalt(Object salt) throws IllegalArgumentException
Sets a salt to be used by theHashServiceduring hash computation. This is a convenience alternative tosetSalt(ByteSource): it will attempt to convert the argument into aByteSourceinstance using Shiro's default conversion heuristics (as defined byByteSource.Util.isCompatible. If the object cannot be heuristically converted to aByteSource, anIllegalArgumentExceptionwill be thrown.- Parameters:
salt- a salt to be used by theHashServiceduring hash computation.- Returns:
- this
Builderinstance for method chaining. - Throws:
IllegalArgumentException- if the argument cannot be heuristically converted to aByteSourceinstance.- 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 finalHashresult. 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 aHashServiceis 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 resultHashgetIterations()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 finalHashresult.- Returns:
- this
Builderinstance for method chaining. - See Also:
HashRequest.getIterations()
-
setAlgorithmName
public HashRequest.Builder setAlgorithmName(String algorithmName)
Sets the name of the hash algorithm theHashServiceshould use when computing theHash. Not calling this method or setting it tonullindicates the the default algorithm configuration of theHashServiceshould be used. A non-null value overrides theHashService's configuration for a single request. Note that aHashServiceis 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 resultHashgetAlgorithmName()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 theHashServiceshould use when computing theHash, ornullif the default algorithm configuration of theHashServiceshould be used.- Returns:
- this
Builderinstance for method chaining. - See Also:
HashRequest.getAlgorithmName()
-
build
public HashRequest build()
Builds aHashRequestinstance reflecting the specified configuration.- Returns:
- a
HashRequestinstance reflecting the specified configuration.
-
-