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 constructing HashRequest instances.
Since:
1.2
See Also:
  • Constructor Details

    • Builder

      public Builder()
      Default no-arg constructor.
  • Method Details

    • setSource

      public HashRequest.Builder setSource(org.apache.shiro.lang.util.ByteSource source)
      Sets the source data that will be hashed by a HashService. For example, this might be a ByteSource representation of a password, or file, etc.
      Parameters:
      source - the source data that will be hashed by a HashService.
      Returns:
      this Builder instance for method chaining.
      See Also:
    • setSource

      public HashRequest.Builder setSource(Object source) throws IllegalArgumentException
      Sets the source data that will be hashed by a HashService.

      This is a convenience alternative to setSource(ByteSource): it will attempt to convert the argument into a ByteSource instance using Shiro's default conversion heuristics (as defined by ByteSource.Util.isCompatible. If the object cannot be heuristically converted to a ByteSource, an IllegalArgumentException will be thrown.

      Parameters:
      source - the byte-backed source data that will be hashed by a HashService.
      Returns:
      this Builder instance for method chaining.
      Throws:
      IllegalArgumentException - if the argument cannot be heuristically converted to a ByteSource instance.
      See Also:
    • setSalt

      public HashRequest.Builder setSalt(org.apache.shiro.lang.util.ByteSource salt)
      Sets a salt to be used by the HashService 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 servicing HashService is free to provide a salting strategy for a request, even if the request did not specify one. You can always check the result Hash 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 the HashService during hash computation
      Returns:
      this Builder instance for method chaining.
      See Also:
    • setSalt

      public HashRequest.Builder setSalt(Object salt) throws IllegalArgumentException
      Sets a salt to be used by the HashService during hash computation.

      This is a convenience alternative to setSalt(ByteSource): it will attempt to convert the argument into a ByteSource instance using Shiro's default conversion heuristics (as defined by ByteSource.Util.isCompatible. If the object cannot be heuristically converted to a ByteSource, an IllegalArgumentException will be thrown.

      Parameters:
      salt - a salt to be used by the HashService during hash computation.
      Returns:
      this Builder instance for method chaining.
      Throws:
      IllegalArgumentException - if the argument cannot be heuristically converted to a ByteSource instance.
      See Also:
    • addParameter

      public HashRequest.Builder addParameter(String parameterName, Object parameterValue)
    • withParameters

      public HashRequest.Builder withParameters(Map<String,Object> parameters)
    • setAlgorithmName

      public HashRequest.Builder setAlgorithmName(String algorithmName)
      Sets the name of the hash algorithm the HashService should use when computing the Hash. Not calling this method or setting it to null indicates the the default algorithm configuration of the HashService should be used. A non-null value overrides the HashService's configuration for a single request.

      Note that a HashService 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 result Hash 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 the HashService should use when computing the Hash, or null if the default algorithm configuration of the HashService should be used.
      Returns:
      this Builder instance for method chaining.
      See Also:
    • build

      public HashRequest build()
      Builds a HashRequest instance reflecting the specified configuration.
      Returns:
      a HashRequest instance reflecting the specified configuration.