【问题标题】:Use of ESAPI getValidInput methodESAPI getValidInput 方法的使用
【发布时间】:2014-03-26 14:26:10
【问题描述】:

我无法使用 ESAPI 类下的 of 方法'

    java.lang.String getValidInput(java.lang.String context,
                                  java.lang.String input,
                                  java.lang.String type,
                                  int maxLength,
                                  boolean allowNull)
                                      throws ValidationException,
                                       IntrusionException

      Parameters:
         type - The regular expression name that maps to the actual regular expression from "ESAPI.properties". 

如何从ESAPI.properties 文件中传递参数类型? 有什么例子可以使用我可以参考的属性文件值吗?

【问题讨论】:

    标签: java esapi


    【解决方案1】:

    这是一个我正在验证“收件人”地址字段的示例调用:

    validator.getValidInput("toAddress", it.next(), "Email", Email.MAX_ADDRESS_SIZE, true)
    

    ESAPI 假设您使用的是 IDE 或有权访问直接源代码。如果您使用的是 Eclipse,只需将鼠标悬停在方法名称上,参数类型就会显示出来。

    ===更新===

    这是直接来自 javadoc 的 rip:

    /**
         * Returns canonicalized and validated input as a String. Invalid input will generate a descriptive ValidationException,
         * and input that is clearly an attack will generate a descriptive IntrusionException.
         *
         * @param context
         *      A descriptive name of the parameter that you are validating (e.g., LoginPage_UsernameField). This value is used by any logging or error handling that is done with respect to the value passed in.
         * @param input
         *      The actual user input data to validate.
         * @param type
         *      The regular expression name that maps to the actual regular expression from "ESAPI.properties".
         * @param maxLength
         *      The maximum post-canonicalized String length allowed.
         * @param allowNull
         *      If allowNull is true then an input that is NULL or an empty string will be legal. If allowNull is false then NULL or an empty String will throw a ValidationException.
         *
         * @return The canonicalized user input.
         *
         * @throws ValidationException
         * @throws IntrusionException
         */
    

    【讨论】:

    • "Email" feild 你有你在这里..它是在 ESAPI.properties 文件下定义的正则表达式吗?如果我不正确,请教育..
    • 在validation.properties 文件中,您应该会看到一个默认条目(对应于我上面的情况),如下所示:Validator.Email=^[A-Za-z0-9._%-]+@[A-Za-z0-9.-]+\\.[a-zA-Z]{2,4}$1 在“getValidInput”调用中,“Email”映射到“Validator.电子邮件”
    • 我们可以在 esapi.properties 文件中添加一个新的正则表达式吗?因为如果我尝试这样做,我会得到 java.lang.IllegalArgumentException: The selected type [DefaultRegex] was not set via the ESAPI validation configuration,其中 DefaultRegex 是正则表达式。
    • 我想说我们开始一个新问题,你在这里链接它。简短的回答是“是的”。
    • 实际上,您可以将这些新的验证正则表达式模式添加到“validation.properties”文件中,该文件应与您正在使用的 ESAPI.properties 文件位于同一目录中。
    【解决方案2】:
    ESAPI.validator().getValidInput("Validationofinput", StringInput, "Onlycharacters",200, true);
    

    【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-09-06
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多