Skip to content
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

Conversation

yasserzamani
Copy link
Contributor

Falls back to getXXX on SecurityException to be more adaptable for environments that have a SecurityManager applied.

Falls back to getXXX on SecurityException to be more adaptable for environments that have a SecurityManager applied.
@JCgH4164838Gh792C124B5
Copy link
Contributor

Hello @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) ?
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 ?

@yasserzamani
Copy link
Contributor Author

yasserzamani commented Aug 15, 2019 via email

@lukaszlenart
Copy link
Collaborator

Looks like we must switch to JDK7

[ERROR] COMPILATION ERROR : 
[INFO] -------------------------------------------------------------
[ERROR] Source option 5 is no longer supported. Use 6 or later.
[ERROR] Target option 1.5 is no longer supported. Use 1.6 or later.
[INFO] 2 errors 

@yasserzamani
Copy link
Contributor Author

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.

@lukaszlenart
Copy link
Collaborator

I was sure I was even using 1.7 but cannot figure out where it go :\

@yasserzamani
Copy link
Contributor Author

I skimmed pom.xml in different branches and realized it's 7 only in master :)

@yasserzamani
Copy link
Contributor Author

fixed via switching to 1.6 :)

Copy link
Contributor

@JCgH4164838Gh792C124B5 JCgH4164838Gh792C124B5 left a 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;
Copy link
Contributor

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 {
Copy link
Contributor

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).

Copy link
Contributor Author

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.

Copy link
Contributor

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. 😄

Copy link
Contributor Author

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.

@@ -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{
Copy link
Contributor

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)

Copy link
Collaborator

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 :)

@yasserzamani
Copy link
Contributor Author

yasserzamani commented Sep 12, 2019 via email

@lukaszlenart lukaszlenart merged commit 32d076d into orphan-oss:ognl-3-1-x Sep 13, 2019
@lukaszlenart
Copy link
Collaborator

Ok, now I can release a new OGNL 3.1.x version, thanks!

@yasserzamani
Copy link
Contributor Author

yasserzamani commented Sep 13, 2019 via email

@yasserzamani yasserzamani deleted the ognl_3_1_SecurityManager_getDeclaredXXX branch September 14, 2019 11:29
yasserzamani added a commit to yasserzamani/ognl that referenced this pull request Dec 16, 2019
…an-oss#79)

not fail on getDeclaredXXX when user has used a SecurityManager

(cherry picked from commit 32d076d)
lukaszlenart added a commit that referenced this pull request Dec 16, 2019
cherry pick #79 and #82 and related commits
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants