|
Struts example source code file (ParameterFilterInterceptor.java)
The Struts ParameterFilterInterceptor.java source code/* * Copyright 2002-2007,2009 The Apache Software Foundation. * * 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.interceptor; import com.opensymphony.xwork2.ActionInvocation; import com.opensymphony.xwork2.util.TextParseUtil; import com.opensymphony.xwork2.util.logging.Logger; import com.opensymphony.xwork2.util.logging.LoggerFactory; import java.util.Collection; import java.util.HashSet; import java.util.Map; import java.util.TreeMap; /** * <!-- START SNIPPET: description --> * * 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. * * <!-- END SNIPPET: description --> * * <!-- START SNIPPET: parameters --> * * <ul> * <li>allowed - a comma delimited list of parameter prefixes * that are allowed to pass to the action</li> * <li>blocked - a comma delimited list of parameter prefixes * that are not allowed to pass to the action</li> * <li>defaultBlock - boolean (default to false) whether by * default a given parameter is blocked. If true, then a parameter * must have a prefix in the allowed list in order to be able * to pass to the action * </ul> * * <p>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.</p> * * <p>For example, if the parameters are: * <ul> * <li>blocked: person,person.address.createDate,personDao * <li>allowed: person.address * <li>defaultBlock: false * </ul> * <br> * 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).</p> * <!-- END SNIPPET: parameters --> * * <!-- START SNIPPET: extending --> * There are no known extension points to this interceptor. * <!-- END SNIPPET: extending --> * * <pre> * <!-- START SNIPPET: example --> * <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> * <!-- END SNIPPET: example --> * </pre> * * @author Gabe */ public class ParameterFilterInterceptor extends AbstractInterceptor { private static final Logger LOG = LoggerFactory.getLogger(ParameterFilterInterceptor.class); private Collection<String> allowed; private Collection<String> blocked; private Map<String, Boolean> includesExcludesMap; private boolean defaultBlock = false; @Override public String intercept(ActionInvocation invocation) throws Exception { Map<String, Object> parameters = invocation.getInvocationContext().getParameters(); HashSet<String> paramsToRemove = new HashSet Other Struts examples (source code examples)Here is a short list of links related to this Struts ParameterFilterInterceptor.java source code file: |
... this post is sponsored by my books ... | |
#1 New Release! |
FP Best Seller |
Copyright 1998-2021 Alvin Alexander, alvinalexander.com
All Rights Reserved.
A percentage of advertising revenue from
pages under the /java/jwarehouse
URI on this website is
paid back to open source projects.