From 5919178ce956d6db679b8cf307ae75f49f026735 Mon Sep 17 00:00:00 2001 From: Kusal Kithul-Godage Date: Thu, 25 Jul 2024 19:52:01 +1000 Subject: [PATCH 1/6] WW-5411 Delete deprecated code part 1 --- .../impl/InstantiatingNullHandler.java | 18 +- .../xwork2/inject/util/Strings.java | 57 ----- .../xwork2/interceptor/AliasInterceptor.java | 10 +- .../interceptor/ModelDrivenInterceptor.java | 5 +- .../xwork2/interceptor/NoParameters.java | 37 --- .../ParameterFilterInterceptor.java | 241 ------------------ .../interceptor/ParameterNameAware.java | 26 -- .../interceptor/ParameterValueAware.java | 26 -- .../interceptor/ParametersInterceptor.java | 25 -- .../StaticParametersInterceptor.java | 6 +- .../interceptor/annotations/Allowed.java | 38 --- .../AnnotationParameterFilterInterceptor.java | 115 --------- .../annotations/BlockByDefault.java | 41 --- .../interceptor/annotations/Blocked.java | 38 --- .../apache/struts2/ServletActionContext.java | 13 +- core/src/main/resources/struts-default.xml | 4 +- core/src/main/resources/xwork-default.xml | 4 +- .../providers/MockConfigurationProvider.java | 38 ++- ...mlConfigurationProviderMultilevelTest.java | 2 +- .../ParameterFilterInterceptorTest.java | 127 --------- .../annotations/AllowingByDefaultAction.java | 44 ---- .../annotations/AllowingByDefaultModel.java | 41 --- ...otationParameterFilterInterceptorTest.java | 199 --------------- .../annotations/BlockingByDefaultAction.java | 45 ---- .../annotations/BlockingByDefaultModel.java | 40 --- .../struts2/TestConfigurationProvider.java | 6 +- .../ExecuteAndWaitInterceptorTest.java | 4 +- .../config/providers/xwork-include-parent.xml | 2 +- .../providers/xwork-test-multilevel.xml | 2 +- core/src/test/resources/xwork-proxyinvoke.xml | 2 +- .../src/test/resources/xwork-test-default.xml | 2 +- .../test/resources/xwork-test-validation.xml | 2 +- .../struts2/junit/StrutsJUnit4TestCase.java | 10 +- .../xwork2/spring/actionContext-xwork.xml | 6 +- .../tiles/StrutsTilesContainerFactory.java | 24 +- .../views/velocity/StrutsVelocityContext.java | 18 -- .../views/velocity/VelocityTagLibrary.java | 8 - 37 files changed, 78 insertions(+), 1248 deletions(-) delete mode 100644 core/src/main/java/com/opensymphony/xwork2/inject/util/Strings.java delete mode 100644 core/src/main/java/com/opensymphony/xwork2/interceptor/NoParameters.java delete mode 100644 core/src/main/java/com/opensymphony/xwork2/interceptor/ParameterFilterInterceptor.java delete mode 100644 core/src/main/java/com/opensymphony/xwork2/interceptor/ParameterNameAware.java delete mode 100644 core/src/main/java/com/opensymphony/xwork2/interceptor/ParameterValueAware.java delete mode 100644 core/src/main/java/com/opensymphony/xwork2/interceptor/ParametersInterceptor.java delete mode 100644 core/src/main/java/com/opensymphony/xwork2/interceptor/annotations/Allowed.java delete mode 100644 core/src/main/java/com/opensymphony/xwork2/interceptor/annotations/AnnotationParameterFilterInterceptor.java delete mode 100644 core/src/main/java/com/opensymphony/xwork2/interceptor/annotations/BlockByDefault.java delete mode 100644 core/src/main/java/com/opensymphony/xwork2/interceptor/annotations/Blocked.java delete mode 100644 core/src/test/java/com/opensymphony/xwork2/interceptor/ParameterFilterInterceptorTest.java delete mode 100644 core/src/test/java/com/opensymphony/xwork2/interceptor/annotations/AllowingByDefaultAction.java delete mode 100644 core/src/test/java/com/opensymphony/xwork2/interceptor/annotations/AllowingByDefaultModel.java delete mode 100644 core/src/test/java/com/opensymphony/xwork2/interceptor/annotations/AnnotationParameterFilterInterceptorTest.java delete mode 100644 core/src/test/java/com/opensymphony/xwork2/interceptor/annotations/BlockingByDefaultAction.java delete mode 100644 core/src/test/java/com/opensymphony/xwork2/interceptor/annotations/BlockingByDefaultModel.java diff --git a/core/src/main/java/com/opensymphony/xwork2/conversion/impl/InstantiatingNullHandler.java b/core/src/main/java/com/opensymphony/xwork2/conversion/impl/InstantiatingNullHandler.java index 9b74f76fc7..e7cc1713b4 100644 --- a/core/src/main/java/com/opensymphony/xwork2/conversion/impl/InstantiatingNullHandler.java +++ b/core/src/main/java/com/opensymphony/xwork2/conversion/impl/InstantiatingNullHandler.java @@ -28,16 +28,24 @@ import org.apache.logging.log4j.Logger; import java.beans.PropertyDescriptor; -import java.util.*; +import java.util.ArrayList; +import java.util.Collection; +import java.util.EnumMap; +import java.util.HashMap; +import java.util.HashSet; +import java.util.List; +import java.util.Map; +import java.util.Set; /** * *

- * Provided that the key {@link ReflectionContextState#CREATE_NULL_OBJECTS} is in the action context with a value of true (this key is set - * only during the execution of the {@link com.opensymphony.xwork2.interceptor.ParametersInterceptor}), OGNL expressions - * that have caused a NullPointerException will be temporarily stopped for evaluation while the system automatically - * tries to solve the null references by automatically creating the object. + * Provided that the key {@link ReflectionContextState#CREATE_NULL_OBJECTS} is in the action context with a value of + * true (this key is set only during the execution of the {@link + * org.apache.struts2.interceptor.parameter.ParametersInterceptor}), OGNL expressions that have caused a + * NullPointerException will be temporarily stopped for evaluation while the system automatically tries to solve the + * null references by automatically creating the object. *

* *

The following rules are used when handling null references:

diff --git a/core/src/main/java/com/opensymphony/xwork2/inject/util/Strings.java b/core/src/main/java/com/opensymphony/xwork2/inject/util/Strings.java deleted file mode 100644 index 2c4df91d97..0000000000 --- a/core/src/main/java/com/opensymphony/xwork2/inject/util/Strings.java +++ /dev/null @@ -1,57 +0,0 @@ -/** - * Copyright (C) 2006 Google Inc. - * - * Licensed 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 com.opensymphony.xwork2.inject.util; - -/** - * String utilities. - * - * @author crazybob@google.com (Bob Lee) - */ -@Deprecated -public class Strings { - - /** - * Returns a string that is equivalent to the specified string with its - * first character converted to uppercase as by {@link String#toUpperCase}. - * The returned string will have the same value as the specified string if - * its first character is non-alphabetic, if its first character is already - * uppercase, or if the specified string is of length 0. - * - *

For example: - *

-   *    capitalize("foo bar").equals("Foo bar");
-   *    capitalize("2b or not 2b").equals("2b or not 2b")
-   *    capitalize("Foo bar").equals("Foo bar");
-   *    capitalize("").equals("");
-   * 
- * - * @param s the string whose first character is to be uppercased - * @return a string equivalent to s with its first character - * converted to uppercase - * @throws NullPointerException if s is null - */ - @Deprecated - public static String capitalize(String s) { - if (s.length() == 0) - return s; - char first = s.charAt(0); - char capitalized = Character.toUpperCase(first); - return (first == capitalized) - ? s - : capitalized + s.substring(1); - } -} diff --git a/core/src/main/java/com/opensymphony/xwork2/interceptor/AliasInterceptor.java b/core/src/main/java/com/opensymphony/xwork2/interceptor/AliasInterceptor.java index 9edafe3fc4..c57df3dabf 100644 --- a/core/src/main/java/com/opensymphony/xwork2/interceptor/AliasInterceptor.java +++ b/core/src/main/java/com/opensymphony/xwork2/interceptor/AliasInterceptor.java @@ -20,21 +20,21 @@ import com.opensymphony.xwork2.ActionContext; import com.opensymphony.xwork2.ActionInvocation; +import com.opensymphony.xwork2.LocalizedTextProvider; import com.opensymphony.xwork2.config.entities.ActionConfig; import com.opensymphony.xwork2.inject.Inject; import com.opensymphony.xwork2.security.AcceptedPatternsChecker; import com.opensymphony.xwork2.security.ExcludedPatternsChecker; import com.opensymphony.xwork2.util.ClearableValueStack; import com.opensymphony.xwork2.util.Evaluated; -import com.opensymphony.xwork2.LocalizedTextProvider; import com.opensymphony.xwork2.util.ValueStack; import com.opensymphony.xwork2.util.ValueStackFactory; import com.opensymphony.xwork2.util.reflection.ReflectionContextState; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; +import org.apache.struts2.StrutsConstants; import org.apache.struts2.dispatcher.HttpParameters; import org.apache.struts2.dispatcher.Parameter; -import org.apache.struts2.StrutsConstants; import java.util.Map; @@ -108,7 +108,7 @@ public class AliasInterceptor extends AbstractInterceptor { @Inject(StrutsConstants.STRUTS_DEVMODE) public void setDevMode(String mode) { this.devMode = Boolean.parseBoolean(mode); - } + } @Inject public void setValueStackFactory(ValueStackFactory valueStackFactory) { @@ -206,7 +206,7 @@ public void setAliasesKey(String aliasesKey) { newStack.setValue(alias, value.get()); } catch (RuntimeException e) { if (devMode) { - String developerNotification = localizedTextProvider.findText(ParametersInterceptor.class, "devmode.notification", ActionContext.getContext().getLocale(), "Developer Notification:\n{0}", new Object[]{ + String developerNotification = localizedTextProvider.findText(AliasInterceptor.class, "devmode.notification", ActionContext.getContext().getLocale(), "Developer Notification:\n{0}", new Object[]{ "Unexpected Exception caught setting '" + entry.getKey() + "' on '" + action.getClass() + ": " + e.getMessage() }); LOG.error(developerNotification); @@ -225,7 +225,7 @@ public void setAliasesKey(String aliasesKey) { LOG.debug("invalid alias expression: {}", aliasesKey); } } - + return invocation.invoke(); } diff --git a/core/src/main/java/com/opensymphony/xwork2/interceptor/ModelDrivenInterceptor.java b/core/src/main/java/com/opensymphony/xwork2/interceptor/ModelDrivenInterceptor.java index fa90a315ca..f1919a8c9e 100644 --- a/core/src/main/java/com/opensymphony/xwork2/interceptor/ModelDrivenInterceptor.java +++ b/core/src/main/java/com/opensymphony/xwork2/interceptor/ModelDrivenInterceptor.java @@ -29,7 +29,8 @@ * Watches for {@link ModelDriven} actions and adds the action's model on to the value stack. * *

Note: The ModelDrivenInterceptor must come before the both {@link StaticParametersInterceptor} and - * {@link ParametersInterceptor} if you want the parameters to be applied to the model. + * {@link org.apache.struts2.interceptor.parameter.ParametersInterceptor} if you want the parameters to be applied to + * the model. *

*

Note: The ModelDrivenInterceptor will only push the model into the stack when the * model is not null, else it will be ignored. @@ -71,7 +72,7 @@ * </action> * * - * + * * @author tm_jee * @version $Date$ $Id$ */ diff --git a/core/src/main/java/com/opensymphony/xwork2/interceptor/NoParameters.java b/core/src/main/java/com/opensymphony/xwork2/interceptor/NoParameters.java deleted file mode 100644 index d4fb7ad14b..0000000000 --- a/core/src/main/java/com/opensymphony/xwork2/interceptor/NoParameters.java +++ /dev/null @@ -1,37 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE 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 com.opensymphony.xwork2.interceptor; - -/** - * Marker interface to indicate no auto setting of parameters. - * - *

- * This marker interface should be implemented by actions that do not want any - * request parameters set on them automatically (by the ParametersInterceptor). - * This may be useful if one is using the action tag and want to supply - * the parameters to the action manually using the param tag. - * It may also be useful if one for security reasons wants to make sure that - * parameters cannot be set by malicious users. - *

- * - * @deprecated since Struts 6.2.0, use {@link org.apache.struts2.action.NoParameters} - */ -@Deprecated -public interface NoParameters extends org.apache.struts2.action.NoParameters { -} diff --git a/core/src/main/java/com/opensymphony/xwork2/interceptor/ParameterFilterInterceptor.java b/core/src/main/java/com/opensymphony/xwork2/interceptor/ParameterFilterInterceptor.java deleted file mode 100644 index 1b402509c0..0000000000 --- a/core/src/main/java/com/opensymphony/xwork2/interceptor/ParameterFilterInterceptor.java +++ /dev/null @@ -1,241 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE 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 com.opensymphony.xwork2.interceptor; - -import com.opensymphony.xwork2.ActionInvocation; -import com.opensymphony.xwork2.util.TextParseUtil; -import org.apache.commons.lang3.StringUtils; -import org.apache.logging.log4j.LogManager; -import org.apache.logging.log4j.Logger; -import org.apache.struts2.dispatcher.HttpParameters; - -import java.util.Collection; -import java.util.Map; -import java.util.TreeMap; - -/** - * - * - * The Parameter Filter Interceptor blocks parameters from getting - * to the rest of the stack or your action. You can use multiple - * parameter filter interceptors for a given action, so, for example, - * you could use one in your default stack that filtered parameters - * you wanted blocked from every action and those you wanted blocked - * from an individual action you could add an additional interceptor - * for each action. - * - * - * - * - * - * - * - *

The way parameters are filtered for the least configuration is that - * if a string is in the allowed or blocked lists, then any parameter - * that is a member of the object represented by the parameter is allowed - * or blocked respectively.

- * - *

For example, if the parameters are: - *

- * - *

- * The parameters person.name, person.phoneNum etc would be blocked - * because 'person' is in the blocked list. However, person.address.street - * and person.address.city would be allowed because person.address is - * in the allowed list (the longer string determines permissions).

- * - * - * - * There are no known extension points to this interceptor. - * - * - *
- * 
- * <interceptors>
- *   ...
- *   <interceptor name="parameterFilter" class="com.opensymphony.xwork2.interceptor.ParameterFilterInterceptor"/>
- *   ...
- * </interceptors>
- *
- * <action ....>
- *   ...
- *   <interceptor-ref name="parameterFilter">
- *     <param name="blocked">person,person.address.createDate,personDao</param>
- *   </interceptor-ref>
- *   ...
- * </action>
- * 
- * 
- * - * @author Gabe - * - * @deprecated since 6.4.0, use {@link org.apache.struts2.interceptor.parameter.ParametersInterceptor}. - */ -@Deprecated -public class ParameterFilterInterceptor extends AbstractInterceptor { - - private static final Logger LOG = LogManager.getLogger(ParameterFilterInterceptor.class); - - private Collection allowed; - private Collection blocked; - private Map includesExcludesMap; - private boolean defaultBlock = false; - - @Override - public String intercept(ActionInvocation invocation) throws Exception { - - HttpParameters parameters = invocation.getInvocationContext().getParameters(); - - Map includesExcludesMap = getIncludesExcludesMap(); - - for (String param : parameters.keySet()) { - boolean currentAllowed = !isDefaultBlock(); - - for (Map.Entry entry : includesExcludesMap.entrySet()) { - String currRule = entry.getKey(); - - if (param.startsWith(currRule) && - (param.length() == currRule.length() || isPropertySeparator(param.charAt(currRule.length()))) - ) { - currentAllowed = entry.getValue(); - } - } - if (!currentAllowed) { - LOG.debug("Removing param: {}", param); - parameters = parameters.remove(param); - } - } - - invocation.getInvocationContext().withParameters(parameters); - - return invocation.invoke(); - } - - /** - * Tests if the given char is a property separator char .([. - * - * @param c the char - * @return true, if char is property separator, false otherwise. - */ - private boolean isPropertySeparator(char c) { - return c == '.' || c == '(' || c == '['; - } - - private Map getIncludesExcludesMap() { - if (this.includesExcludesMap == null) { - this.includesExcludesMap = new TreeMap<>(); - - if (getAllowedCollection() != null) { - for (String e : getAllowedCollection()) { - this.includesExcludesMap.put(e, Boolean.TRUE); - } - } - if (getBlockedCollection() != null) { - for (String b : getBlockedCollection()) { - this.includesExcludesMap.put(b, Boolean.FALSE); - } - } - } - - return this.includesExcludesMap; - } - - /** - * @return Returns the defaultBlock. - */ - public boolean isDefaultBlock() { - return defaultBlock; - } - - /** - * @param defaultExclude The defaultExclude to set. - */ - public void setDefaultBlock(boolean defaultExclude) { - this.defaultBlock = defaultExclude; - } - - /** - * @return Returns the blocked. - */ - public Collection getBlockedCollection() { - return blocked; - } - - /** - * @param blocked The blocked to set. - */ - public void setBlockedCollection(Collection blocked) { - this.blocked = blocked; - } - - /** - * @param blocked The blocked paramters as comma separated String. - */ - public void setBlocked(String blocked) { - setBlockedCollection(asCollection(blocked)); - } - - /** - * @return Returns the allowed. - */ - public Collection getAllowedCollection() { - return allowed; - } - - /** - * @param allowed The allowed to set. - */ - public void setAllowedCollection(Collection allowed) { - this.allowed = allowed; - } - - /** - * @param allowed The allowed paramters as comma separated String. - */ - public void setAllowed(String allowed) { - setAllowedCollection(asCollection(allowed)); - } - - /** - * Return a collection from the comma delimited String. - * - * @param commaDelim the comma delimited String. - * @return A collection from the comma delimited String. Returns null if the string is empty. - */ - private Collection asCollection(String commaDelim) { - if (StringUtils.isBlank(commaDelim)) { - return null; - } - return TextParseUtil.commaDelimitedStringToSet(commaDelim); - } - -} diff --git a/core/src/main/java/com/opensymphony/xwork2/interceptor/ParameterNameAware.java b/core/src/main/java/com/opensymphony/xwork2/interceptor/ParameterNameAware.java deleted file mode 100644 index ae73871cdf..0000000000 --- a/core/src/main/java/com/opensymphony/xwork2/interceptor/ParameterNameAware.java +++ /dev/null @@ -1,26 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE 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 com.opensymphony.xwork2.interceptor; - -/** - * @deprecated since 6.4.0, use {@link org.apache.struts2.action.ParameterNameAware}. - */ -@Deprecated -public interface ParameterNameAware extends org.apache.struts2.action.ParameterNameAware { -} diff --git a/core/src/main/java/com/opensymphony/xwork2/interceptor/ParameterValueAware.java b/core/src/main/java/com/opensymphony/xwork2/interceptor/ParameterValueAware.java deleted file mode 100644 index 4c9a4e1099..0000000000 --- a/core/src/main/java/com/opensymphony/xwork2/interceptor/ParameterValueAware.java +++ /dev/null @@ -1,26 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE 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 com.opensymphony.xwork2.interceptor; - -/** - * @deprecated since 6.4.0, use {@link org.apache.struts2.action.ParameterValueAware}. - */ -@Deprecated -public interface ParameterValueAware extends org.apache.struts2.action.ParameterValueAware { -} diff --git a/core/src/main/java/com/opensymphony/xwork2/interceptor/ParametersInterceptor.java b/core/src/main/java/com/opensymphony/xwork2/interceptor/ParametersInterceptor.java deleted file mode 100644 index aa9518208b..0000000000 --- a/core/src/main/java/com/opensymphony/xwork2/interceptor/ParametersInterceptor.java +++ /dev/null @@ -1,25 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE 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 com.opensymphony.xwork2.interceptor; - -/** - * @deprecated since 6.4.0, use {@link org.apache.struts2.interceptor.parameter.ParametersInterceptor}. - */ -public class ParametersInterceptor extends org.apache.struts2.interceptor.parameter.ParametersInterceptor { -} diff --git a/core/src/main/java/com/opensymphony/xwork2/interceptor/StaticParametersInterceptor.java b/core/src/main/java/com/opensymphony/xwork2/interceptor/StaticParametersInterceptor.java index 9d32a8a184..b95a0e6e60 100644 --- a/core/src/main/java/com/opensymphony/xwork2/interceptor/StaticParametersInterceptor.java +++ b/core/src/main/java/com/opensymphony/xwork2/interceptor/StaticParametersInterceptor.java @@ -20,11 +20,11 @@ import com.opensymphony.xwork2.ActionContext; import com.opensymphony.xwork2.ActionInvocation; +import com.opensymphony.xwork2.LocalizedTextProvider; import com.opensymphony.xwork2.config.entities.ActionConfig; import com.opensymphony.xwork2.config.entities.Parameterizable; import com.opensymphony.xwork2.inject.Inject; import com.opensymphony.xwork2.util.ClearableValueStack; -import com.opensymphony.xwork2.LocalizedTextProvider; import com.opensymphony.xwork2.util.TextParseUtil; import com.opensymphony.xwork2.util.ValueStack; import com.opensymphony.xwork2.util.ValueStackFactory; @@ -169,7 +169,7 @@ public String intercept(ActionInvocation invocation) throws Exception { for (Map.Entry entry : parameters.entrySet()) { Object val = entry.getValue(); - if (parse && val instanceof String) { + if (parse && val != null) { val = TextParseUtil.translateVariables(val.toString(), stack); } try { @@ -177,7 +177,7 @@ public String intercept(ActionInvocation invocation) throws Exception { } catch (RuntimeException e) { if (devMode) { - String developerNotification = localizedTextProvider.findText(ParametersInterceptor.class, "devmode.notification", ActionContext.getContext().getLocale(), "Developer Notification:\n{0}", new Object[]{ + String developerNotification = localizedTextProvider.findText(StaticParametersInterceptor.class, "devmode.notification", ActionContext.getContext().getLocale(), "Developer Notification:\n{0}", new Object[]{ "Unexpected Exception caught setting '" + entry.getKey() + "' on '" + action.getClass() + ": " + e.getMessage() }); LOG.error(developerNotification); diff --git a/core/src/main/java/com/opensymphony/xwork2/interceptor/annotations/Allowed.java b/core/src/main/java/com/opensymphony/xwork2/interceptor/annotations/Allowed.java deleted file mode 100644 index 39bfdcb26b..0000000000 --- a/core/src/main/java/com/opensymphony/xwork2/interceptor/annotations/Allowed.java +++ /dev/null @@ -1,38 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE 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 com.opensymphony.xwork2.interceptor.annotations; - -import java.lang.annotation.ElementType; -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; -import java.lang.annotation.Target; - -/** - * Declares that it is permitted for the field be mutated through - * a HttpRequest parameter. - * - * @author martin.gilday - * @deprecated since 6.6.0, use {@link org.apache.struts2.interceptor.parameter.StrutsParameter}. - */ -@Retention(RetentionPolicy.RUNTIME) -@Target(ElementType.FIELD) -@Deprecated -public @interface Allowed { - -} diff --git a/core/src/main/java/com/opensymphony/xwork2/interceptor/annotations/AnnotationParameterFilterInterceptor.java b/core/src/main/java/com/opensymphony/xwork2/interceptor/annotations/AnnotationParameterFilterInterceptor.java deleted file mode 100644 index d1b7260ac4..0000000000 --- a/core/src/main/java/com/opensymphony/xwork2/interceptor/annotations/AnnotationParameterFilterInterceptor.java +++ /dev/null @@ -1,115 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE 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 com.opensymphony.xwork2.interceptor.annotations; - -import com.opensymphony.xwork2.Action; -import com.opensymphony.xwork2.ActionInvocation; -import com.opensymphony.xwork2.interceptor.AbstractInterceptor; -import com.opensymphony.xwork2.interceptor.Interceptor; -import com.opensymphony.xwork2.interceptor.ParameterFilterInterceptor; -import com.opensymphony.xwork2.util.AnnotationUtils; -import org.apache.struts2.dispatcher.HttpParameters; -import org.apache.struts2.interceptor.parameter.ParametersInterceptor; -import org.apache.struts2.interceptor.parameter.StrutsParameter; - -import java.lang.reflect.Field; -import java.util.ArrayList; -import java.util.List; - -/** - * Annotation based version of {@link ParameterFilterInterceptor}. - * - *

- * This {@link Interceptor} must be placed in the stack before the {@link ParametersInterceptor} - * When a parameter matches a field that is marked {@link Blocked} then it is removed from - * the parameter map. - *

- *

- * If an {@link Action} class is marked with {@link BlockByDefault} then all parameters are - * removed unless a field on the Action exists and is marked with {@link Allowed} - *

- * - * @author martin.gilday - * @deprecated since 6.6.0, integrated into {@link ParametersInterceptor} with {@link StrutsParameter} using - * {@code struts.parameters.requireAnnotations=true} - */ -@Deprecated -public class AnnotationParameterFilterInterceptor extends AbstractInterceptor { - - /* (non-Javadoc) - * @see com.opensymphony.xwork2.interceptor.AbstractInterceptor#intercept(com.opensymphony.xwork2.ActionInvocation) - */ - @Override public String intercept(ActionInvocation invocation) throws Exception { - - final Object action = invocation.getAction(); - HttpParameters parameters = invocation.getInvocationContext().getParameters(); - - Object model = invocation.getStack().peek(); - if (model == action) { - model = null; - } - - boolean blockByDefault = action.getClass().isAnnotationPresent(BlockByDefault.class); - List annotatedFields = new ArrayList<>(); - - if (blockByDefault) { - AnnotationUtils.addAllFields(Allowed.class, action.getClass(), annotatedFields); - if (model != null) { - AnnotationUtils.addAllFields(Allowed.class, model.getClass(), annotatedFields); - } - - for (String paramName : parameters.keySet()) { - boolean allowed = false; - - for (Field field : annotatedFields) { - //TODO only matches exact field names. need to change to it matches start of ognl expression - //i.e take param name up to first . (period) and match against that - if (field.getName().equals(paramName)) { - allowed = true; - break; - } - } - - if (!allowed) { - parameters = parameters.remove(paramName); - } - } - } else { - AnnotationUtils.addAllFields(Blocked.class, action.getClass(), annotatedFields); - if (model != null) { - AnnotationUtils.addAllFields(Blocked.class, model.getClass(), annotatedFields); - } - - for (String paramName : parameters.keySet()) { - for (Field field : annotatedFields) { - //TODO only matches exact field names. need to change to it matches start of ognl expression - //i.e take param name up to first . (period) and match against that - if (field.getName().equals(paramName)) { - parameters = parameters.remove(paramName); - } - } - } - } - - invocation.getInvocationContext().withParameters(parameters); - - return invocation.invoke(); - } - -} diff --git a/core/src/main/java/com/opensymphony/xwork2/interceptor/annotations/BlockByDefault.java b/core/src/main/java/com/opensymphony/xwork2/interceptor/annotations/BlockByDefault.java deleted file mode 100644 index e7b4520220..0000000000 --- a/core/src/main/java/com/opensymphony/xwork2/interceptor/annotations/BlockByDefault.java +++ /dev/null @@ -1,41 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE 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 com.opensymphony.xwork2.interceptor.annotations; - -import com.opensymphony.xwork2.Action; - -import java.lang.annotation.ElementType; -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; -import java.lang.annotation.Target; - -/** - * Declares that by default fields on the {@link Action} class - * are NOT permitted to be set from HttpRequest parameters. - * To allow access to a field it must be annotated with {@link Allowed} - * - * @author martin.gilday - * @deprecated since 6.6.0, use {@code struts.parameters.requireAnnotations=true} to block all parameters globally. - */ -@Retention(RetentionPolicy.RUNTIME) -@Target(ElementType.TYPE) -@Deprecated -public @interface BlockByDefault { - -} diff --git a/core/src/main/java/com/opensymphony/xwork2/interceptor/annotations/Blocked.java b/core/src/main/java/com/opensymphony/xwork2/interceptor/annotations/Blocked.java deleted file mode 100644 index 17ec80940d..0000000000 --- a/core/src/main/java/com/opensymphony/xwork2/interceptor/annotations/Blocked.java +++ /dev/null @@ -1,38 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE 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 com.opensymphony.xwork2.interceptor.annotations; - -import java.lang.annotation.ElementType; -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; -import java.lang.annotation.Target; - -/** - * Declares that the given field should NOT be able to be mutated through - * a HttpRequest parameter. - * - * @author martin.gilday - * @deprecated since 6.6.0, use {@code struts.parameters.requireAnnotations=true} to block all parameters globally. - */ -@Retention(RetentionPolicy.RUNTIME) -@Target(ElementType.FIELD) -@Deprecated -public @interface Blocked { - -} diff --git a/core/src/main/java/org/apache/struts2/ServletActionContext.java b/core/src/main/java/org/apache/struts2/ServletActionContext.java index bf0cd84934..e6038e302a 100644 --- a/core/src/main/java/org/apache/struts2/ServletActionContext.java +++ b/core/src/main/java/org/apache/struts2/ServletActionContext.java @@ -20,12 +20,11 @@ import com.opensymphony.xwork2.ActionContext; import com.opensymphony.xwork2.util.ValueStack; -import org.apache.struts2.dispatcher.mapper.ActionMapping; - import jakarta.servlet.ServletContext; import jakarta.servlet.http.HttpServletRequest; import jakarta.servlet.http.HttpServletResponse; import jakarta.servlet.jsp.PageContext; +import org.apache.struts2.dispatcher.mapper.ActionMapping; /** * Web-specific context information for actions. This class subclasses ActionContext which @@ -55,16 +54,6 @@ public static ActionContext getActionContext(HttpServletRequest req) { } } - /** - * Do not use this method, use {@link #getActionContext()} - * @return action context - * @deprecated Use {@link #getActionContext()} instead - */ - @Deprecated - public static ActionContext getContext() { - return ActionContext.getContext(); - } - public static ActionContext getActionContext() { return ActionContext.getContext(); } diff --git a/core/src/main/resources/struts-default.xml b/core/src/main/resources/struts-default.xml index 326477bc41..70e06ce5c4 100644 --- a/core/src/main/resources/struts-default.xml +++ b/core/src/main/resources/struts-default.xml @@ -64,7 +64,7 @@ - + @@ -83,8 +83,6 @@ - diff --git a/core/src/main/resources/xwork-default.xml b/core/src/main/resources/xwork-default.xml index c25cdc59c0..152236e8eb 100644 --- a/core/src/main/resources/xwork-default.xml +++ b/core/src/main/resources/xwork-default.xml @@ -38,8 +38,7 @@ - - + - - - - - - - Date: Thu, 25 Jul 2024 20:22:48 +1000 Subject: [PATCH 4/6] WW-5411 Delete deprecated code part 4 --- .../xwork2/conversion/TypeConverter.java | 3 - .../util/AbstractLocalizedTextProvider.java | 32 +------- .../validator/DelegatingValidatorContext.java | 78 +++++++++++++------ .../org/apache/struts2/StrutsConstants.java | 19 ----- .../StrutsXmlConfigurationProvider.java | 10 --- .../struts2/dispatcher/HttpParameters.java | 55 +------------ .../multipart/StrutsUploadedFile.java | 13 ---- .../ActionMappingParametersInterceptor.java | 7 +- .../struts2/interceptor/csp/CspSettings.java | 6 -- .../interceptor/csp/DefaultCspSettings.java | 9 +-- .../parameter/ParametersInterceptor.java | 9 --- .../struts2/ognl/ProviderAllowlist.java | 18 ----- .../apache/struts2/url/QueryStringParser.java | 6 -- .../struts2/url/StrutsQueryStringParser.java | 5 -- .../struts2/util/ServletContextAware.java | 32 -------- .../struts2/views/jsp/ui/AbstractUITag.java | 12 +-- .../util/StrutsLocalizedTextProviderTest.java | 9 --- 17 files changed, 66 insertions(+), 257 deletions(-) delete mode 100644 core/src/main/java/org/apache/struts2/util/ServletContextAware.java diff --git a/core/src/main/java/com/opensymphony/xwork2/conversion/TypeConverter.java b/core/src/main/java/com/opensymphony/xwork2/conversion/TypeConverter.java index 0bbad6c6a6..98725e95a5 100644 --- a/core/src/main/java/com/opensymphony/xwork2/conversion/TypeConverter.java +++ b/core/src/main/java/com/opensymphony/xwork2/conversion/TypeConverter.java @@ -48,7 +48,4 @@ public interface TypeConverter { Object NO_CONVERSION_POSSIBLE = "ognl.NoConversionPossible"; - @Deprecated - String TYPE_CONVERTER_CONTEXT_KEY = "_typeConverter"; - } diff --git a/core/src/main/java/com/opensymphony/xwork2/util/AbstractLocalizedTextProvider.java b/core/src/main/java/com/opensymphony/xwork2/util/AbstractLocalizedTextProvider.java index 2d6a7c6783..87f65b216d 100644 --- a/core/src/main/java/com/opensymphony/xwork2/util/AbstractLocalizedTextProvider.java +++ b/core/src/main/java/com/opensymphony/xwork2/util/AbstractLocalizedTextProvider.java @@ -226,21 +226,6 @@ public void setDelegatedClassLoader(final ClassLoader classLoader) { } } - /** - * Clear a specific bundle from the bundlesMap. - * - * Warning: This method is now a "no-op". It was ineffective due - * to the way the bundlesMap is used in combination with locale. - * Descendants should use the method {@link #clearBundle(java.lang.String, java.util.Locale)} instead. - * - * @param bundleName The bundle to remove from the bundle map - * - * @deprecated A "no-op" since 6.0.0. Use {@link #clearBundle(java.lang.String, java.util.Locale)} instead. - */ - public void clearBundle(final String bundleName) { - LOG.debug("No-op. Did NOT clear resource bundle [{}], result: false.", bundleName); - } - /** * Clear a specific bundle + locale combination from the bundlesMap. * Intended for descendants to use clear a bundle + locale combination. @@ -491,16 +476,6 @@ public ResourceBundle findResourceBundle(String aBundleName, Locale locale) { return bundle; } - /** - * Clears all the internal lists. - * - * @deprecated used only in tests - */ - @Deprecated - public void reset() { - // no-op - } - /** * Determines if we found the text in the bundles. * @@ -513,12 +488,7 @@ protected boolean unableToFindTextForKey(GetDefaultMessageReturnArg result) { } // did we find it in the bundle, then no problem? - if (result.foundInBundle) { - return false; - } - - // not found in bundle - return true; + return !result.foundInBundle; } /** diff --git a/core/src/main/java/com/opensymphony/xwork2/validator/DelegatingValidatorContext.java b/core/src/main/java/com/opensymphony/xwork2/validator/DelegatingValidatorContext.java index bc8c88875c..4760ef72a4 100644 --- a/core/src/main/java/com/opensymphony/xwork2/validator/DelegatingValidatorContext.java +++ b/core/src/main/java/com/opensymphony/xwork2/validator/DelegatingValidatorContext.java @@ -18,13 +18,22 @@ */ package com.opensymphony.xwork2.validator; -import com.opensymphony.xwork2.*; +import com.opensymphony.xwork2.ActionContext; +import com.opensymphony.xwork2.CompositeTextProvider; +import com.opensymphony.xwork2.LocaleProvider; +import com.opensymphony.xwork2.LocaleProviderFactory; +import com.opensymphony.xwork2.TextProvider; +import com.opensymphony.xwork2.TextProviderFactory; import com.opensymphony.xwork2.interceptor.ValidationAware; import com.opensymphony.xwork2.util.ValueStack; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; -import java.util.*; +import java.util.Collection; +import java.util.List; +import java.util.Locale; +import java.util.Map; +import java.util.ResourceBundle; /** * A default implementation of the {@link ValidatorContext} interface. @@ -65,49 +74,42 @@ public DelegatingValidatorContext(Object object, TextProviderFactory textProvide this.textProvider = makeTextProvider(object, textProviderFactory); } - /** - * Create a new validation context given a Class definition. The locale provider, text provider and - * the validation context are created based on the class. - * - * @param clazz the class to initialize the context with. - * - * @deprecated will be removed, do not use! - */ - @Deprecated - public DelegatingValidatorContext(Class clazz) { - localeProvider = new ActionContextLocaleProvider(); - textProvider = new StrutsTextProviderFactory().createInstance(clazz); - validationAware = new LoggingValidationAware(clazz); - } - + @Override public void setActionErrors(Collection errorMessages) { validationAware.setActionErrors(errorMessages); } + @Override public Collection getActionErrors() { return validationAware.getActionErrors(); } + @Override public void setActionMessages(Collection messages) { validationAware.setActionMessages(messages); } + @Override public Collection getActionMessages() { return validationAware.getActionMessages(); } + @Override public void setFieldErrors(Map> errorMap) { validationAware.setFieldErrors(errorMap); } + @Override public Map> getFieldErrors() { return validationAware.getFieldErrors(); } + @Override public String getFullFieldName(String fieldName) { return fieldName; } + @Override public Locale getLocale() { return localeProvider.getLocale(); } @@ -127,78 +129,97 @@ public Locale toLocale(String localeStr) { return localeProvider.toLocale(localeStr); } + @Override public boolean hasKey(String key) { return textProvider.hasKey(key); } + @Override public String getText(String aTextName) { return textProvider.getText(aTextName); } + @Override public String getText(String aTextName, String defaultValue) { return textProvider.getText(aTextName, defaultValue); } + @Override public String getText(String aTextName, String defaultValue, String obj) { return textProvider.getText(aTextName, defaultValue, obj); } + @Override public String getText(String aTextName, List args) { return textProvider.getText(aTextName, args); } + @Override public String getText(String key, String[] args) { return textProvider.getText(key, args); } + @Override public String getText(String aTextName, String defaultValue, List args) { return textProvider.getText(aTextName, defaultValue, args); } + @Override public String getText(String key, String defaultValue, String[] args) { return textProvider.getText(key, defaultValue, args); } + @Override public ResourceBundle getTexts(String aBundleName) { return textProvider.getTexts(aBundleName); } + @Override public String getText(String key, String defaultValue, List args, ValueStack stack) { return textProvider.getText(key, defaultValue, args, stack); } + @Override public String getText(String key, String defaultValue, String[] args, ValueStack stack) { return textProvider.getText(key, defaultValue, args, stack); } + @Override public ResourceBundle getTexts() { return textProvider.getTexts(); } + @Override public void addActionError(String anErrorMessage) { validationAware.addActionError(anErrorMessage); } + @Override public void addActionMessage(String aMessage) { validationAware.addActionMessage(aMessage); } + @Override public void addFieldError(String fieldName, String errorMessage) { validationAware.addFieldError(fieldName, errorMessage); } + @Override public boolean hasActionErrors() { return validationAware.hasActionErrors(); } + @Override public boolean hasActionMessages() { return validationAware.hasActionMessages(); } + @Override public boolean hasErrors() { return validationAware.hasErrors(); } + @Override public boolean hasFieldErrors() { return validationAware.hasFieldErrors(); } @@ -307,62 +328,73 @@ public LoggingValidationAware(Object obj) { log = LogManager.getLogger(obj.getClass()); } + @Override public void setActionErrors(Collection errorMessages) { - for (Object errorMessage : errorMessages) { - String s = (String) errorMessage; - addActionError(s); + for (String errorMessage : errorMessages) { + addActionError(errorMessage); } } + @Override public Collection getActionErrors() { return null; } + @Override public void setActionMessages(Collection messages) { - for (Object message : messages) { - String s = (String) message; - addActionMessage(s); + for (String message : messages) { + addActionMessage(message); } } + @Override public Collection getActionMessages() { return null; } + @Override public void setFieldErrors(Map> errorMap) { for (Map.Entry> entry : errorMap.entrySet()) { addFieldError(entry.getKey(), entry.getValue().toString()); } } + @Override public Map> getFieldErrors() { return null; } + @Override public void addActionError(String anErrorMessage) { log.error("Validation error: {}", anErrorMessage); } + @Override public void addActionMessage(String aMessage) { log.info("Validation Message: {}", aMessage); } + @Override public void addFieldError(String fieldName, String errorMessage) { log.error("Validation error for {}:{}", fieldName, errorMessage); } + @Override public boolean hasActionErrors() { return false; } + @Override public boolean hasActionMessages() { return false; } + @Override public boolean hasErrors() { return false; } + @Override public boolean hasFieldErrors() { return false; } diff --git a/core/src/main/java/org/apache/struts2/StrutsConstants.java b/core/src/main/java/org/apache/struts2/StrutsConstants.java index c8c7489d44..1f5b379290 100644 --- a/core/src/main/java/org/apache/struts2/StrutsConstants.java +++ b/core/src/main/java/org/apache/struts2/StrutsConstants.java @@ -324,25 +324,12 @@ public final class StrutsConstants { */ public static final String STRUTS_OGNL_VALUE_STACK_FALLBACK_TO_CONTEXT = "struts.ognl.valueStackFallbackToContext"; - /** - * Logs properties that are not found (very verbose) - * @deprecated as of 6.0.0. Use {@link #STRUTS_OGNL_LOG_MISSING_PROPERTIES} instead. - */ - @Deprecated - public static final String STRUTS_LOG_MISSING_PROPERTIES = STRUTS_OGNL_LOG_MISSING_PROPERTIES; - /** * Enables caching of parsed OGNL expressions * @since 6.0.0 */ public static final String STRUTS_OGNL_ENABLE_EXPRESSION_CACHE = "struts.ognl.enableExpressionCache"; - /** - * Enables caching of parsed OGNL expressions - * @deprecated as of 6.0.0. Use {@link #STRUTS_OGNL_ENABLE_EXPRESSION_CACHE} instead. - */ - public static final String STRUTS_ENABLE_OGNL_EXPRESSION_CACHE = STRUTS_OGNL_ENABLE_EXPRESSION_CACHE; - /** * Specifies the type of cache to use for parsed OGNL expressions. Valid values defined in * {@link com.opensymphony.xwork2.ognl.OgnlCacheFactory.CacheType}. @@ -371,12 +358,6 @@ public final class StrutsConstants { */ public static final String STRUTS_OGNL_ENABLE_EVAL_EXPRESSION = "struts.ognl.enableEvalExpression"; - /** - * Enables evaluation of OGNL expressions - * @deprecated as of 6.0.0. Use {@link #STRUTS_OGNL_ENABLE_EVAL_EXPRESSION} instead. - */ - public static final String STRUTS_ENABLE_OGNL_EVAL_EXPRESSION = STRUTS_OGNL_ENABLE_EVAL_EXPRESSION; - /** The maximum length of an expression (OGNL) */ public static final String STRUTS_OGNL_EXPRESSION_MAX_LENGTH = "struts.ognl.expressionMaxLength"; diff --git a/core/src/main/java/org/apache/struts2/config/StrutsXmlConfigurationProvider.java b/core/src/main/java/org/apache/struts2/config/StrutsXmlConfigurationProvider.java index 3ea6dbabbc..e235ef9c3a 100644 --- a/core/src/main/java/org/apache/struts2/config/StrutsXmlConfigurationProvider.java +++ b/core/src/main/java/org/apache/struts2/config/StrutsXmlConfigurationProvider.java @@ -68,16 +68,6 @@ public StrutsXmlConfigurationProvider() { this("struts.xml", null); } - /** - * Constructs the configuration provider - * - * @param errorIfMissing If we should throw an exception if the file can't be found - */ - @Deprecated - public StrutsXmlConfigurationProvider(boolean errorIfMissing) { - this("struts.xml", null); - } - /** * Constructs the configuration provider based on the provided config file * diff --git a/core/src/main/java/org/apache/struts2/dispatcher/HttpParameters.java b/core/src/main/java/org/apache/struts2/dispatcher/HttpParameters.java index 54f465eea1..af8ccca104 100644 --- a/core/src/main/java/org/apache/struts2/dispatcher/HttpParameters.java +++ b/core/src/main/java/org/apache/struts2/dispatcher/HttpParameters.java @@ -64,20 +64,6 @@ public boolean contains(String name) { return parameters.containsKey(name); } - /** - * Access to this method can be potentially dangerous as it allows access to raw parameter values. - * - * @deprecated since 6.4.0, it will be removed with a new major release - */ - @Deprecated - private Map toMap() { - final Map result = new HashMap<>(parameters.size()); - for (Map.Entry entry : parameters.entrySet()) { - result.put(entry.getKey(), entry.getValue().getMultipleValues()); - } - return result; - } - /** * Appends all the parameters by overriding any existing params in a case-insensitive manner * @@ -187,44 +173,9 @@ public Builder withComparator(Comparator orderedComparator) { } public HttpParameters build() { - Map parameters = (parent == null) - ? new HashMap<>() - : new HashMap<>(parent.parameters); - - for (Map.Entry entry : requestParameterMap.entrySet()) { - String name = entry.getKey(); - Object value = entry.getValue(); - if (value instanceof Parameter) { - parameters.put(name, (Parameter) value); - } else { - parameters.put(name, new Parameter.Request(name, value)); - } - } - - return new HttpParameters(parameters); - } - - /** - * Alternate Builder method which avoids wrapping any parameters that are already - * a {@link Parameter} element within another {@link Parameter} wrapper. - * - * @deprecated since 6.4.0, use {@link #build()} instead - */ - @Deprecated - public HttpParameters buildNoNestedWrapping() { - Map parameters = (parent == null) - ? new HashMap<>() - : new HashMap<>(parent.parameters); - - for (Map.Entry entry : requestParameterMap.entrySet()) { - String name = entry.getKey(); - Object value = entry.getValue(); - Parameter parameterValue = (value instanceof Parameter) - ? (Parameter) value - : new Parameter.Request(name, value); - parameters.put(name, parameterValue); - } - + Map parameters = parent == null ? new HashMap<>() : new HashMap<>(parent.parameters); + requestParameterMap.forEach((name, value) -> + parameters.put(name,value instanceof Parameter ? (Parameter) value : new Parameter.Request(name, value))); return new HttpParameters(parameters); } } diff --git a/core/src/main/java/org/apache/struts2/dispatcher/multipart/StrutsUploadedFile.java b/core/src/main/java/org/apache/struts2/dispatcher/multipart/StrutsUploadedFile.java index 07e936ef03..eb9e93c36f 100644 --- a/core/src/main/java/org/apache/struts2/dispatcher/multipart/StrutsUploadedFile.java +++ b/core/src/main/java/org/apache/struts2/dispatcher/multipart/StrutsUploadedFile.java @@ -26,19 +26,6 @@ public class StrutsUploadedFile implements UploadedFile { private final String contentType; private final String originalName; - /** - * Use builder instead of constructor - * - * @param file an uploaded file - * @deprecated since Struts 6.4.0 - */ - @Deprecated - public StrutsUploadedFile(File file) { - this.file = file; - this.contentType = null; - this.originalName = null; - } - private StrutsUploadedFile(File file, String contentType, String originalName) { this.file = file; this.contentType = contentType; diff --git a/core/src/main/java/org/apache/struts2/interceptor/ActionMappingParametersInterceptor.java b/core/src/main/java/org/apache/struts2/interceptor/ActionMappingParametersInterceptor.java index 4d52c5f9a5..3cf53e0a26 100644 --- a/core/src/main/java/org/apache/struts2/interceptor/ActionMappingParametersInterceptor.java +++ b/core/src/main/java/org/apache/struts2/interceptor/ActionMappingParametersInterceptor.java @@ -83,9 +83,9 @@ public class ActionMappingParametersInterceptor extends ParametersInterceptor { protected HttpParameters retrieveParameters(ActionContext actionContext) { ActionMapping mapping = actionContext.getActionMapping(); if (mapping != null) { - return HttpParameters.create(mapping.getParams()).buildNoNestedWrapping(); + return HttpParameters.create(mapping.getParams()).build(); } else { - return HttpParameters.create().buildNoNestedWrapping(); + return HttpParameters.create().build(); } } @@ -101,7 +101,6 @@ protected HttpParameters retrieveParameters(ActionContext actionContext) { protected void addParametersToContext(ActionContext ac, Map newParams) { HttpParameters previousParams = ac.getParameters(); HttpParameters.Builder combinedParams = HttpParameters.create().withParent(previousParams).withExtraParams(newParams); - - ac.withParameters(combinedParams.buildNoNestedWrapping()); + ac.withParameters(combinedParams.build()); } } diff --git a/core/src/main/java/org/apache/struts2/interceptor/csp/CspSettings.java b/core/src/main/java/org/apache/struts2/interceptor/csp/CspSettings.java index 3132b9d6a8..0548dde2e1 100644 --- a/core/src/main/java/org/apache/struts2/interceptor/csp/CspSettings.java +++ b/core/src/main/java/org/apache/struts2/interceptor/csp/CspSettings.java @@ -44,12 +44,6 @@ public interface CspSettings { String HTTPS = "https:"; String CSP_REPORT_TYPE = "application/csp-report"; - /** - * @deprecated use {@link #addCspHeaders(HttpServletRequest, HttpServletResponse)} instead - */ - @Deprecated - void addCspHeaders(HttpServletResponse response); - void addCspHeaders(HttpServletRequest request, HttpServletResponse response); /** diff --git a/core/src/main/java/org/apache/struts2/interceptor/csp/DefaultCspSettings.java b/core/src/main/java/org/apache/struts2/interceptor/csp/DefaultCspSettings.java index 338a29914f..399ef4a4c7 100644 --- a/core/src/main/java/org/apache/struts2/interceptor/csp/DefaultCspSettings.java +++ b/core/src/main/java/org/apache/struts2/interceptor/csp/DefaultCspSettings.java @@ -18,12 +18,12 @@ */ package org.apache.struts2.interceptor.csp; +import jakarta.servlet.http.HttpServletRequest; +import jakarta.servlet.http.HttpServletResponse; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; import org.apache.struts2.action.CspSettingsAware; -import jakarta.servlet.http.HttpServletRequest; -import jakarta.servlet.http.HttpServletResponse; import java.security.SecureRandom; import java.util.Base64; import java.util.Objects; @@ -52,11 +52,6 @@ public class DefaultCspSettings implements CspSettings { // default to reporting mode protected String cspHeader = CSP_REPORT_HEADER; - @Override - public void addCspHeaders(HttpServletResponse response) { - throw new UnsupportedOperationException("Unsupported implementation, use #addCspHeaders(HttpServletRequest request, HttpServletResponse response)"); - } - @Override public void addCspHeaders(HttpServletRequest request, HttpServletResponse response) { if (isSessionActive(request)) { diff --git a/core/src/main/java/org/apache/struts2/interceptor/parameter/ParametersInterceptor.java b/core/src/main/java/org/apache/struts2/interceptor/parameter/ParametersInterceptor.java index 75bc44abe4..ee8e8f781f 100644 --- a/core/src/main/java/org/apache/struts2/interceptor/parameter/ParametersInterceptor.java +++ b/core/src/main/java/org/apache/struts2/interceptor/parameter/ParametersInterceptor.java @@ -375,15 +375,6 @@ protected boolean hasValidAnnotatedMember(String rootProperty, Object action, lo return hasValidAnnotatedField(action, rootProperty, paramDepth); } - /** - * @deprecated since 6.5.0, use {@link #hasValidAnnotatedPropertyDescriptor(Object, PropertyDescriptor, long)} - * instead. - */ - @Deprecated - protected boolean hasValidAnnotatedPropertyDescriptor(PropertyDescriptor propDesc, long paramDepth) { - return hasValidAnnotatedPropertyDescriptor(null, propDesc, paramDepth); - } - protected boolean hasValidAnnotatedPropertyDescriptor(Object action, PropertyDescriptor propDesc, long paramDepth) { Method relevantMethod = paramDepth == 0 ? propDesc.getWriteMethod() : propDesc.getReadMethod(); if (relevantMethod == null) { diff --git a/core/src/main/java/org/apache/struts2/ognl/ProviderAllowlist.java b/core/src/main/java/org/apache/struts2/ognl/ProviderAllowlist.java index 93f7506b7a..dc7842ac05 100644 --- a/core/src/main/java/org/apache/struts2/ognl/ProviderAllowlist.java +++ b/core/src/main/java/org/apache/struts2/ognl/ProviderAllowlist.java @@ -18,8 +18,6 @@ */ package org.apache.struts2.ognl; -import com.opensymphony.xwork2.config.ConfigurationProvider; - import java.util.HashMap; import java.util.HashSet; import java.util.Map; @@ -52,14 +50,6 @@ public synchronized void registerAllowlist(Object key, Set> allowlist) this.allowlistClasses.addAll(allowlist); } - /** - * @deprecated since 6.6.0, use {@link #registerAllowlist(Object, Set)} - */ - @Deprecated - public synchronized void registerAllowlist(ConfigurationProvider configurationProvider, Set> allowlist) { - registerAllowlist((Object) configurationProvider, allowlist); - } - public synchronized void clearAllowlist(Object key) { Set> allowlist = allowlistMap.get(key); if (allowlist == null) { @@ -69,14 +59,6 @@ public synchronized void clearAllowlist(Object key) { reconstructAllowlist(); } - /** - * @deprecated since 6.6.0, use {@link #clearAllowlist(Object)} - */ - @Deprecated - public synchronized void clearAllowlist(ConfigurationProvider configurationProvider) { - clearAllowlist((Object) configurationProvider); - } - public Set> getProviderAllowlist() { return unmodifiableSet(allowlistClasses); } diff --git a/core/src/main/java/org/apache/struts2/url/QueryStringParser.java b/core/src/main/java/org/apache/struts2/url/QueryStringParser.java index 84cfa45edb..c57d545bc1 100644 --- a/core/src/main/java/org/apache/struts2/url/QueryStringParser.java +++ b/core/src/main/java/org/apache/struts2/url/QueryStringParser.java @@ -28,12 +28,6 @@ */ public interface QueryStringParser extends Serializable { - /** - * @deprecated since Struts 6.2.0, use {@link #parse(String)} instead - */ - @Deprecated - Map parse(String queryString, boolean forceValueArray); - /** * @param queryString a query string to parse * @return a {@link Result} of parsing the query string diff --git a/core/src/main/java/org/apache/struts2/url/StrutsQueryStringParser.java b/core/src/main/java/org/apache/struts2/url/StrutsQueryStringParser.java index ec75215607..58944f1ea3 100644 --- a/core/src/main/java/org/apache/struts2/url/StrutsQueryStringParser.java +++ b/core/src/main/java/org/apache/struts2/url/StrutsQueryStringParser.java @@ -41,11 +41,6 @@ public StrutsQueryStringParser(UrlDecoder decoder) { this.decoder = decoder; } - @Override - public Map parse(String queryString, boolean forceValueArray) { - return parse(queryString).getQueryParams(); - } - @Override public Result parse(String queryString) { if (StringUtils.isEmpty(queryString)) { diff --git a/core/src/main/java/org/apache/struts2/util/ServletContextAware.java b/core/src/main/java/org/apache/struts2/util/ServletContextAware.java deleted file mode 100644 index 5937366436..0000000000 --- a/core/src/main/java/org/apache/struts2/util/ServletContextAware.java +++ /dev/null @@ -1,32 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE 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 org.apache.struts2.util; - -import jakarta.servlet.ServletContext; - -@Deprecated -public interface ServletContextAware extends org.apache.struts2.action.ServletContextAware { - - void setServletContext(ServletContext context); - - @Override - default void withServletContext(ServletContext context) { - setServletContext(context); - } -} diff --git a/core/src/main/java/org/apache/struts2/views/jsp/ui/AbstractUITag.java b/core/src/main/java/org/apache/struts2/views/jsp/ui/AbstractUITag.java index aecf265e69..31248c7860 100644 --- a/core/src/main/java/org/apache/struts2/views/jsp/ui/AbstractUITag.java +++ b/core/src/main/java/org/apache/struts2/views/jsp/ui/AbstractUITag.java @@ -18,11 +18,11 @@ */ package org.apache.struts2.views.jsp.ui; +import jakarta.servlet.jsp.JspException; +import jakarta.servlet.jsp.tagext.DynamicAttributes; import org.apache.struts2.components.UIBean; import org.apache.struts2.views.jsp.ComponentTagSupport; -import jakarta.servlet.jsp.JspException; -import jakarta.servlet.jsp.tagext.DynamicAttributes; import java.util.HashMap; import java.util.Map; @@ -137,14 +137,6 @@ public void setCssClass(String cssClass) { this.cssClass = cssClass; } - /** - * @deprecated Use {@link #setCssClass(String)} instead - */ - @Deprecated - public void setClass(String cssClass) { - this.cssClass = cssClass; - } - public void setCssStyle(String cssStyle) { this.cssStyle = cssStyle; } diff --git a/core/src/test/java/com/opensymphony/xwork2/util/StrutsLocalizedTextProviderTest.java b/core/src/test/java/com/opensymphony/xwork2/util/StrutsLocalizedTextProviderTest.java index 7bb8af612e..a7ba7f61e2 100644 --- a/core/src/test/java/com/opensymphony/xwork2/util/StrutsLocalizedTextProviderTest.java +++ b/core/src/test/java/com/opensymphony/xwork2/util/StrutsLocalizedTextProviderTest.java @@ -305,11 +305,6 @@ public void testLocalizedTextProviderClearingMethods() { assertEquals("testStrutsLocalizedTextProvider bundle map size not 6 after retrievals ?", 6, testStrutsLocalizedTextProvider.currentBundlesMapSize()); - // Expect the call to be ineffective due to deprecation and change to a "no-op" (but shouldn't throw an Exception or cause failure). - testStrutsLocalizedTextProvider.callClearBundleNoLocale("com/opensymphony/xwork2/test"); - assertEquals("testStrutsLocalizedTextProvider bundle map size not 6 after non-locale clear call ?", - 6, testStrutsLocalizedTextProvider.currentBundlesMapSize()); - // Expect the call to function with bundle name + locale. Remove all four of the non-default // bundles and confirm the bundle map size changes. testStrutsLocalizedTextProvider.callClearBundleWithLocale("com/opensymphony/xwork2/test", Locale.ENGLISH); @@ -595,10 +590,6 @@ class TestStrutsLocalizedTextProvider extends StrutsLocalizedTextProvider { */ private static final String RELOADED = "com.opensymphony.xwork2.util.LocalizedTextProvider.reloaded"; - public void callClearBundleNoLocale(String bundleName) { - super.clearBundle(bundleName); - } - public void callClearBundleWithLocale(String bundleName, Locale locale) { super.clearBundle(bundleName, locale); } From 4e4cf468a2778903cdac4e494acb59f1f9128bb1 Mon Sep 17 00:00:00 2001 From: Kusal Kithul-Godage Date: Thu, 25 Jul 2024 20:33:14 +1000 Subject: [PATCH 5/6] WW-5411 Delete deprecated code part 5 --- .../xwork2/ognl/SecurityMemberAccess.java | 14 -------- .../util/StrutsLocalizedTextProvider.java | 12 +++++-- .../reflection/ReflectionProviderFactory.java | 32 ------------------- .../xwork2/ognl/OgnlValueStackTest.java | 9 +++--- .../xwork2/ognl/SecurityMemberAccessTest.java | 10 ++++-- .../xwork2/ognl/SetPropertiesTest.java | 8 +++-- .../util/StrutsLocalizedTextProviderTest.java | 7 ++-- .../test/ExternalSecurityMemberAccess.java | 6 ++-- .../ExternalSecurityMemberAccessTest.java | 4 +-- .../interceptor/CspInterceptorTest.java | 6 ++-- .../parameter/ParametersInterceptorTest.java | 2 +- .../SecurityMemberAccessInServletsTest.java | 4 +-- 12 files changed, 42 insertions(+), 72 deletions(-) delete mode 100644 core/src/main/java/com/opensymphony/xwork2/util/reflection/ReflectionProviderFactory.java diff --git a/core/src/main/java/com/opensymphony/xwork2/ognl/SecurityMemberAccess.java b/core/src/main/java/com/opensymphony/xwork2/ognl/SecurityMemberAccess.java index f15b50af1e..29faaf3da5 100644 --- a/core/src/main/java/com/opensymphony/xwork2/ognl/SecurityMemberAccess.java +++ b/core/src/main/java/com/opensymphony/xwork2/ognl/SecurityMemberAccess.java @@ -112,20 +112,6 @@ public SecurityMemberAccess(@Inject ProviderAllowlist providerAllowlist, @Inject this.threadAllowlist = threadAllowlist; } - /** - * SecurityMemberAccess - * - access decisions based on whether member is static (or not) - * - block or allow access to properties (configurable-after-construction) - * - * @param allowStaticFieldAccess if set to true static fields (constants) will be accessible - * @deprecated since 6.4.0, use {@link #SecurityMemberAccess(ProviderAllowlist, ThreadAllowlist)} instead. - */ - @Deprecated - public SecurityMemberAccess(boolean allowStaticFieldAccess) { - this(null, null); - useAllowStaticFieldAccess(String.valueOf(allowStaticFieldAccess)); - } - @Override public Object setup(Map context, Object target, Member member, String propertyName) { Object result = null; diff --git a/core/src/main/java/com/opensymphony/xwork2/util/StrutsLocalizedTextProvider.java b/core/src/main/java/com/opensymphony/xwork2/util/StrutsLocalizedTextProvider.java index 441e52e474..abe407866c 100644 --- a/core/src/main/java/com/opensymphony/xwork2/util/StrutsLocalizedTextProvider.java +++ b/core/src/main/java/com/opensymphony/xwork2/util/StrutsLocalizedTextProvider.java @@ -22,7 +22,8 @@ import com.opensymphony.xwork2.ActionInvocation; import com.opensymphony.xwork2.ModelDriven; import com.opensymphony.xwork2.conversion.impl.XWorkConverter; -import com.opensymphony.xwork2.util.reflection.ReflectionProviderFactory; +import com.opensymphony.xwork2.inject.Inject; +import com.opensymphony.xwork2.util.reflection.ReflectionProvider; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; @@ -37,6 +38,7 @@ public class StrutsLocalizedTextProvider extends AbstractLocalizedTextProvider { private static final Logger LOG = LogManager.getLogger(StrutsLocalizedTextProvider.class); + private transient ReflectionProvider reflectionProvider; public StrutsLocalizedTextProvider() { addDefaultResourceBundle(XWORK_MESSAGES_BUNDLE); @@ -276,9 +278,9 @@ public String findText(Class aClass, String aTextName, Locale locale, String def if (prop != null) { Object obj = valueStack.findValue(prop); try { - Object actionObj = ReflectionProviderFactory.getInstance().getRealTarget(prop, valueStack.getContext(), valueStack.getRoot()); + Object actionObj = reflectionProvider.getRealTarget(prop, valueStack.getContext(), valueStack.getRoot()); if (actionObj != null) { - PropertyDescriptor propertyDescriptor = ReflectionProviderFactory.getInstance().getPropertyDescriptor(actionObj.getClass(), prop); + PropertyDescriptor propertyDescriptor = reflectionProvider.getPropertyDescriptor(actionObj.getClass(), prop); if (propertyDescriptor != null) { Class clazz = propertyDescriptor.getPropertyType(); @@ -373,4 +375,8 @@ public String findText(ResourceBundle bundle, String aTextName, Locale locale, S return findText(bundle, aTextName, locale, defaultMessage, args, valueStack); } + @Inject + public void setReflectionProvider(ReflectionProvider reflectionProvider) { + this.reflectionProvider = reflectionProvider; + } } diff --git a/core/src/main/java/com/opensymphony/xwork2/util/reflection/ReflectionProviderFactory.java b/core/src/main/java/com/opensymphony/xwork2/util/reflection/ReflectionProviderFactory.java deleted file mode 100644 index 55541add6b..0000000000 --- a/core/src/main/java/com/opensymphony/xwork2/util/reflection/ReflectionProviderFactory.java +++ /dev/null @@ -1,32 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE 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 com.opensymphony.xwork2.util.reflection; - -import com.opensymphony.xwork2.ActionContext; - -/** - * @deprecated inject RefectionProvider directly - */ -@Deprecated -public class ReflectionProviderFactory { - - public static ReflectionProvider getInstance() { - return ActionContext.getContext().getContainer().getInstance(ReflectionProvider.class); - } -} diff --git a/core/src/test/java/com/opensymphony/xwork2/ognl/OgnlValueStackTest.java b/core/src/test/java/com/opensymphony/xwork2/ognl/OgnlValueStackTest.java index a983b5d261..f6e5137102 100644 --- a/core/src/test/java/com/opensymphony/xwork2/ognl/OgnlValueStackTest.java +++ b/core/src/test/java/com/opensymphony/xwork2/ognl/OgnlValueStackTest.java @@ -26,7 +26,6 @@ import com.opensymphony.xwork2.conversion.impl.ConversionData; import com.opensymphony.xwork2.conversion.impl.XWorkConverter; import com.opensymphony.xwork2.inject.ContainerBuilder; -import com.opensymphony.xwork2.ognl.accessor.CompoundRootAccessor; import com.opensymphony.xwork2.ognl.accessor.RootAccessor; import com.opensymphony.xwork2.test.StubConfigurationProvider; import com.opensymphony.xwork2.test.TestBean2; @@ -1059,9 +1058,11 @@ public void testTypeConversionError() { public void testConstructorWithAStack() { vs.push("Hello World"); - OgnlValueStack stack2 = new OgnlValueStack(vs, - container.getInstance(XWorkConverter.class), - (CompoundRootAccessor) container.getInstance(RootAccessor.class), new SecurityMemberAccess(true)); + OgnlValueStack stack2 = new OgnlValueStack( + vs, + container.getInstance(XWorkConverter.class), + container.getInstance(RootAccessor.class), + new SecurityMemberAccess(null, null)); container.inject(stack2); assertEquals(vs.getRoot(), stack2.getRoot()); diff --git a/core/src/test/java/com/opensymphony/xwork2/ognl/SecurityMemberAccessTest.java b/core/src/test/java/com/opensymphony/xwork2/ognl/SecurityMemberAccessTest.java index d508ef99d0..47eb2fb231 100644 --- a/core/src/test/java/com/opensymphony/xwork2/ognl/SecurityMemberAccessTest.java +++ b/core/src/test/java/com/opensymphony/xwork2/ognl/SecurityMemberAccessTest.java @@ -58,8 +58,8 @@ public class SecurityMemberAccessTest { private Map context; private FooBar target; protected SecurityMemberAccess sma; - private ProviderAllowlist mockedProviderAllowlist; - private ThreadAllowlist mockedThreadAllowlist; + protected ProviderAllowlist mockedProviderAllowlist; + protected ThreadAllowlist mockedThreadAllowlist; @Before public void setUp() throws Exception { @@ -73,10 +73,14 @@ public void setUp() throws Exception { protected void assignNewSma(boolean allowStaticFieldAccess) { when(mockedProviderAllowlist.getProviderAllowlist()).thenReturn(new HashSet<>()); when(mockedThreadAllowlist.getAllowlist()).thenReturn(new HashSet<>()); - sma = new SecurityMemberAccess(mockedProviderAllowlist, mockedThreadAllowlist); + assignNewSmaHelper(); sma.useAllowStaticFieldAccess(String.valueOf(allowStaticFieldAccess)); } + protected void assignNewSmaHelper() { + sma = new SecurityMemberAccess(mockedProviderAllowlist, mockedThreadAllowlist); + } + private T reflectField(String fieldName) throws IllegalAccessException { return reflectField(sma, fieldName); } diff --git a/core/src/test/java/com/opensymphony/xwork2/ognl/SetPropertiesTest.java b/core/src/test/java/com/opensymphony/xwork2/ognl/SetPropertiesTest.java index cbd1f519e3..436dced893 100644 --- a/core/src/test/java/com/opensymphony/xwork2/ognl/SetPropertiesTest.java +++ b/core/src/test/java/com/opensymphony/xwork2/ognl/SetPropertiesTest.java @@ -38,7 +38,11 @@ import com.opensymphony.xwork2.util.reflection.ReflectionContextState; import ognl.Ognl; -import java.util.*; +import java.util.ArrayList; +import java.util.Collection; +import java.util.HashMap; +import java.util.HashSet; +import java.util.Map; /** @@ -57,7 +61,7 @@ public void setUp() throws Exception { } public void testOgnlUtilEmptyStringAsLong() { Bar bar = new Bar(); - Map context = Ognl.createDefaultContext(bar, new SecurityMemberAccess(true)); + Map context = Ognl.createDefaultContext(bar, new SecurityMemberAccess(null, null)); context.put(XWorkConverter.REPORT_CONVERSION_ERRORS, Boolean.TRUE); bar.setId(null); diff --git a/core/src/test/java/com/opensymphony/xwork2/util/StrutsLocalizedTextProviderTest.java b/core/src/test/java/com/opensymphony/xwork2/util/StrutsLocalizedTextProviderTest.java index a7ba7f61e2..7c19a5f0e3 100644 --- a/core/src/test/java/com/opensymphony/xwork2/util/StrutsLocalizedTextProviderTest.java +++ b/core/src/test/java/com/opensymphony/xwork2/util/StrutsLocalizedTextProviderTest.java @@ -581,7 +581,7 @@ protected void tearDown() throws Exception { * * @since 6.0.0 */ - class TestStrutsLocalizedTextProvider extends StrutsLocalizedTextProvider { + static class TestStrutsLocalizedTextProvider extends StrutsLocalizedTextProvider { /** * Some test correctness depends on this {@link #RELOADED} value matching that of the private ancestor @@ -624,9 +624,8 @@ public void callReloadBundlesForceReload() { * @return true if resource bundles reloaded indicator is true, false otherwise (including if value was never set). */ public boolean getBundlesReloadedIndicatorValue() { - final ActionContext actionContext = ActionContext.getContext(); - final Object reloadedObject = actionContext.get(RELOADED); - return ((reloadedObject instanceof Boolean) ? ((Boolean) reloadedObject).booleanValue() : false); + final Object reloadedObject = ActionContext.getContext().get(RELOADED); + return reloadedObject instanceof Boolean && (Boolean) reloadedObject; } } } diff --git a/core/src/test/java/com/test/ExternalSecurityMemberAccess.java b/core/src/test/java/com/test/ExternalSecurityMemberAccess.java index a53f1736bf..4043e9ada9 100644 --- a/core/src/test/java/com/test/ExternalSecurityMemberAccess.java +++ b/core/src/test/java/com/test/ExternalSecurityMemberAccess.java @@ -19,11 +19,13 @@ package com.test; import com.opensymphony.xwork2.ognl.SecurityMemberAccess; +import org.apache.struts2.ognl.ProviderAllowlist; +import org.apache.struts2.ognl.ThreadAllowlist; class ExternalSecurityMemberAccess extends SecurityMemberAccess { - ExternalSecurityMemberAccess(boolean allowStaticFieldAccess) { - super(allowStaticFieldAccess); + public ExternalSecurityMemberAccess(ProviderAllowlist providerAllowlist, ThreadAllowlist threadAllowlist) { + super(providerAllowlist, threadAllowlist); } @Override diff --git a/core/src/test/java/com/test/ExternalSecurityMemberAccessTest.java b/core/src/test/java/com/test/ExternalSecurityMemberAccessTest.java index a418e6b4ec..5fd642eb01 100644 --- a/core/src/test/java/com/test/ExternalSecurityMemberAccessTest.java +++ b/core/src/test/java/com/test/ExternalSecurityMemberAccessTest.java @@ -27,7 +27,7 @@ public class ExternalSecurityMemberAccessTest extends SecurityMemberAccessTest { @Override - protected void assignNewSma(boolean allowStaticFieldAccess) { - sma = new ExternalSecurityMemberAccess(allowStaticFieldAccess); + protected void assignNewSmaHelper() { + sma = new ExternalSecurityMemberAccess(mockedProviderAllowlist, mockedThreadAllowlist); } } diff --git a/core/src/test/java/org/apache/struts2/interceptor/CspInterceptorTest.java b/core/src/test/java/org/apache/struts2/interceptor/CspInterceptorTest.java index f913f74d56..94d86cf46e 100644 --- a/core/src/test/java/org/apache/struts2/interceptor/CspInterceptorTest.java +++ b/core/src/test/java/org/apache/struts2/interceptor/CspInterceptorTest.java @@ -21,6 +21,8 @@ import com.opensymphony.xwork2.ActionContext; import com.opensymphony.xwork2.config.ConfigurationException; import com.opensymphony.xwork2.mock.MockActionInvocation; +import jakarta.servlet.http.HttpServletRequest; +import jakarta.servlet.http.HttpSession; import org.apache.logging.log4j.util.Strings; import org.apache.struts2.StrutsInternalTestCase; import org.apache.struts2.TestAction; @@ -32,9 +34,6 @@ import org.springframework.mock.web.MockHttpServletRequest; import org.springframework.mock.web.MockHttpServletResponse; -import jakarta.servlet.http.HttpSession; -import jakarta.servlet.http.HttpServletRequest; - import static org.junit.Assert.assertNotEquals; public class CspInterceptorTest extends StrutsInternalTestCase { @@ -312,6 +311,7 @@ public CspSettings getCspSettings() { */ public static class CustomDefaultCspSettings extends DefaultCspSettings { + @Override protected String createPolicyFormat(HttpServletRequest request) { return "foo"; } diff --git a/core/src/test/java/org/apache/struts2/interceptor/parameter/ParametersInterceptorTest.java b/core/src/test/java/org/apache/struts2/interceptor/parameter/ParametersInterceptorTest.java index 9bcc70ae00..b5caa3d265 100644 --- a/core/src/test/java/org/apache/struts2/interceptor/parameter/ParametersInterceptorTest.java +++ b/core/src/test/java/org/apache/struts2/interceptor/parameter/ParametersInterceptorTest.java @@ -965,7 +965,7 @@ private ValueStack createStubValueStack(final Map actual) { ValueStack stack = new OgnlValueStack( container.getInstance(XWorkConverter.class), (CompoundRootAccessor) container.getInstance(RootAccessor.class), - container.getInstance(TextProvider.class, "system"), new SecurityMemberAccess(true)) { + container.getInstance(TextProvider.class, "system"), new SecurityMemberAccess(null, null)) { @Override public void setValue(String expr, Object value) { actual.put(expr, value); diff --git a/core/src/test/java/org/apache/struts2/util/SecurityMemberAccessInServletsTest.java b/core/src/test/java/org/apache/struts2/util/SecurityMemberAccessInServletsTest.java index 9d934c36ee..68766c4779 100644 --- a/core/src/test/java/org/apache/struts2/util/SecurityMemberAccessInServletsTest.java +++ b/core/src/test/java/org/apache/struts2/util/SecurityMemberAccessInServletsTest.java @@ -38,7 +38,7 @@ public void setUp() throws Exception { public void testJavaxServletPackageAccess() throws Exception { // given - SecurityMemberAccess sma = new SecurityMemberAccess(true); + SecurityMemberAccess sma = new SecurityMemberAccess(null, null); sma.useExcludedPackageNamePatterns("^(?!jakarta\\.servlet\\..+)(jakarta\\..+)"); @@ -54,7 +54,7 @@ public void testJavaxServletPackageAccess() throws Exception { public void testJavaxServletPackageExclusion() throws Exception { // given - SecurityMemberAccess sma = new SecurityMemberAccess(true); + SecurityMemberAccess sma = new SecurityMemberAccess(null, null); sma.useExcludedPackageNamePatterns("^jakarta\\..+"); From aec78dd1619586171b5c71278fa59949441521b1 Mon Sep 17 00:00:00 2001 From: Kusal Kithul-Godage Date: Thu, 25 Jul 2024 21:16:56 +1000 Subject: [PATCH 6/6] WW-5411 Misc code cleanup --- .../application/TestDataProvider.java | 23 ++++++++------ .../struts2/showcase/hangman/Hangman.java | 29 ++++++----------- .../struts2/showcase/hangman/Vocab.java | 31 +++++++------------ .../opensymphony/xwork2/ActionSupport.java | 8 +++-- .../xwork2/DefaultTextProvider.java | 4 +-- .../xwork2/inject/ContainerImpl.java | 2 +- .../xwork2/ognl/OgnlValueStack.java | 2 ++ .../xwork2/ognl/SecurityMemberAccess.java | 29 +++++++---------- .../xwork2/util/fs/DefaultFileManager.java | 9 ++++-- .../PrefixBasedActionProxyFactory.java | 12 ++----- .../debugging/DebuggingInterceptor.java | 11 ++++--- .../result/ServletActionRedirectResult.java | 3 +- .../struts2/result/ServletRedirectResult.java | 7 ++--- .../struts2/url/StrutsQueryStringParser.java | 3 +- .../org/apache/struts2/util/MakeIterator.java | 4 +-- .../convention/DefaultResultMapBuilder.java | 13 ++++---- 16 files changed, 84 insertions(+), 106 deletions(-) diff --git a/apps/showcase/src/main/java/org/apache/struts2/showcase/application/TestDataProvider.java b/apps/showcase/src/main/java/org/apache/struts2/showcase/application/TestDataProvider.java index 6e60ebfddc..25cfa32986 100644 --- a/apps/showcase/src/main/java/org/apache/struts2/showcase/application/TestDataProvider.java +++ b/apps/showcase/src/main/java/org/apache/struts2/showcase/application/TestDataProvider.java @@ -31,6 +31,7 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; +import java.io.Serial; import java.io.Serializable; import java.util.Arrays; import java.util.Date; @@ -41,6 +42,7 @@ @Service public class TestDataProvider implements Serializable, InitializingBean { + @Serial private static final long serialVersionUID = 1L; private static final Logger log = LogManager.getLogger(TestDataProvider.class); @@ -64,9 +66,9 @@ public class TestDataProvider implements Serializable, InitializingBean { }; public static final Employee[] TEST_EMPLOYEES = { - new Employee(new Long(1), "Alan", "Smithee", new Date(), new Float(2000f), true, POSITIONS[0], + new Employee(1L, "Alan", "Smithee", new Date(), 2000f, true, POSITIONS[0], TEST_SKILLS[0], null, "alan", LEVELS[0], "Nice guy"), - new Employee(new Long(2), "Robert", "Robson", new Date(), new Float(10000f), false, POSITIONS[1], + new Employee(2L, "Robert", "Robson", new Date(), 10000f, false, POSITIONS[1], TEST_SKILLS[1], Arrays.asList(TEST_SKILLS).subList(1, TEST_SKILLS.length), "rob", LEVELS[1], "Smart guy") }; @@ -78,27 +80,27 @@ public class TestDataProvider implements Serializable, InitializingBean { protected void addTestSkills() { try { - for (int i = 0, j = TEST_SKILLS.length; i < j; i++) { - skillDao.merge(TEST_SKILLS[i]); - } + for (Skill testSkill : TEST_SKILLS) { + skillDao.merge(testSkill); + } if (log.isInfoEnabled()) { log.info("TestDataProvider - [addTestSkills]: Added test skill data."); } } catch (StorageException e) { - log.error("TestDataProvider - [addTestSkills]: Exception catched: " + e.getMessage()); + log.error("TestDataProvider - [addTestSkills]: Exception caught: {}", e.getMessage()); } } protected void addTestEmployees() { try { - for (int i = 0, j = TEST_EMPLOYEES.length; i < j; i++) { - employeeDao.merge(TEST_EMPLOYEES[i]); - } + for (Employee testEmployee : TEST_EMPLOYEES) { + employeeDao.merge(testEmployee); + } if (log.isInfoEnabled()) { log.info("TestDataProvider - [addTestEmployees]: Added test employee data."); } } catch (StorageException e) { - log.error("TestDataProvider - [addTestEmployees]: Exception catched: " + e.getMessage()); + log.error("TestDataProvider - [addTestEmployees]: Exception caught: {}", e.getMessage()); } } @@ -107,6 +109,7 @@ protected void addTestData() { addTestEmployees(); } + @Override public void afterPropertiesSet() throws Exception { addTestData(); } diff --git a/apps/showcase/src/main/java/org/apache/struts2/showcase/hangman/Hangman.java b/apps/showcase/src/main/java/org/apache/struts2/showcase/hangman/Hangman.java index 4dce5521cd..99696ce3a3 100644 --- a/apps/showcase/src/main/java/org/apache/struts2/showcase/hangman/Hangman.java +++ b/apps/showcase/src/main/java/org/apache/struts2/showcase/hangman/Hangman.java @@ -20,40 +20,29 @@ */ package org.apache.struts2.showcase.hangman; +import java.io.Serial; import java.io.Serializable; import java.util.ArrayList; -import java.util.Arrays; import java.util.List; public class Hangman implements Serializable { + @Serial private static final long serialVersionUID = 8566954355839652509L; - private Vocab vocab; + private final Vocab vocab; private Boolean win = false; private int guessLeft = 5; - public List charactersAvailable; + public final List charactersAvailable; public List charactersGuessed; public Hangman(Vocab vocab) { - // Arrays.asList(...) returns List that doesn't support remove(), hence - // we wrap it with an ArrayList to avoid UnsupportedOperationException - // when doing a remove() - charactersAvailable = new ArrayList(Arrays.asList( - new Character[]{ - Character.valueOf('A'), Character.valueOf('B'), Character.valueOf('C'), - Character.valueOf('D'), Character.valueOf('E'), Character.valueOf('F'), - Character.valueOf('G'), Character.valueOf('H'), Character.valueOf('I'), - Character.valueOf('J'), Character.valueOf('K'), Character.valueOf('L'), - Character.valueOf('M'), Character.valueOf('N'), Character.valueOf('O'), - Character.valueOf('P'), Character.valueOf('Q'), Character.valueOf('R'), - Character.valueOf('S'), Character.valueOf('T'), Character.valueOf('U'), - Character.valueOf('V'), Character.valueOf('W'), Character.valueOf('X'), - Character.valueOf('Y'), Character.valueOf('Z') - })); - charactersGuessed = new ArrayList(); + charactersAvailable = new ArrayList<>(List.of( + 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', + 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z')); + charactersGuessed = new ArrayList<>(); this.vocab = vocab; } @@ -98,7 +87,7 @@ public Integer guessLeft() { public List getCharactersAvailable() { synchronized (charactersAvailable) { - return new ArrayList(charactersAvailable); + return new ArrayList<>(charactersAvailable); //return charactersAvailable; } } diff --git a/apps/showcase/src/main/java/org/apache/struts2/showcase/hangman/Vocab.java b/apps/showcase/src/main/java/org/apache/struts2/showcase/hangman/Vocab.java index 80f8b470d1..3be7bc72c4 100644 --- a/apps/showcase/src/main/java/org/apache/struts2/showcase/hangman/Vocab.java +++ b/apps/showcase/src/main/java/org/apache/struts2/showcase/hangman/Vocab.java @@ -20,17 +20,19 @@ */ package org.apache.struts2.showcase.hangman; +import java.io.Serial; import java.io.Serializable; -import java.util.ArrayList; import java.util.Arrays; +import java.util.HashSet; import java.util.List; public class Vocab implements Serializable { + @Serial private static final long serialVersionUID = 1L; - private String vocab; - private String hint; + private final String vocab; + private final String hint; private Character[] characters; // character this vocab is made up of public Vocab(String vocab, String hint) { @@ -52,7 +54,7 @@ public String getHint() { public Boolean containCharacter(Character character) { assert (character != null); - return (vocab.contains(character.toString())) ? true : false; + return vocab.contains(character.toString()); } public Character[] inCharacters() { @@ -60,32 +62,21 @@ public Character[] inCharacters() { char[] c = vocab.toCharArray(); characters = new Character[c.length]; for (int a = 0; a < c.length; a++) { - characters[a] = Character.valueOf(c[a]); + characters[a] = c[a]; } } return characters; } public boolean containsAllCharacter(List charactersGuessed) { - Character[] chars = inCharacters(); - List tmpChars = Arrays.asList(chars); - return charactersGuessed.containsAll(tmpChars); + return new HashSet<>(charactersGuessed).containsAll(Arrays.asList(inCharacters())); } - public static void main(String args[]) throws Exception { + public static void main(String[] args) throws Exception { Vocab v = new Vocab("JAVA", "a java word"); - List list1 = new ArrayList(); - list1.add(new Character('J')); - list1.add(new Character('V')); - - List list2 = new ArrayList(); - list2.add(new Character('J')); - list2.add(new Character('V')); - list2.add(new Character('A')); - - System.out.println(v.containsAllCharacter(list1)); - System.out.println(v.containsAllCharacter(list2)); + System.out.println(v.containsAllCharacter(List.of('J', 'V'))); + System.out.println(v.containsAllCharacter(List.of('J', 'V', 'A'))); } } diff --git a/core/src/main/java/com/opensymphony/xwork2/ActionSupport.java b/core/src/main/java/com/opensymphony/xwork2/ActionSupport.java index ab1a18099a..33a88be368 100644 --- a/core/src/main/java/com/opensymphony/xwork2/ActionSupport.java +++ b/core/src/main/java/com/opensymphony/xwork2/ActionSupport.java @@ -28,7 +28,11 @@ import org.apache.struts2.StrutsConstants; import java.io.Serializable; -import java.util.*; +import java.util.Collection; +import java.util.List; +import java.util.Locale; +import java.util.Map; +import java.util.ResourceBundle; /** * Provides a default implementation for the most common actions. @@ -160,7 +164,7 @@ public String getFormatted(String key, String expr) { } else { final ValueStack valueStack = ActionContext.getContext().getValueStack(); final Object val = valueStack.findValue(expr); - return getText(key, Arrays.asList(val)); + return getText(key, List.of(val)); } } diff --git a/core/src/main/java/com/opensymphony/xwork2/DefaultTextProvider.java b/core/src/main/java/com/opensymphony/xwork2/DefaultTextProvider.java index 5fe207ecd0..a4b514c7d9 100644 --- a/core/src/main/java/com/opensymphony/xwork2/DefaultTextProvider.java +++ b/core/src/main/java/com/opensymphony/xwork2/DefaultTextProvider.java @@ -103,7 +103,7 @@ public String getText(String key, String defaultValue, List args) { return format.format(params); } - return text; + return text; } public String getText(String key, String defaultValue, String[] args) { @@ -136,7 +136,7 @@ public String getText(String key, String defaultValue, List args, ValueStack public String getText(String key, String defaultValue, String[] args, ValueStack stack) { //we're not using the value stack here - List values = new ArrayList(Arrays.asList(args)); + List values = new ArrayList<>(Arrays.asList(args)); return getText(key, defaultValue, values); } diff --git a/core/src/main/java/com/opensymphony/xwork2/inject/ContainerImpl.java b/core/src/main/java/com/opensymphony/xwork2/inject/ContainerImpl.java index 455f8a4495..b11bb4e3a0 100644 --- a/core/src/main/java/com/opensymphony/xwork2/inject/ContainerImpl.java +++ b/core/src/main/java/com/opensymphony/xwork2/inject/ContainerImpl.java @@ -118,7 +118,7 @@ void injectStatics(List> staticInjections) { } void addInjectorsForMethods(Method[] methods, boolean statics, List injectors) { - addInjectorsForMembers(Arrays.asList(methods), statics, injectors, MethodInjector::new); + addInjectorsForMembers(List.of(methods), statics, injectors, MethodInjector::new); } void addInjectorsForFields(Field[] fields, boolean statics, List injectors) { diff --git a/core/src/main/java/com/opensymphony/xwork2/ognl/OgnlValueStack.java b/core/src/main/java/com/opensymphony/xwork2/ognl/OgnlValueStack.java index 0da14020dc..a052305d08 100644 --- a/core/src/main/java/com/opensymphony/xwork2/ognl/OgnlValueStack.java +++ b/core/src/main/java/com/opensymphony/xwork2/ognl/OgnlValueStack.java @@ -40,6 +40,7 @@ import org.apache.struts2.StrutsConstants; import org.apache.struts2.StrutsException; +import java.io.Serial; import java.io.Serializable; import java.util.HashMap; import java.util.Map; @@ -61,6 +62,7 @@ public class OgnlValueStack implements Serializable, ValueStack, ClearableValueS private static final Logger LOG = LogManager.getLogger(OgnlValueStack.class); + @Serial private static final long serialVersionUID = 370737852934925530L; private static final String MAP_IDENTIFIER_KEY = "com.opensymphony.xwork2.util.OgnlValueStack.MAP_IDENTIFIER_KEY"; diff --git a/core/src/main/java/com/opensymphony/xwork2/ognl/SecurityMemberAccess.java b/core/src/main/java/com/opensymphony/xwork2/ognl/SecurityMemberAccess.java index 29faaf3da5..8223d86ad8 100644 --- a/core/src/main/java/com/opensymphony/xwork2/ognl/SecurityMemberAccess.java +++ b/core/src/main/java/com/opensymphony/xwork2/ognl/SecurityMemberAccess.java @@ -33,13 +33,12 @@ import java.lang.reflect.Field; import java.lang.reflect.Member; import java.lang.reflect.Modifier; -import java.util.Arrays; -import java.util.HashSet; import java.util.List; import java.util.Map; import java.util.Set; import java.util.regex.Matcher; import java.util.regex.Pattern; +import java.util.stream.IntStream; import static com.opensymphony.xwork2.util.ConfigParseUtil.toClassObjectsSet; import static com.opensymphony.xwork2.util.ConfigParseUtil.toClassesSet; @@ -49,8 +48,6 @@ import static com.opensymphony.xwork2.util.ConfigParseUtil.toPackageNamesSet; import static java.text.MessageFormat.format; import static java.util.Collections.emptySet; -import static java.util.Collections.singletonList; -import static java.util.Collections.unmodifiableSet; import static org.apache.struts2.StrutsConstants.STRUTS_ALLOWLIST_CLASSES; import static org.apache.struts2.StrutsConstants.STRUTS_ALLOWLIST_PACKAGE_NAMES; @@ -62,20 +59,20 @@ public class SecurityMemberAccess implements MemberAccess { private static final Logger LOG = LogManager.getLogger(SecurityMemberAccess.class); - private static final Set ALLOWLIST_REQUIRED_PACKAGES = unmodifiableSet(new HashSet<>(Arrays.asList( + private static final Set ALLOWLIST_REQUIRED_PACKAGES = Set.of( "com.opensymphony.xwork2.validator.validators", "org.apache.struts2.components", "org.apache.struts2.views.jsp" - ))); + ); - private static final Set> ALLOWLIST_REQUIRED_CLASSES = unmodifiableSet(new HashSet<>(Arrays.asList( + private static final Set> ALLOWLIST_REQUIRED_CLASSES = Set.of( java.lang.Enum.class, java.lang.String.class, java.util.Date.class, java.util.HashMap.class, java.util.Map.class, java.util.Map.Entry.class - ))); + ); private final ProviderAllowlist providerAllowlist; private final ThreadAllowlist threadAllowlist; @@ -85,7 +82,7 @@ public class SecurityMemberAccess implements MemberAccess { private Set excludeProperties = emptySet(); private Set acceptProperties = emptySet(); - private Set excludedClasses = unmodifiableSet(new HashSet<>(singletonList(Object.class.getName()))); + private Set excludedClasses = Set.of(Object.class.getName()); private Set excludedPackageNamePatterns = emptySet(); private Set excludedPackageNames = emptySet(); private Set excludedPackageExemptClasses = emptySet(); @@ -93,7 +90,7 @@ public class SecurityMemberAccess implements MemberAccess { private static volatile boolean isDevModeLogged = false; private volatile boolean isDevModeInit; private boolean isDevMode; - private Set devModeExcludedClasses = unmodifiableSet(new HashSet<>(singletonList(Object.class.getName()))); + private Set devModeExcludedClasses = Set.of(Object.class.getName()); private Set devModeExcludedPackageNamePatterns = emptySet(); private Set devModeExcludedPackageNames = emptySet(); private Set devModeExcludedPackageExemptClasses = emptySet(); @@ -395,14 +392,10 @@ protected boolean isExcludedPackageNames(Class clazz) { } public static boolean isClassBelongsToPackages(Class clazz, Set matchingPackages) { - List packageParts = Arrays.asList(toPackageName(clazz).split("\\.")); - for (int i = 0; i < packageParts.size(); i++) { - String parentPackage = String.join(".", packageParts.subList(0, i + 1)); - if (matchingPackages.contains(parentPackage)) { - return true; - } - } - return false; + List packageParts = List.of(toPackageName(clazz).split("\\.")); + return IntStream.range(0, packageParts.size()) + .mapToObj(i -> String.join(".", packageParts.subList(0, i + 1))) + .anyMatch(matchingPackages::contains); } protected boolean isClassExcluded(Class clazz) { diff --git a/core/src/main/java/com/opensymphony/xwork2/util/fs/DefaultFileManager.java b/core/src/main/java/com/opensymphony/xwork2/util/fs/DefaultFileManager.java index 5708bd5f22..15b882fd4a 100644 --- a/core/src/main/java/com/opensymphony/xwork2/util/fs/DefaultFileManager.java +++ b/core/src/main/java/com/opensymphony/xwork2/util/fs/DefaultFileManager.java @@ -26,7 +26,12 @@ import java.io.InputStream; import java.net.MalformedURLException; import java.net.URL; -import java.util.*; +import java.util.ArrayList; +import java.util.Collection; +import java.util.Collections; +import java.util.HashMap; +import java.util.List; +import java.util.Map; import java.util.regex.Matcher; import java.util.regex.Pattern; @@ -158,7 +163,7 @@ public boolean internal() { } public Collection getAllPhysicalUrls(URL url) throws IOException { - return Arrays.asList(url); + return List.of(url); } } diff --git a/core/src/main/java/org/apache/struts2/factory/PrefixBasedActionProxyFactory.java b/core/src/main/java/org/apache/struts2/factory/PrefixBasedActionProxyFactory.java index 03052ec6a2..7b6133a5fe 100644 --- a/core/src/main/java/org/apache/struts2/factory/PrefixBasedActionProxyFactory.java +++ b/core/src/main/java/org/apache/struts2/factory/PrefixBasedActionProxyFactory.java @@ -20,15 +20,12 @@ import com.opensymphony.xwork2.ActionProxy; import com.opensymphony.xwork2.ActionProxyFactory; -import com.opensymphony.xwork2.DefaultActionProxyFactory; -import com.opensymphony.xwork2.inject.Container; import com.opensymphony.xwork2.inject.Initializable; import com.opensymphony.xwork2.inject.Inject; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; import org.apache.struts2.StrutsConstants; -import java.util.Arrays; import java.util.HashMap; import java.util.HashSet; import java.util.Map; @@ -63,18 +60,13 @@ public class PrefixBasedActionProxyFactory extends StrutsActionProxyFactory impl private static final Logger LOG = LogManager.getLogger(PrefixBasedActionProxyFactory.class); - private Map actionProxyFactories = new HashMap<>(); + private final Map actionProxyFactories = new HashMap<>(); private Set prefixes = new HashSet<>(); - @Inject - public void setContainer(Container container) { - this.container = container; - } - @Inject(StrutsConstants.PREFIX_BASED_MAPPER_CONFIGURATION) public void setPrefixBasedActionProxyFactories(String list) { if (list != null) { - prefixes = new HashSet<>(Arrays.asList(list.split(","))); + prefixes = Set.of(list.split(",")); } } diff --git a/core/src/main/java/org/apache/struts2/interceptor/debugging/DebuggingInterceptor.java b/core/src/main/java/org/apache/struts2/interceptor/debugging/DebuggingInterceptor.java index 4daec590b5..869f382c38 100644 --- a/core/src/main/java/org/apache/struts2/interceptor/debugging/DebuggingInterceptor.java +++ b/core/src/main/java/org/apache/struts2/interceptor/debugging/DebuggingInterceptor.java @@ -25,6 +25,7 @@ import com.opensymphony.xwork2.interceptor.PreResultListener; import com.opensymphony.xwork2.util.ValueStack; import com.opensymphony.xwork2.util.reflection.ReflectionProvider; +import jakarta.servlet.http.HttpServletResponse; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; import org.apache.struts2.ServletActionContext; @@ -36,21 +37,20 @@ import org.apache.struts2.views.freemarker.FreemarkerManager; import org.apache.struts2.views.freemarker.FreemarkerResult; -import jakarta.servlet.http.HttpServletResponse; import java.beans.BeanInfo; import java.beans.Introspector; import java.beans.PropertyDescriptor; import java.io.IOException; import java.io.PrintWriter; +import java.io.Serial; import java.io.StringWriter; import java.lang.reflect.Array; import java.lang.reflect.Method; import java.util.ArrayList; -import java.util.Arrays; import java.util.Collection; -import java.util.HashSet; import java.util.List; import java.util.Map; +import java.util.Set; /** * @@ -95,17 +95,18 @@ */ public class DebuggingInterceptor extends AbstractInterceptor { + @Serial private static final long serialVersionUID = -3097324155953078783L; private final static Logger LOG = LogManager.getLogger(DebuggingInterceptor.class); private final String[] ignorePrefixes = new String[]{"org.apache.struts.", "com.opensymphony.xwork2.", "xwork."}; - private final HashSet ignoreKeys = new HashSet<>(Arrays.asList( + private final Set ignoreKeys = Set.of( DispatcherConstants.APPLICATION, DispatcherConstants.SESSION, DispatcherConstants.PARAMETERS, DispatcherConstants.REQUEST - )); + ); private final static String XML_MODE = "xml"; private final static String CONSOLE_MODE = "console"; diff --git a/core/src/main/java/org/apache/struts2/result/ServletActionRedirectResult.java b/core/src/main/java/org/apache/struts2/result/ServletActionRedirectResult.java index dc6ac2191d..f5fce489ea 100644 --- a/core/src/main/java/org/apache/struts2/result/ServletActionRedirectResult.java +++ b/core/src/main/java/org/apache/struts2/result/ServletActionRedirectResult.java @@ -23,7 +23,6 @@ import org.apache.struts2.dispatcher.mapper.ActionMapper; import org.apache.struts2.dispatcher.mapper.ActionMapping; -import java.util.Arrays; import java.util.List; /** @@ -210,7 +209,7 @@ public void setMethod(String method) { } protected List getProhibitedResultParams() { - return Arrays.asList( + return List.of( DEFAULT_PARAM, "namespace", "method", diff --git a/core/src/main/java/org/apache/struts2/result/ServletRedirectResult.java b/core/src/main/java/org/apache/struts2/result/ServletRedirectResult.java index c0e7390bdf..c9f12f584e 100644 --- a/core/src/main/java/org/apache/struts2/result/ServletRedirectResult.java +++ b/core/src/main/java/org/apache/struts2/result/ServletRedirectResult.java @@ -24,6 +24,8 @@ import com.opensymphony.xwork2.inject.Inject; import com.opensymphony.xwork2.util.reflection.ReflectionException; import com.opensymphony.xwork2.util.reflection.ReflectionExceptionHandler; +import jakarta.servlet.http.HttpServletRequest; +import jakarta.servlet.http.HttpServletResponse; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; import org.apache.struts2.dispatcher.Dispatcher; @@ -31,13 +33,10 @@ import org.apache.struts2.dispatcher.mapper.ActionMapping; import org.apache.struts2.url.QueryStringBuilder; -import jakarta.servlet.http.HttpServletRequest; -import jakarta.servlet.http.HttpServletResponse; import java.io.IOException; import java.net.MalformedURLException; import java.net.URI; import java.net.URL; -import java.util.Arrays; import java.util.Collection; import java.util.LinkedHashMap; import java.util.List; @@ -217,7 +216,7 @@ protected void doExecute(String finalLocation, ActionInvocation invocation) thro } protected List getProhibitedResultParams() { - return Arrays.asList( + return List.of( DEFAULT_PARAM, "namespace", "method", diff --git a/core/src/main/java/org/apache/struts2/url/StrutsQueryStringParser.java b/core/src/main/java/org/apache/struts2/url/StrutsQueryStringParser.java index 58944f1ea3..792ddb0d56 100644 --- a/core/src/main/java/org/apache/struts2/url/StrutsQueryStringParser.java +++ b/core/src/main/java/org/apache/struts2/url/StrutsQueryStringParser.java @@ -24,7 +24,6 @@ import org.apache.logging.log4j.Logger; import java.util.ArrayList; -import java.util.Arrays; import java.util.Collections; import java.util.LinkedHashMap; import java.util.List; @@ -123,7 +122,7 @@ public Result addParam(String name, String value) { } else { String[] currentParamValues = (String[]) currentParam; if (currentParamValues != null) { - List paramList = new ArrayList<>(Arrays.asList(currentParamValues)); + List paramList = new ArrayList<>(List.of(currentParamValues)); paramList.add(value); queryParams.put(name, paramList.toArray(new String[0])); } else { diff --git a/core/src/main/java/org/apache/struts2/util/MakeIterator.java b/core/src/main/java/org/apache/struts2/util/MakeIterator.java index 131d2f8b45..8411c23ca4 100644 --- a/core/src/main/java/org/apache/struts2/util/MakeIterator.java +++ b/core/src/main/java/org/apache/struts2/util/MakeIterator.java @@ -22,9 +22,9 @@ import java.lang.reflect.Array; import java.util.ArrayList; -import java.util.Arrays; import java.util.Enumeration; import java.util.Iterator; +import java.util.List; import java.util.Map; /** @@ -89,7 +89,7 @@ public static Iterator convert(Object value) { } else if (value instanceof Enumeration) { iterator = new EnumerationIterator((Enumeration) value); } else { - iterator = Arrays.asList(value).iterator(); + iterator = List.of(value).iterator(); } return iterator; diff --git a/plugins/convention/src/main/java/org/apache/struts2/convention/DefaultResultMapBuilder.java b/plugins/convention/src/main/java/org/apache/struts2/convention/DefaultResultMapBuilder.java index 51dd24ff6f..0bc877a419 100644 --- a/plugins/convention/src/main/java/org/apache/struts2/convention/DefaultResultMapBuilder.java +++ b/plugins/convention/src/main/java/org/apache/struts2/convention/DefaultResultMapBuilder.java @@ -26,11 +26,11 @@ import com.opensymphony.xwork2.config.entities.ResultTypeConfig; import com.opensymphony.xwork2.inject.Container; import com.opensymphony.xwork2.inject.Inject; -import com.opensymphony.xwork2.util.TextParseUtil; import com.opensymphony.xwork2.util.finder.ClassLoaderInterface; import com.opensymphony.xwork2.util.finder.ClassLoaderInterfaceDelegate; import com.opensymphony.xwork2.util.finder.ResourceFinder; import com.opensymphony.xwork2.util.finder.Test; +import jakarta.servlet.ServletContext; import org.apache.commons.lang3.BooleanUtils; import org.apache.commons.lang3.ObjectUtils; import org.apache.commons.lang3.StringUtils; @@ -39,10 +39,11 @@ import org.apache.struts2.convention.annotation.Result; import org.apache.struts2.convention.annotation.Results; -import jakarta.servlet.ServletContext; import java.io.IOException; import java.net.URL; -import java.util.*; +import java.util.HashMap; +import java.util.Map; +import java.util.Set; /** *

@@ -115,8 +116,8 @@ public class DefaultResultMapBuilder implements ResultMapBuilder { private static final Logger LOG = LogManager.getLogger(DefaultResultMapBuilder.class); private final ServletContext servletContext; - private Set relativeResultTypes; - private ConventionsService conventionsService; + private final Set relativeResultTypes; + private final ConventionsService conventionsService; private boolean flatResultLayout = true; /** @@ -131,7 +132,7 @@ public class DefaultResultMapBuilder implements ResultMapBuilder { public DefaultResultMapBuilder(ServletContext servletContext, Container container, @Inject(ConventionConstants.CONVENTION_RELATIVE_RESULT_TYPES) String relativeResultTypes) { this.servletContext = servletContext; - this.relativeResultTypes = new HashSet<>(Arrays.asList(relativeResultTypes.split("\\s*[,]\\s*"))); + this.relativeResultTypes = Set.of(relativeResultTypes.split("\\s*[,]\\s*")); this.conventionsService = container.getInstance(ConventionsService.class, container.getInstance(String.class, ConventionConstants.CONVENTION_CONVENTIONS_SERVICE)); }