java.lang.Object
net.i2p.i2pcontrol.servlets.jsonrpc2handlers.JSONRPC2Helper

public class JSONRPC2Helperextends Object
Helper utility class for I2PControl JSON-RPC2 handlers. Provides common functionality for parameter validation and authentication token verification.
  • Field Details

    • USE_NO_AUTH

      public static final Boolean USE_NO_AUTH
      Token value marking a handler call as needing no authentication.
    • USE_AUTH

      public static final Boolean USE_AUTH
      Token value marking a handler call as needing authentication.
    • _secMan

      private final SecurityManager _secMan
      The manager consulted to validate the token a request carries.
  • Constructor Details

    • JSONRPC2Helper

      public JSONRPC2Helper(SecurityManager secMan)
      JSONRPC2Helper.
      Parameters:
      secMan - SecurityManager consulted when a request carries an authentication token
  • Method Details

    • validateParams

      public JSONRPC2Error validateParams(String[] requiredArgs, JSONRPC2Request req, Boolean useAuth)
      Check incoming request for required arguments, to make sure they are valid.
      Parameters:
      requiredArgs - - Array of names of required arguments. If null don't check for any parameters.
      req - - Incoming JSONRPC2 request
      useAuth - - If true, will validate authentication token.
      Returns:
      - null if no errors were found. Corresponding JSONRPC2Error if error is found.
    • validateParams

      public JSONRPC2Error validateParams(String[] requiredArgs, JSONRPC2Request req)
      Check incoming request for required arguments, to make sure they are valid. Will authenticate req.
      Parameters:
      requiredArgs - - Array of names of required arguments. If null don't check for any parameters.
      req - - Incoming JSONRPC2 request
      Returns:
      - null if no errors were found. Corresponding JSONRPC2Error if error is found.
    • validateToken

      private JSONRPC2Error validateToken(Map<String,Object> params)
      Will check incoming parameters to make sure they contain a valid token.
      Parameters:
      params - - Parameters of incoming request
      Returns:
      null if everything is fine, JSONRPC2Error for any corresponding error.