Class SimpleHashRequest

java.lang.Object
org.apache.shiro.crypto.hash.SimpleHashRequest
All Implemented Interfaces:
HashRequest

public class SimpleHashRequest extends Object implements HashRequest
Simple implementation of HashRequest that can be used when interacting with a HashService.
Since:
1.2
  • Constructor Details

    • SimpleHashRequest

      public SimpleHashRequest(String algorithmName, org.apache.shiro.lang.util.ByteSource source, org.apache.shiro.lang.util.ByteSource salt, Map<String,Object> parameters)
      Creates a new SimpleHashRequest instance.
      Parameters:
      algorithmName - the name of the hash algorithm to use. This is often null as the HashService implementation is usually configured with an appropriate algorithm name, but this can be non-null if the hash service's algorithm should be overridden with a specific one for the duration of the request.
      source - the source to be hashed
      salt - any public salt which should be used when computing the hash
      parameters - e.g. the number of hash iterations to execute or other parameters.
      Throws:
      NullPointerException - if source is null or empty or parameters is null.
  • Method Details

    • getSource

      public org.apache.shiro.lang.util.ByteSource getSource()
      Description copied from interface: HashRequest
      Returns the source data that will be hashed by a HashService. For example, this might be a ByteSource representation of a password, or file, etc.
      Specified by:
      getSource in interface HashRequest
      Returns:
      the source data that will be hashed by a HashService.
    • getSalt

      public Optional<org.apache.shiro.lang.util.ByteSource> getSalt()
      Description copied from interface: HashRequest
      Returns a salt to be used by the HashService during hash computation, or null if no salt is provided as part of the request.

      Note that a null value does not necessarily mean a salt won't be used at all - it just means that the request didn't include one. The servicing HashService is free to provide a salting strategy for a request, even if the request did not specify one.

      Specified by:
      getSalt in interface HashRequest
      Returns:
      a salt to be used by the HashService during hash computation, or null if no salt is provided as part of the request.
    • getAlgorithmName

      public Optional<String> getAlgorithmName()
      Description copied from interface: HashRequest
      Returns 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. 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.

      Specified by:
      getAlgorithmName in interface HashRequest
      Returns:
      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.
    • getParameters

      public Map<String,Object> getParameters()
      Description copied from interface: HashRequest
      Returns various parameters for the requested hash.

      If the map is empty for a specific parameter, the implementation must select the default.

      Implementations should provide a nested .Parameters class with public static final Strings for convenience.

      Example parameters the number of requested hash iterations (does not apply to bcrypt), memory and cpu constrains, etc. Please find their specific names in the implementation’s nested .Parameters class.

      Specified by:
      getParameters in interface HashRequest
      Returns:
      the parameters for the requested hash to be used when computing the final Hash result.