正在检查 Spring 安全方法调用以获得精确的参数信息
Inspecting Spring Security MethodInvocation for precise argument info
Spring 这里的安全性并试图弄清楚如何使用 MethodInvocation
实例来获取:
- 传递给方法的所有参数(名称和类型)的列表;和
- 每个参数对应的值
有 MethodInvocation#getArguments() : Object[]
方法,但绝对没有 Spring 关于可以在对象数组中返回什么类型的安全文档。
它是一个数组,包含调用方法的所有参数。最左边的参数从索引 0 开始,依此类推。
假设调用的方法是:
void hello(Integer int , String str, Boolean bool);
它被调用:
hello(1000, "world" , true);
然后MethodInvocation#getArguments()
将return一个数组:
- 在索引 0 处:整数 1000
- 在索引 1 处:字符串“world”
- 在索引 2 处:一个布尔值 true
您可以在每个参数对象上使用 getClass()
来访问它们的类型信息,如果您想访问该类型的特定方法,则可以将其转换为实际的 class。喜欢的东西:
Object[] args = methodInvocation.getArguments();
args[0].getClass() // return you Integer class
if(args[0] instanceof Integer){
((Integer)arg[0]).intValue(); // cast it to the integer and access a specific method provided by the Integer
}
如果调用的方法没有任何输入参数,它return为 null。
Spring 这里的安全性并试图弄清楚如何使用 MethodInvocation
实例来获取:
- 传递给方法的所有参数(名称和类型)的列表;和
- 每个参数对应的值
有 MethodInvocation#getArguments() : Object[]
方法,但绝对没有 Spring 关于可以在对象数组中返回什么类型的安全文档。
它是一个数组,包含调用方法的所有参数。最左边的参数从索引 0 开始,依此类推。
假设调用的方法是:
void hello(Integer int , String str, Boolean bool);
它被调用:
hello(1000, "world" , true);
然后MethodInvocation#getArguments()
将return一个数组:
- 在索引 0 处:整数 1000
- 在索引 1 处:字符串“world”
- 在索引 2 处:一个布尔值 true
您可以在每个参数对象上使用 getClass()
来访问它们的类型信息,如果您想访问该类型的特定方法,则可以将其转换为实际的 class。喜欢的东西:
Object[] args = methodInvocation.getArguments();
args[0].getClass() // return you Integer class
if(args[0] instanceof Integer){
((Integer)arg[0]).intValue(); // cast it to the integer and access a specific method provided by the Integer
}
如果调用的方法没有任何输入参数,它return为 null。