diff --git a/pom.xml b/pom.xml index 677aa197fe5..95adffbd09b 100644 --- a/pom.xml +++ b/pom.xml @@ -152,7 +152,7 @@ ognl ognl - 3.1.16 + 3.2.6 compile true diff --git a/src/main/java/org/apache/ibatis/scripting/xmltags/OgnlCache.java b/src/main/java/org/apache/ibatis/scripting/xmltags/OgnlCache.java index 64c64b5c9cc..9c1ad89dffd 100644 --- a/src/main/java/org/apache/ibatis/scripting/xmltags/OgnlCache.java +++ b/src/main/java/org/apache/ibatis/scripting/xmltags/OgnlCache.java @@ -1,5 +1,5 @@ /** - * Copyright 2009-2016 the original author or authors. + * Copyright 2009-2018 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -32,6 +32,7 @@ */ public final class OgnlCache { + private static final OgnlMemberAccess MEMBER_ACCESS = new OgnlMemberAccess(); private static final Map expressionCache = new ConcurrentHashMap(); private OgnlCache() { @@ -40,7 +41,7 @@ private OgnlCache() { public static Object getValue(String expression, Object root) { try { - Map context = Ognl.createDefaultContext(root, new OgnlClassResolver()); + Map context = Ognl.createDefaultContext(root, MEMBER_ACCESS, new OgnlClassResolver(), null); return Ognl.getValue(parseExpression(expression), context, root); } catch (OgnlException e) { throw new BuilderException("Error evaluating expression '" + expression + "'. Cause: " + e, e); diff --git a/src/main/java/org/apache/ibatis/scripting/xmltags/OgnlMemberAccess.java b/src/main/java/org/apache/ibatis/scripting/xmltags/OgnlMemberAccess.java new file mode 100644 index 00000000000..dd3cb8cfd26 --- /dev/null +++ b/src/main/java/org/apache/ibatis/scripting/xmltags/OgnlMemberAccess.java @@ -0,0 +1,64 @@ +/** + * Copyright 2009-2018 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.ibatis.scripting.xmltags; + +import ognl.MemberAccess; + +import java.lang.reflect.AccessibleObject; +import java.lang.reflect.Member; +import java.lang.reflect.Modifier; +import java.util.Map; + +/** + * The {@link MemberAccess} class that based on DefaultMemberAccess. + * + * @author Kazuki Shimizu + * @since 3.5.0 + * + * @see DefaultMemberAccess + * @see #47 of ognl + */ +class OgnlMemberAccess implements MemberAccess { + + @Override + public Object setup(Map context, Object target, Member member, String propertyName) { + Object result = null; + if (isAccessible(context, target, member, propertyName)) { + AccessibleObject accessible = (AccessibleObject) member; + if (!accessible.isAccessible()) { + result = Boolean.FALSE; + accessible.setAccessible(true); + } + } + return result; + } + + @Override + public void restore(Map context, Object target, Member member, String propertyName, + Object state) { + if (state != null) { + ((AccessibleObject) member).setAccessible(((Boolean) state)); + } + } + + @Override + public boolean isAccessible(Map context, Object target, Member member, String propertyName) { + return Modifier.isPublic(member.getModifiers()); + } + +}