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 9b74f76fc..e7cc1713b 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.LogManager; 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 2c4df91d9..000000000 --- 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 9edafe3fc..c57df3dab 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 @@ package com.opensymphony.xwork2.interceptor; 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 class AliasInterceptor extends AbstractInterceptor { 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 class AliasInterceptor extends AbstractInterceptor { 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 fa90a315c..f1919a8c9 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 @@ import com.opensymphony.xwork2.util.ValueStack; * 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 @@ import com.opensymphony.xwork2.util.ValueStack; * </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 d4fb7ad14..000000000 --- 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 1b402509c..000000000 --- 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 ae73871cd..000000000 --- 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 4c9a4e109..000000000 --- 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 aa9518208..000000000 --- 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 9d32a8a18..b95a0e6e6 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 @@ package com.opensymphony.xwork2.interceptor; 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 class StaticParametersInterceptor extends AbstractInterceptor { 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 class StaticParametersInterceptor extends AbstractInterceptor { } 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 39bfdcb26..000000000 --- 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 d1b7260ac..000000000 --- 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 e7b452022..000000000 --- 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 17ec80940..000000000 --- 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 bf0cd8493..e6038e302 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 @@ package org.apache.struts2; 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 class ServletActionContext implements StrutsStatics { } } - /** - * 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 326477bc4..70e06ce5c 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 c25cdc59c..152236e8e 100644 --- a/core/src/main/resources/xwork-default.xml +++ b/core/src/main/resources/xwork-default.xml @@ -38,8 +38,7 @@ - - +