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

WW-5336 Deprecate OgnlTool #735

Merged
merged 10 commits into from
Aug 22, 2023
Merged

WW-5336 Deprecate OgnlTool #735

merged 10 commits into from
Aug 22, 2023

Conversation

kusalk
Copy link
Member

@kusalk kusalk commented Aug 21, 2023

WW-5336

I couldn't see any value in retaining OgnlTool as its own class so I've deprecated it and merged the method into StrutsUtil.

@kusalk kusalk force-pushed the WW-5336-deprecate-ognltool branch from fdf00c1 to 23abcf7 Compare August 21, 2023 13:50
@kusalk
Copy link
Member Author

kusalk commented Aug 21, 2023

Await merge of #731 first

@kusalk kusalk force-pushed the WW-5336-deprecate-ognltool branch 2 times, most recently from 518d2ac to 740cb68 Compare August 22, 2023 01:35
@kusalk kusalk force-pushed the WW-5336-deprecate-ognltool branch from 740cb68 to 35b0a68 Compare August 22, 2023 01:57
@@ -50,32 +61,30 @@ public class StrutsUtil {

protected HttpServletRequest request;
protected HttpServletResponse response;
protected Map<String, Class> classes = new Hashtable<>();
protected OgnlTool ognl;
protected Map<String, Class<?>> classes = new HashMap<>();
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This class is constructed per request thread so I don't believe we need concurrency handling here

public Object bean(Object name) throws Exception {
String className = name.toString();
Class<?> clazz = classes.get(className);
if (clazz == null) {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using #computeIfAbsent here would change the exception handling semantics so I've forgone it

@@ -124,6 +123,17 @@ public Object findValue(String expression, String className) throws ClassNotFoun
return stack.findValue(expression, Class.forName(className));
}

public Object findValue(String expr, Object context) {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copied this here from OgnlTool

return ognl.getValue(expr, ActionContext.getContext().getContextMap(), context);
} catch (OgnlException e) {
if (e.getReason() instanceof SecurityException) {
LOG.error(format("Could not evaluate this expression due to security constraints: [{0}]", expr), e);
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed broken logging

selectedItems.add(i);
}
}
public List<ListEntry> makeSelectList(String selectedList, String list, String listKey, String listValue) {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed cognitive complexity and readability

@kusalk kusalk marked this pull request as ready for review August 22, 2023 02:07
@@ -198,7 +198,7 @@
<bean type="ognl.MethodAccessor" name="com.opensymphony.xwork2.util.CompoundRoot"
class="com.opensymphony.xwork2.ognl.accessor.CompoundRootAccessor"/>

<bean class="org.apache.struts2.views.jsp.ui.OgnlTool"/>
<bean class="org.apache.struts2.views.jsp.ui.OgnlTool"/> <!-- Deprecated since 6.3.0 -->
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe it's better to put the comment before the bean?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Amended - I tend to favour the same line as sometimes comments can become detached from their intended line in highly concurrent teams


List<ListEntry> listMade = strutsUtil.makeSelectList("#mySelectedList", "#myList", null, null);

assertEquals(listMade.size(), 3);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

for assertEquals, the expected value should be the first argument

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems all the assertions in this class are mis-ordered, I've amended the ones I've touched :)

@sonarqubecloud
Copy link

Kudos, SonarCloud Quality Gate passed!    Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 5 Code Smells

85.2% 85.2% Coverage
0.0% 0.0% Duplication

Copy link
Member

@lukaszlenart lukaszlenart left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM 👍

@lukaszlenart
Copy link
Member

Hope this is the last change and I can prepare another RC or even test build and call for vote :)

@kusalk
Copy link
Member Author

kusalk commented Aug 22, 2023

Hope this is the last change and I can prepare another RC or even test build and call for vote :)

I opened 2 more security enhancement cards that I intend to work on next week or the week after. Up to you whether you want these in 6.3.0 or a later release

@kusalk kusalk merged commit 555a3a3 into master Aug 22, 2023
@kusalk kusalk deleted the WW-5336-deprecate-ognltool branch August 22, 2023 12:54
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