Skip to content

Commit

Permalink
Merge pull request #38 from yasserzamani/ognl-3-0-x-WW-4817
Browse files Browse the repository at this point in the history
WW-4817 Same as #36 for ognl-3-0-x
  • Loading branch information
lukaszlenart authored Aug 1, 2017
2 parents ad8e228 + ca58bf0 commit 68a054d
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 31 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
<groupId>ognl</groupId>
<artifactId>ognl</artifactId>
<packaging>jar</packaging>
<version>3.0.20</version>
<version>3.0.21-SNAPSHOT</version>
<name>OGNL - Object Graph Navigation Library</name>
<description>OGNL - Object Graph Navigation Library</description>

Expand Down
65 changes: 35 additions & 30 deletions src/java/ognl/OgnlRuntime.java
Original file line number Diff line number Diff line change
Expand Up @@ -823,21 +823,48 @@ public static Object invokeMethod(Object target, Method method, Object[] argsArr
// only synchronize method invocation if it actually requires it

synchronized(method) {
if (_methodAccessCache.get(method) == null
|| _methodAccessCache.get(method) == Boolean.TRUE) {
if (_methodAccessCache.get(method) == null) {
if (!Modifier.isPublic(method.getModifiers()) || !Modifier.isPublic(method.getDeclaringClass().getModifiers()))
{
if (!(((AccessibleObject) method).isAccessible()))
{
_methodAccessCache.put(method, Boolean.TRUE);
} else
{
_methodAccessCache.put(method, Boolean.FALSE);
}
} else
{
_methodAccessCache.put(method, Boolean.FALSE);
}
}
if (_methodAccessCache.get(method) == Boolean.TRUE) {
syncInvoke = true;
}

if (_securityManager != null && _methodPermCache.get(method) == null
|| _methodPermCache.get(method) == Boolean.FALSE) {
if (_methodPermCache.get(method) == null) {
if (_securityManager != null) {
try
{
_securityManager.checkPermission(getPermission(method));
_methodPermCache.put(method, Boolean.TRUE);
} catch (SecurityException ex) {
_methodPermCache.put(method, Boolean.FALSE);
throw new IllegalAccessException("Method [" + method + "] cannot be accessed.");
}
}
else {
_methodPermCache.put(method, Boolean.TRUE);
}
}
if (_methodPermCache.get(method) == Boolean.FALSE) {
checkPermission = true;
}
}

Object result;
boolean wasAccessible = true;

if (syncInvoke)
if (syncInvoke) //if is not public and is not accessible
{
synchronized(method)
{
Expand All @@ -846,34 +873,14 @@ public static Object invokeMethod(Object target, Method method, Object[] argsArr
try
{
_securityManager.checkPermission(getPermission(method));
_methodPermCache.put(method, Boolean.TRUE);
} catch (SecurityException ex) {
_methodPermCache.put(method, Boolean.FALSE);
throw new IllegalAccessException("Method [" + method + "] cannot be accessed.");
}
}

if (!Modifier.isPublic(method.getModifiers()) || !Modifier.isPublic(method.getDeclaringClass().getModifiers()))
{
if (!(wasAccessible = ((AccessibleObject) method).isAccessible()))
{
((AccessibleObject) method).setAccessible(true);
_methodAccessCache.put(method, Boolean.TRUE);
} else
{
_methodAccessCache.put(method, Boolean.FALSE);
}
} else
{
_methodAccessCache.put(method, Boolean.FALSE);
}

((AccessibleObject) method).setAccessible(true);
result = method.invoke(target, argsArray);

if (!wasAccessible)
{
((AccessibleObject) method).setAccessible(false);
}
((AccessibleObject) method).setAccessible(false);
}
} else
{
Expand All @@ -882,9 +889,7 @@ public static Object invokeMethod(Object target, Method method, Object[] argsArr
try
{
_securityManager.checkPermission(getPermission(method));
_methodPermCache.put(method, Boolean.TRUE);
} catch (SecurityException ex) {
_methodPermCache.put(method, Boolean.FALSE);
throw new IllegalAccessException("Method [" + method + "] cannot be accessed.");
}
}
Expand Down

0 comments on commit 68a054d

Please sign in to comment.