模块名称:BeanWrapperImpl

模块功能:实现BeanWrapper接口的默认实现,对Bean的属性进行访问和设置。

模块实现:

import org.springframework.beans.BeanWrapper; import org.springframework.beans.PropertyAccessorFactory;

public class BeanWrapperImpl implements BeanWrapper { private Object wrappedObject;

public BeanWrapperImpl(Object object) {
    this.wrappedObject = object;
}

@Override
public Object getPropertyValue(String propertyName) {
    return PropertyAccessorFactory.forBeanPropertyAccess(wrappedObject).getPropertyValue(propertyName);
}

@Override
public void setPropertyValue(String propertyName, Object value) {
    PropertyAccessorFactory.forBeanPropertyAccess(wrappedObject).setPropertyValue(propertyName, value);
}

@Override
public boolean isReadableProperty(String propertyName) {
    return PropertyAccessorFactory.forBeanPropertyAccess(wrappedObject).isReadableProperty(propertyName);
}

@Override
public boolean isWritableProperty(String propertyName) {
    return PropertyAccessorFactory.forBeanPropertyAccess(wrappedObject).isWritableProperty(propertyName);
}

@Override
public Class<?> getPropertyType(String propertyName) {
    return PropertyAccessorFactory.forBeanPropertyAccess(wrappedObject).getPropertyType(propertyName);
}

@Override
public Object getWrappedInstance() {
    return wrappedObject;
}

@Override
public void setWrappedInstance(Object object) {
    this.wrappedObject = object;
}

@Override
public boolean isWrappedInstance(Class<?> clazz) {
    return clazz.isInstance(wrappedObject);
}

@Override
public boolean isAutoGrowNestedPaths() {
    return false;
}

@Override
public void setAutoGrowNestedPaths(boolean autoGrowNestedPaths) {
    // do nothing
}

}

说明:

  1. BeanWrapperImpl实现了BeanWrapper接口,对Bean的属性进行访问和设置。

  2. getPropertyValue方法通过PropertyAccessorFactory.forBeanPropertyAccess方法获取Bean的属性值。

  3. setPropertyValue方法通过PropertyAccessorFactory.forBeanPropertyAccess方法设置Bean的属性值。

  4. isReadableProperty和isWritableProperty方法用于判断Bean的属性是否可读/可写。

  5. getPropertyType方法获取Bean的属性类型。

  6. getWrappedInstance和setWrappedInstance方法用于获取和设置被包装的Bean对象。

  7. isWrappedInstance方法用于判断被包装的对象是否为指定类的实例。

  8. isAutoGrowNestedPaths方法返回false,setAutoGrowNestedPaths方法不做任何操作

《Spring Framework RCE CVE-2022-22965漏洞复现报告》在Spring中BeanWrapper接口是对Bean的包装定义了大量可以非常方便的方法对Bean的属性进行访问和设置。BeanWrapperImpl类是BeanWrapper接口的默认实现BeanWrapperImplwrappedObject属性即为被包装的Bean对象BeanWrapperImpl对Bean

原文地址: https://www.cveoy.top/t/topic/gkg5 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录