Class JsonProtectionInterceptor

java.lang.Object
com.predic8.membrane.core.interceptor.AbstractInterceptor
com.predic8.membrane.core.interceptor.json.JsonProtectionInterceptor
All Implemented Interfaces:
Interceptor

public class JsonProtectionInterceptor extends AbstractInterceptor
Enforces JSON restrictions in requests
  • Constructor Details

    • JsonProtectionInterceptor

      public JsonProtectionInterceptor()
  • Method Details

    • init

      public void init() throws Exception
      Description copied from class: AbstractInterceptor
      Called after parsing is complete and this has been added to the object tree (whose root is Router).
      Overrides:
      init in class AbstractInterceptor
      Throws:
      Exception
    • handleRequest

      public Outcome handleRequest(Exchange exc) throws Exception
      Specified by:
      handleRequest in interface Interceptor
      Overrides:
      handleRequest in class AbstractInterceptor
      Throws:
      Exception
    • getMaxTokens

      public int getMaxTokens()
    • setReportError

      public void setReportError(boolean reportError)
      Parameters:
      reportError -
      Default
      null
      Description
      Overwrites default error reporting behaviour. If set to true, errors will provide ProblemDetails body, if set to false, errors will throw standard exceptions.
    • getReportError

      public Boolean getReportError()
    • setMaxTokens

      public void setMaxTokens(int maxTokens)
      Parameters:
      maxTokens -
      Default
      10000
      Description
      Maximum number of tokens a JSON document may consist of. For example, {"a":"b"} counts as 3.
    • getMaxSize

      public int getMaxSize()
    • setMaxSize

      public void setMaxSize(int maxSize)
      Parameters:
      maxSize -
      Default
      52428800
      Description
      Maximum total size of the JSON document in bytes.
    • getMaxDepth

      public int getMaxDepth()
    • setMaxDepth

      public void setMaxDepth(int maxDepth)
      Parameters:
      maxDepth -
      Default
      50
      Description
      Maximum depth of nested JSON structures. For example, {"a":{"b":{"c":"d"}}} has a depth of 3.
    • getMaxStringLength

      public int getMaxStringLength()
    • setMaxStringLength

      public void setMaxStringLength(int maxStringLength)
      Parameters:
      maxStringLength -
      Default
      262144
      Description
      Maximum string length. For example, {"abcd": "efgh", "ijkl": [ "mnop" ], "qrst": { "uvwx": 1}} has a maximum string length of 4. (In this example, all 6 strings effectively have length 4.)

      The maximum string length also affects keys ("abcd", "ijkl", "qrst" and "uvwx" in the example). The keys can be also limited by the separate property maxKeyLength. The stricter limit applies.

    • getMaxKeyLength

      public int getMaxKeyLength()
    • setMaxKeyLength

      public void setMaxKeyLength(int maxKeyLength)
      Parameters:
      maxKeyLength -
      Default
      256
      Description
      Maximum key length. For example, {"abcd": "efgh123", "ijkl": [ "mnop123" ], "qrst": { "uvwx": 1}} has a maximum key length of 4. (In this example, all 4 strings used as keys effectively have length 4.)

      The maximum key length also affects strings ("abcd", "ijkl", "qrst" and "uvwx" in the example). The strings can be also limited by the separate property maxStringLength. The stricter limit applies.

    • getMaxObjectSize

      public int getMaxObjectSize()
    • setMaxObjectSize

      public void setMaxObjectSize(int maxObjectSize)
      Parameters:
      maxObjectSize -
      Default
      1000
      Description
      Maximum size of JSON objects. For example, {"a": {"b":"c", "d": "e"}, "f": "g"} has a maximum object size of 2. (In this example, both objects effectively have a size of 2.)
    • getMaxArraySize

      public int getMaxArraySize()
    • setMaxArraySize

      public void setMaxArraySize(int maxArraySize)
      Parameters:
      maxArraySize -
      Default
      1000
      Description
      Maximum size of JSON objects. For example, {"a": {"b":"c", "d": "e"}, "f": "g"} has a maximum object size of 2. (In this example, both objects effectively have a size of 2.)
    • getShortDescription

      public String getShortDescription()
      Specified by:
      getShortDescription in interface Interceptor
      Overrides:
      getShortDescription in class AbstractInterceptor
    • getLongDescription

      public String getLongDescription()
      Specified by:
      getLongDescription in interface Interceptor
      Overrides:
      getLongDescription in class AbstractInterceptor