Source Code Cross Referenced for ParameterFilterInterceptor.java in  » J2EE » webwork-2.2.6 » com » opensymphony » xwork » interceptor » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » J2EE » webwork 2.2.6 » com.opensymphony.xwork.interceptor 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * Copyright (c) 2002-2006 by OpenSymphony
003:         * All rights reserved.
004:         */
005:
006:        package com.opensymphony.xwork.interceptor;
007:
008:        import com.opensymphony.xwork.ActionInvocation;
009:        import com.opensymphony.xwork.util.TextParseUtil;
010:
011:        import java.util.*;
012:
013:        import org.apache.commons.logging.Log;
014:        import org.apache.commons.logging.LogFactory;
015:
016:        /**
017:         * <!-- START SNIPPET: description -->
018:         *
019:         * <p>The Parameter Filter Interceptor blocks parameters from getting
020:         * to the rest of the stack or your action. You can use multiple 
021:         * parameter filter interceptors for a given action, so, for example,
022:         * you could use one in your default stack that filtered parameters
023:         * you wanted blocked from every action and those you wanted blocked 
024:         * from an individual action you could add an additional interceptor
025:         * for each action.</p>
026:         * 
027:         * <!-- END SNIPPET: description -->
028:         * 
029:         * <!-- START SNIPPET: parameters -->
030:         *
031:         * <ul>
032:         *
033:         * <li>allowed - a comma delimited list of parameter prefixes
034:         *  that are allowed to pass to the action</li>
035:         * <li>blocked - a comma delimited list of parameter prefixes 
036:         * that are not allowed to pass to the action</li>
037:         * <li>defaultBlock - boolean (default to false) whether by
038:         * default a given parameter is blocked. If true, then a parameter
039:         * must have a prefix in the allowed list in order to be able 
040:         * to pass to the action
041:         * </ul>
042:         * 
043:         * <p>The way parameters are filtered for the least configuration is that
044:         * if a string is in the allowed or blocked lists, then any parameter
045:         * that is a member of the object represented by the parameter is allowed
046:         * or blocked respectively.</p>
047:         * 
048:         * <p>For example, if the parameters are:
049:         * <ul>
050:         * <li>blocked: person,person.address.createDate,personDao</li>
051:         * <li>allowed: person.address</li>
052:         * <li>defaultBlock: false</li>
053:         * </ul>
054:         * <br>
055:         * The parameters person.name, person.phoneNum etc would be blocked 
056:         * because 'person' is in the blocked list. However, person.address.street
057:         * and person.address.city would be allowed because person.address is
058:         * in the allowed list (the longer string determines permissions).</p> 
059:         * <!-- END SNIPPET: parameters -->
060:         *
061:         * @author Gabe
062:         */
063:        public class ParameterFilterInterceptor implements  Interceptor {
064:
065:            private static final long serialVersionUID = -7467459931718970229L;
066:
067:            private static final Log LOG = LogFactory
068:                    .getLog(ParameterFilterInterceptor.class);
069:
070:            private Collection allowed;
071:
072:            private Collection blocked;
073:
074:            private Map includesExcludesMap;
075:
076:            private boolean defaultBlock = false;
077:
078:            public void destroy() {
079:            }
080:
081:            public void init() {
082:            }
083:
084:            public String intercept(ActionInvocation invocation)
085:                    throws Exception {
086:
087:                Map parameters = invocation.getInvocationContext()
088:                        .getParameters();
089:                HashSet paramsToRemove = new HashSet();
090:
091:                Map includesExcludesMap = getIncludesExcludesMap();
092:
093:                for (Iterator i = parameters.keySet().iterator(); i.hasNext();) {
094:
095:                    String param = (String) i.next();
096:
097:                    boolean currentAllowed = !isDefaultBlock();
098:
099:                    boolean foundApplicableRule = false;
100:                    for (Iterator j = includesExcludesMap.keySet().iterator(); j
101:                            .hasNext();) {
102:                        String currRule = (String) j.next();
103:
104:                        if (param.startsWith(currRule)
105:                                && (param.length() == currRule.length() || isPropSeperator(param
106:                                        .charAt(currRule.length())))) {
107:                            currentAllowed = ((Boolean) includesExcludesMap
108:                                    .get(currRule)).booleanValue();
109:                        } else {
110:                            if (foundApplicableRule) {
111:                                foundApplicableRule = false;
112:                                break;
113:                            }
114:                        }
115:                    }
116:                    if (!currentAllowed) {
117:                        paramsToRemove.add(param);
118:                    }
119:                }
120:
121:                if (LOG.isDebugEnabled()) {
122:                    LOG.debug("Params to remove: " + paramsToRemove);
123:                }
124:
125:                for (Iterator i = paramsToRemove.iterator(); i.hasNext();) {
126:                    parameters.remove(i.next());
127:                }
128:
129:                return invocation.invoke();
130:            }
131:
132:            /**
133:             * @param c
134:             * @return <tt>true</tt>, if char is property separator, <tt>false</tt> otherwise.
135:             */
136:            private boolean isPropSeperator(char c) {
137:                return c == '.' || c == '(' || c == '[';
138:            }
139:
140:            private Map getIncludesExcludesMap() {
141:                if (this .includesExcludesMap == null) {
142:                    this .includesExcludesMap = new TreeMap();
143:
144:                    if (getAllowedCollection() != null) {
145:                        for (Iterator i = getAllowedCollection().iterator(); i
146:                                .hasNext();) {
147:                            this .includesExcludesMap
148:                                    .put(i.next(), Boolean.TRUE);
149:                        }
150:                    }
151:                    if (getBlockedCollection() != null) {
152:                        for (Iterator i = getBlockedCollection().iterator(); i
153:                                .hasNext();) {
154:                            this .includesExcludesMap.put(i.next(),
155:                                    Boolean.FALSE);
156:                        }
157:                    }
158:                }
159:
160:                return this .includesExcludesMap;
161:            }
162:
163:            /**
164:             * @return Returns the defaultBlock.
165:             */
166:            public boolean isDefaultBlock() {
167:                return defaultBlock;
168:            }
169:
170:            /**
171:             * @param defaultExclude The defaultExclude to set.
172:             */
173:            public void setDefaultBlock(boolean defaultExclude) {
174:                this .defaultBlock = defaultExclude;
175:            }
176:
177:            /**
178:             * @return Returns the blocked.
179:             */
180:            public Collection getBlockedCollection() {
181:                return blocked;
182:            }
183:
184:            /**
185:             * @param blocked The blocked to set.
186:             */
187:            public void setBlockedCollection(Collection blocked) {
188:                this .blocked = blocked;
189:            }
190:
191:            /**
192:             * @param blocked The blocked paramters as comma separated String.
193:             */
194:            public void setBlocked(String blocked) {
195:                setBlockedCollection(asCollection(blocked));
196:            }
197:
198:            /**
199:             * @return Returns the allowed.
200:             */
201:            public Collection getAllowedCollection() {
202:                return allowed;
203:            }
204:
205:            /**
206:             * @param allowed The allowed to set.
207:             */
208:            public void setAllowedCollection(Collection allowed) {
209:                this .allowed = allowed;
210:            }
211:
212:            /**
213:             * @param allowed The allowed paramters as comma separated String.
214:             */
215:            public void setAllowed(String allowed) {
216:                setAllowedCollection(asCollection(allowed));
217:            }
218:
219:            /**
220:             * Return a collection from the comma delimited String.
221:             *
222:             * @param commaDelim
223:             * @return A collection from the comma delimited String.
224:             */
225:            private Collection asCollection(String commaDelim) {
226:                if (commaDelim == null || commaDelim.trim().length() == 0) {
227:                    return null;
228:                }
229:                return TextParseUtil.commaDelimitedStringToSet(commaDelim);
230:            }
231:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.