You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@shiro.apache.org by bd...@apache.org on 2017/04/12 14:33:07 UTC
shiro git commit: SHIRO-619: use private instance of BeanUtilsBean
Repository: shiro
Updated Branches:
refs/heads/master 09ebb5ca7 -> 8acc82ab4
SHIRO-619: use private instance of BeanUtilsBean
Fixes: SHIRO-619, #60
Project: http://git-wip-us.apache.org/repos/asf/shiro/repo
Commit: http://git-wip-us.apache.org/repos/asf/shiro/commit/8acc82ab
Tree: http://git-wip-us.apache.org/repos/asf/shiro/tree/8acc82ab
Diff: http://git-wip-us.apache.org/repos/asf/shiro/diff/8acc82ab
Branch: refs/heads/master
Commit: 8acc82ab4775b3af546e3bbde928f299be62dc23
Parents: 09ebb5c
Author: Brian Demers <bd...@apache.org>
Authored: Tue Mar 28 14:26:36 2017 -0400
Committer: Brian Demers <bd...@apache.org>
Committed: Wed Apr 12 10:28:11 2017 -0400
----------------------------------------------------------------------
.../apache/shiro/config/ReflectionBuilder.java | 25 +++++++++++++-------
samples/aspectj/pom.xml | 5 ++++
.../apache/shiro/guice/BeanTypeListener.java | 17 +++++++++++--
3 files changed, 37 insertions(+), 10 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/shiro/blob/8acc82ab/config/ogdl/src/main/java/org/apache/shiro/config/ReflectionBuilder.java
----------------------------------------------------------------------
diff --git a/config/ogdl/src/main/java/org/apache/shiro/config/ReflectionBuilder.java b/config/ogdl/src/main/java/org/apache/shiro/config/ReflectionBuilder.java
index a39cc02..1c3df1f 100644
--- a/config/ogdl/src/main/java/org/apache/shiro/config/ReflectionBuilder.java
+++ b/config/ogdl/src/main/java/org/apache/shiro/config/ReflectionBuilder.java
@@ -18,8 +18,8 @@
*/
package org.apache.shiro.config;
-import org.apache.commons.beanutils.BeanUtils;
-import org.apache.commons.beanutils.PropertyUtils;
+import org.apache.commons.beanutils.BeanUtilsBean;
+import org.apache.commons.beanutils.SuppressPropertiesBeanIntrospector;
import org.apache.shiro.codec.Base64;
import org.apache.shiro.codec.Hex;
import org.apache.shiro.config.event.BeanEvent;
@@ -104,6 +104,11 @@ public class ReflectionBuilder {
*/
private final Map<String,Object> registeredEventSubscribers;
+ /**
+ * @since 1.4
+ */
+ private final BeanUtilsBean beanUtilsBean;
+
//@since 1.3
private Map<String,Object> createDefaultObjectMap() {
Map<String,Object> map = new LinkedHashMap<String, Object>();
@@ -117,6 +122,10 @@ public class ReflectionBuilder {
public ReflectionBuilder(Map<String, ?> defaults) {
+ // SHIRO-619
+ beanUtilsBean = new BeanUtilsBean();
+ beanUtilsBean.getPropertyUtils().addBeanIntrospector(SuppressPropertiesBeanIntrospector.SUPPRESS_CLASS);
+
this.interpolator = createInterpolator();
this.objects = createDefaultObjectMap();
@@ -343,7 +352,7 @@ public class ReflectionBuilder {
protected void applyGlobalProperty(Map objects, String property, String value) {
for (Object instance : objects.values()) {
try {
- PropertyDescriptor pd = PropertyUtils.getPropertyDescriptor(instance, property);
+ PropertyDescriptor pd = beanUtilsBean.getPropertyUtils().getPropertyDescriptor(instance, property);
if (pd != null) {
applyProperty(instance, property, value);
}
@@ -415,7 +424,7 @@ public class ReflectionBuilder {
throw new NullPointerException("type (class) argument cannot be null.");
}
try {
- PropertyDescriptor descriptor = PropertyUtils.getPropertyDescriptor(object, propertyName);
+ PropertyDescriptor descriptor = beanUtilsBean.getPropertyUtils().getPropertyDescriptor(object, propertyName);
if (descriptor == null) {
String msg = "Property '" + propertyName + "' does not exist for object of " +
"type " + object.getClass().getName() + ".";
@@ -656,7 +665,7 @@ public class ReflectionBuilder {
log.trace("Applying property [{}] value [{}] on object of type [{}]",
new Object[]{propertyPath, value, object.getClass().getName()});
}
- BeanUtils.setProperty(object, propertyPath, value);
+ beanUtilsBean.setProperty(object, propertyPath, value);
} catch (Exception e) {
String msg = "Unable to set property '" + propertyPath + "' with value [" + value + "] on object " +
"of type " + (object != null ? object.getClass().getName() : null) + ". If " +
@@ -670,7 +679,7 @@ public class ReflectionBuilder {
private Object getProperty(Object object, String propertyPath) {
try {
- return PropertyUtils.getProperty(object, propertyPath);
+ return beanUtilsBean.getPropertyUtils().getProperty(object, propertyPath);
} catch (Exception e) {
throw new ConfigurationException("Unable to access property '" + propertyPath + "'", e);
}
@@ -678,7 +687,7 @@ public class ReflectionBuilder {
private void setIndexedProperty(Object object, String propertyPath, int index, Object value) {
try {
- PropertyUtils.setIndexedProperty(object, propertyPath, index, value);
+ beanUtilsBean.getPropertyUtils().setIndexedProperty(object, propertyPath, index, value);
} catch (Exception e) {
throw new ConfigurationException("Unable to set array property '" + propertyPath + "'", e);
}
@@ -686,7 +695,7 @@ public class ReflectionBuilder {
private Object getIndexedProperty(Object object, String propertyPath, int index) {
try {
- return PropertyUtils.getIndexedProperty(object, propertyPath, index);
+ return beanUtilsBean.getPropertyUtils().getIndexedProperty(object, propertyPath, index);
} catch (Exception e) {
throw new ConfigurationException("Unable to acquire array property '" + propertyPath + "'", e);
}
http://git-wip-us.apache.org/repos/asf/shiro/blob/8acc82ab/samples/aspectj/pom.xml
----------------------------------------------------------------------
diff --git a/samples/aspectj/pom.xml b/samples/aspectj/pom.xml
index 154af00..39fb3b3 100644
--- a/samples/aspectj/pom.xml
+++ b/samples/aspectj/pom.xml
@@ -85,6 +85,11 @@
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
+ <artifactId>jcl-over-slf4j</artifactId>
+ <scope>runtime</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.slf4j</groupId>
<artifactId>slf4j-log4j12</artifactId>
<scope>runtime</scope>
</dependency>
http://git-wip-us.apache.org/repos/asf/shiro/blob/8acc82ab/support/guice/src/main/java/org/apache/shiro/guice/BeanTypeListener.java
----------------------------------------------------------------------
diff --git a/support/guice/src/main/java/org/apache/shiro/guice/BeanTypeListener.java b/support/guice/src/main/java/org/apache/shiro/guice/BeanTypeListener.java
index 7cc4521..0031bb6 100644
--- a/support/guice/src/main/java/org/apache/shiro/guice/BeanTypeListener.java
+++ b/support/guice/src/main/java/org/apache/shiro/guice/BeanTypeListener.java
@@ -43,7 +43,8 @@ import com.google.inject.spi.TypeEncounter;
import com.google.inject.spi.TypeListener;
import com.google.inject.util.Types;
-import org.apache.commons.beanutils.PropertyUtils;
+import org.apache.commons.beanutils.BeanUtilsBean;
+import org.apache.commons.beanutils.SuppressPropertiesBeanIntrospector;
import org.apache.shiro.SecurityUtils;
/**
@@ -63,6 +64,11 @@ class BeanTypeListener implements TypeListener {
private static final String BEAN_TYPE_MAP_NAME = "__SHIRO_BEAN_TYPES__";
static final Key<?> MAP_KEY = Key.get(Types.mapOf(TypeLiteral.class, BeanTypeKey.class), Names.named(BEAN_TYPE_MAP_NAME));
+ /**
+ * @since 1.4
+ */
+ private final BeanUtilsBean beanUtilsBean;
+
private static final Set<Class<?>> WRAPPER_TYPES = new HashSet<Class<?>>(Arrays.asList(
Byte.class,
Boolean.class,
@@ -74,8 +80,15 @@ class BeanTypeListener implements TypeListener {
Short.class,
Void.class));
+ public BeanTypeListener() {
+ // SHIRO-619
+ beanUtilsBean = new BeanUtilsBean();
+ beanUtilsBean.getPropertyUtils().addBeanIntrospector(
+ SuppressPropertiesBeanIntrospector.SUPPRESS_CLASS);
+ }
+
public <I> void hear(TypeLiteral<I> type, final TypeEncounter<I> encounter) {
- PropertyDescriptor propertyDescriptors[] = PropertyUtils.getPropertyDescriptors(type.getRawType());
+ PropertyDescriptor propertyDescriptors[] = beanUtilsBean.getPropertyUtils().getPropertyDescriptors(type.getRawType());
final Map<PropertyDescriptor, Key<?>> propertyDependencies = new HashMap<PropertyDescriptor, Key<?>>(propertyDescriptors.length);
final Provider<Injector> injectorProvider = encounter.getProvider(Injector.class);
for (PropertyDescriptor propertyDescriptor : propertyDescriptors) {