forked from ESAPI/esapi-java-legacy
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathESAPI.java
More file actions
282 lines (238 loc) · 6.82 KB
/
Copy pathESAPI.java
File metadata and controls
282 lines (238 loc) · 6.82 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
/**
* OWASP Enterprise Security API (ESAPI)
*
* This file is part of the Open Web Application Security Project (OWASP)
* Enterprise Security API (ESAPI) project. For details, please see
* <a href="http://www.owasp.org/index.php/ESAPI">http://www.owasp.org/index.php/ESAPI</a>.
*
* Copyright (c) 2008 - The OWASP Foundation
*
* The ESAPI is published by OWASP under the BSD license. You should read and accept the
* LICENSE before you use, modify, and/or redistribute this software.
*
* @author Rogan Dawes <a href="http://www.aspectsecurity.com">Aspect Security</a>
* @created 2008
*/
package org.owasp.esapi;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.owasp.esapi.reference.DefaultEncoder;
import org.owasp.esapi.reference.DefaultExecutor;
import org.owasp.esapi.reference.DefaultHTTPUtilities;
import org.owasp.esapi.reference.DefaultIntrusionDetector;
import org.owasp.esapi.reference.DefaultRandomizer;
import org.owasp.esapi.reference.DefaultSecurityConfiguration;
import org.owasp.esapi.reference.DefaultValidator;
import org.owasp.esapi.reference.FileBasedAccessController;
import org.owasp.esapi.reference.FileBasedAuthenticator;
import org.owasp.esapi.reference.JavaEncryptor;
import org.owasp.esapi.reference.JavaLogFactory;
/**
* ESAPI locator class to make it easy to get a concrete implementation of the
* various ESAPI classes. Use the setters to override the reference implementations
* with instances of any custom ESAPI implementations.
*/
public class ESAPI {
private static AccessController accessController = null;
private static Authenticator authenticator = null;
private static Encoder encoder = null;
private static Encryptor encryptor = null;
private static Executor executor = null;
private static HTTPUtilities httpUtilities = null;
private static IntrusionDetector intrusionDetector = null;
private static LogFactory logFactory = null;
private static Logger defaultLogger = null;
private static Randomizer randomizer = null;
private static SecurityConfiguration securityConfiguration = null;
private static Validator validator = null;
/**
* prevent instantiation of this class
*/
private ESAPI() {
}
public static HttpServletRequest currentRequest() {
return httpUtilities().getCurrentRequest();
}
public static HttpServletResponse currentResponse() {
return httpUtilities().getCurrentResponse();
}
/**
* @return the accessController
*/
public static AccessController accessController() {
if (ESAPI.accessController == null)
ESAPI.accessController = new FileBasedAccessController();
return ESAPI.accessController;
}
/**
* @param accessController
* the accessController to set
*/
public static void setAccessController(AccessController accessController) {
ESAPI.accessController = accessController;
}
/**
* @return the authenticator
*/
public static Authenticator authenticator() {
if (ESAPI.authenticator == null)
ESAPI.authenticator = new FileBasedAuthenticator();
return ESAPI.authenticator;
}
/**
* @param authenticator
* the authenticator to set
*/
public static void setAuthenticator(Authenticator authenticator) {
ESAPI.authenticator = authenticator;
}
/**
* @return the encoder
*/
public static Encoder encoder() {
if (ESAPI.encoder == null)
ESAPI.encoder = new DefaultEncoder();
return ESAPI.encoder;
}
/**
* @param encoder
* the encoder to set
*/
public static void setEncoder(Encoder encoder) {
ESAPI.encoder = encoder;
}
/**
* @return the encryptor
*/
public static Encryptor encryptor() {
if (ESAPI.encryptor == null)
ESAPI.encryptor = new JavaEncryptor();
return ESAPI.encryptor;
}
/**
* @param encryptor
* the encryptor to set
*/
public static void setEncryptor(Encryptor encryptor) {
ESAPI.encryptor = encryptor;
}
/**
* @return the executor
*/
public static Executor executor() {
if (ESAPI.executor == null)
ESAPI.executor = new DefaultExecutor();
return ESAPI.executor;
}
/**
* @param executor
* the executor to set
*/
public static void setExecutor(Executor executor) {
ESAPI.executor = executor;
}
/**
* @return the httpUtilities
*/
public static HTTPUtilities httpUtilities() {
if (ESAPI.httpUtilities == null)
ESAPI.httpUtilities = new DefaultHTTPUtilities();
return ESAPI.httpUtilities;
}
/**
* @param httpUtilities
* the httpUtilities to set
*/
public static void setHttpUtilities(HTTPUtilities httpUtilities) {
ESAPI.httpUtilities = httpUtilities;
}
/**
* @return the intrusionDetector
*/
public static IntrusionDetector intrusionDetector() {
if (ESAPI.intrusionDetector == null)
ESAPI.intrusionDetector = new DefaultIntrusionDetector();
return ESAPI.intrusionDetector;
}
/**
* @param intrusionDetector
* the intrusionDetector to set
*/
public static void setIntrusionDetector(IntrusionDetector intrusionDetector) {
ESAPI.intrusionDetector = intrusionDetector;
}
private static LogFactory logFactory() {
if (logFactory == null)
logFactory = new JavaLogFactory(securityConfiguration().getApplicationName());
return logFactory;
}
/**
*
*/
public static Logger getLogger(Class clazz) {
return logFactory().getLogger(clazz);
}
/**
*
*/
public static Logger getLogger(String name) {
return logFactory().getLogger(name);
}
public static Logger log() {
if (defaultLogger == null)
defaultLogger = logFactory().getLogger("");
return defaultLogger;
}
/**
* @param factory the log factory to set
*/
public static void setLogFactory(LogFactory factory) {
ESAPI.logFactory = factory;
}
/**
* @return the randomizer
*/
public static Randomizer randomizer() {
if (ESAPI.randomizer == null)
ESAPI.randomizer = new DefaultRandomizer();
return ESAPI.randomizer;
}
/**
* @param randomizer
* the randomizer to set
*/
public static void setRandomizer(Randomizer randomizer) {
ESAPI.randomizer = randomizer;
}
/**
* @return the securityConfiguration
*/
public static SecurityConfiguration securityConfiguration() {
if (ESAPI.securityConfiguration == null)
ESAPI.securityConfiguration = new DefaultSecurityConfiguration();
return ESAPI.securityConfiguration;
}
/**
* @param securityConfiguration
* the securityConfiguration to set
*/
public static void setSecurityConfiguration(
SecurityConfiguration securityConfiguration) {
ESAPI.securityConfiguration = securityConfiguration;
}
/**
* @return the validator
*/
public static Validator validator() {
if (ESAPI.validator == null)
ESAPI.validator = new DefaultValidator();
return ESAPI.validator;
}
/**
* @param validator
* the validator to set
*/
public static void setValidator(Validator validator) {
ESAPI.validator = validator;
}
}