Skip to content

Introduces AbstractMemberAccess to allow create it on-fly #109

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Nov 8, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 36 additions & 0 deletions src/main/java/ognl/AbstractMemberAccess.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* and/or LICENSE file distributed with this work for additional
* information regarding copyright ownership. The ASF licenses
* this file to you 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 ognl;

import java.lang.reflect.Member;
import java.util.Map;

/**
* Used as a based class
*/
abstract public class AbstractMemberAccess implements MemberAccess {

public Object setup(Map context, Object target, Member member, String propertyName) {
return null;
}

public void restore(Map context, Object target, Member member, String propertyName, Object state) {
}

}
29 changes: 21 additions & 8 deletions src/main/java/ognl/Ognl.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@
import ognl.security.OgnlSecurityManager;

import java.io.StringReader;
import java.lang.reflect.Member;
import java.lang.reflect.Modifier;
import java.util.Map;

/**
Expand Down Expand Up @@ -223,7 +225,14 @@ public static Node compileExpression(OgnlContext context, Object root, String ex
@Deprecated
public static Map createDefaultContext(Object root)
{
return addDefaultContext(root, null, null, null, new OgnlContext(null, null, null));
MemberAccess memberAccess = new AbstractMemberAccess() {
@Override
public boolean isAccessible(Map context, Object target, Member member, String propertyName) {
int modifiers = member.getModifiers();
return Modifier.isPublic(modifiers);
}
};
return addDefaultContext(root, memberAccess, null, null, new OgnlContext(null, null, null));
}

/**
Expand Down Expand Up @@ -477,7 +486,7 @@ public static void setRoot(Map context, Object root)
*
* @param context
* The context to get the root object from.
*
*
* @return The root object - or null if none found.
*/
public static Object getRoot(Map context)
Expand All @@ -490,7 +499,7 @@ public static Object getRoot(Map context)
*
* @param context
* The context to get the evaluation from.
*
*
* @return The {@link Evaluation} - or null if none was found.
*/
public static Evaluation getLastEvaluation(Map context)
Expand All @@ -517,7 +526,9 @@ public static Evaluation getLastEvaluation(Map context)
* if the expression can't be used in this context
* @throws OgnlException
* if there is a pathological environmental problem
* @deprecated
*/
@Deprecated
public static Object getValue(Object tree, Map context, Object root)
throws OgnlException
{
Expand Down Expand Up @@ -545,7 +556,9 @@ public static Object getValue(Object tree, Map context, Object root)
* if the expression can't be used in this context
* @throws OgnlException
* if there is a pathological environmental problem
* @deprecated
*/
@Deprecated
public static Object getValue(Object tree, Map context, Object root, Class resultType)
throws OgnlException
{
Expand All @@ -566,11 +579,11 @@ public static Object getValue(Object tree, Map context, Object root, Class resul
}

/**
* Gets the value represented by the given pre-compiled expression on the specified root
* Gets the value represented by the given pre-compiled expression on the specified root
* object.
*
* @param expression
* The pre-compiled expression, as found in {@link Node#getAccessor()}.
* The pre-compiled expression, as found in {@link Node#getAccessor()}.
* @param context
* The ognl context.
* @param root
Expand All @@ -584,11 +597,11 @@ public static Object getValue(ExpressionAccessor expression, OgnlContext context
}

/**
* Gets the value represented by the given pre-compiled expression on the specified root
* Gets the value represented by the given pre-compiled expression on the specified root
* object.
*
* @param expression
* The pre-compiled expression, as found in {@link Node#getAccessor()}.
* The pre-compiled expression, as found in {@link Node#getAccessor()}.
* @param context
* The ognl context.
* @param root
Expand Down Expand Up @@ -947,7 +960,7 @@ public static boolean isConstant(String expression, Map context)
*
* @param tree
* The {@link Node} to check.
*
*
* @return True if the node represents a constant expression - false otherwise.
* @throws OgnlException If an exception occurs.
*/
Expand Down