Java ESAPI getValidInput 方法的使用

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/22664006/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-13 17:10:32  来源:igfitidea点击:

Use of ESAPI getValidInput method

javaesapi

提问by abc

I was not able to use the of method present under ESAPIclass'

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

    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". 

How to pass parameter type from ESAPI.propertiesfile? Any example to use properties file value from which I can refer?

如何从ESAPI.properties文件传递参数类型?任何使用我可以参考的属性文件值的示例?

采纳答案by avgvstvs

Here's an example call where I'm validating the "to" address field:

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

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

ESAPI assumes you're using an IDE or have access to the direct source. If you're using Eclipse, just mouse-hover over the method name, and the parameter types will be displayed.

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

===UPDATED===

===更新===

Here's the rip directly from the javadoc:

这是直接来自 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
     */

回答by srinivas gowda

ESAPI.validator().getValidInput("Validationofinput", StringInput, "Onlycharacters",200, true);