-
-
Notifications
You must be signed in to change notification settings - Fork 80
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
not fail on getDeclaredXXX when user has used a SecurityManager #79
not fail on getDeclaredXXX when user has used a SecurityManager #79
Conversation
Falls back to getXXX on SecurityException to be more adaptable for environments that have a SecurityManager applied.
Hello @yasserzamani . |
On 8/15/2019 12:08 AM, JCgH4164838Gh792C124B5 wrote:
Hello @yasserzamani <https://github.com/yasserzamani> .
This change could cause different behaviour for environments using a
SecurityManager vs. ones that are not, couldn't it (due to returning a
different list of methods) ?
Howdy,
If the SecurityManager doesn't allow "suppressaccesscheck", yes it will.
But I think it's a nice adaption rather than a back-ward compatibility
issue.
If an application/user's security manager blocks access to declared
methods it might be better to let it fail and force the application to
adjust its security manager to allow the needed access ?
She already can allow the needed access then OGNL will operate exactly
as before. This change takes the control and adapts only when there are
a SecurityManager and that doesn't allow "suppressaccesscheck" elsewhere
(i.e. when there are no SecurityManager OR there are but does allow
"suppressaccesscheck") OGNL will operate exactly as before.
Regards.
|
Looks like we must switch to JDK7
|
It seems Travis environment doesn't support 5 and 1.5 for source and target option anymore. Is it OK to change them to 6 and 1.6 in pom.xml? I think it should be fine because java 5 is obviously absolute. |
I was sure I was even using 1.7 but cannot figure out where it go :\ |
I skimmed pom.xml in different branches and realized it's 7 only in master :) |
fixed via switching to 1.6 :) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The PR does appear to have the potential to improve behaviour under the circumstances it identified, but at the cost of extra overhead the rest of the time (e.g. when no SecurityManager is installed).
Someone might have a different suggestion, but the one provided could reduce the overhead a bit.
@@ -1861,7 +1861,12 @@ public static Map getMethods(Class targetClass, boolean staticMethods) | |||
} | |||
|
|||
private static void collectMethods(Class c, Map result, boolean staticMethods) { | |||
Method[] ma = c.getDeclaredMethods(); | |||
Method[] ma; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since there is loop processing involved below, there will probably be extra overhead for processing the try..catch multiple times within the loop. Since we're attempting the getDeclaredMethods vs. getMethods checks here it should be possible to set a boolean flag that determines which methodology the current SecurityManager allows.
boolean smSupportsGetDeclaredMethods = true;
try {
ma = c.getDeclaredMethods();
} catch (SecurityException ignored) {
smSupportsGetDeclaredMethods = false;
ma = c.getMethods();
}
@@ -1966,7 +1971,11 @@ public static Map getFields(Class targetClass) | |||
Field fa[]; | |||
|
|||
result = new HashMap(23); | |||
fa = targetClass.getDeclaredFields(); | |||
try { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
And then in the loop here the try..catch code could be replaced by something like:
smSupportsGetDeclaredMethods ? fa = targetClass.getDeclaredFields() : fa = targetClass.getFields();
which limits the overhead of looping over a try..catch when the determination of which mechanism to use is known (someone would have to look at the bytecode to be certain, but a boolean check should be more efficient, especially over multiple iterations).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks! I got your idea but they aren't in same scope (method). Their call order isn't guaranteed. Furthermore, I'm not going to use a global flag because user might remove security manager at runtime after some calls. At bottom, according to my googling and experience, java security checks aren't expensive.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi @yasserzamani . I know this PR has already been merged, but I wanted to respond to make sure I understood your reply.
Ooops ... I missed that the two code blocks were in separate methods, and interpreted them as being in the same block scope with a loop involved. 😥 Since there's not actually any looping over a try..catch involved the new logic shouldn't introduce any noticeable overhead (especially since post-computation results are cached).
Thanks for clarifying and pointing out my mis-interpretation. 😄
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Cool! Frankly I had overlooked the performance. Thanks for your acknowledgement.
src/java/ognl/OgnlRuntime.java
Outdated
@@ -2264,7 +2273,12 @@ public static List getDeclaredMethods(Class targetClass, String propertyName, bo | |||
|
|||
private static void collectAccessors(Class c, String baseName, List result, boolean findSets) | |||
{ | |||
final Method[] methods = c.getDeclaredMethods(); | |||
Method[] methods; | |||
try{ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could change try{
to try {
(whitespace to match the others in the PR)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@yasserzamani this tiny thing and I'm good to merge this PR :)
fixed :+1 Now this will be a good candidate to squash :) Thanks!
|
Ok, now I can release a new OGNL 3.1.x version, thanks! |
Yes please. Then I will adapt Struts 2.5.x to be less brittle with
Security Managers via a PR :)
|
…an-oss#79) not fail on getDeclaredXXX when user has used a SecurityManager (cherry picked from commit 32d076d)
Falls back to getXXX on SecurityException to be more adaptable for environments that have a SecurityManager applied.