Package org.apache.shiro.crypto.hash
Class HashRequest.Builder
java.lang.Object
org.apache.shiro.crypto.hash.HashRequest.Builder
- Enclosing interface:
HashRequest
A Builder class representing the Builder design pattern for constructing
HashRequest instances.- Since:
- 1.2
- See Also:
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionaddParameter(String parameterName, Object parameterValue) build()Builds aHashRequestinstance reflecting the specified configuration.setAlgorithmName(String algorithmName) Sets the name of the hash algorithm theHashServiceshould use when computing theHash.Sets a salt to be used by theHashServiceduring hash computation.setSalt(org.apache.shiro.lang.util.ByteSource salt) Sets a salt to be used by theHashServiceduring hash computation.Sets the source data that will be hashed by aHashService.setSource(org.apache.shiro.lang.util.ByteSource source) Sets the source data that will be hashed by aHashService.withParameters(Map<String, Object> parameters)
-
Constructor Details
-
Builder
public Builder()Default no-arg constructor.
-
-
Method Details
-
setSource
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:
-
setSource
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:
-
setSalt
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:
-
setSalt
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:
-
addParameter
-
withParameters
-
setAlgorithmName
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:
-
build
Builds aHashRequestinstance reflecting the specified configuration.- Returns:
- a
HashRequestinstance reflecting the specified configuration.
-