Skip to content

Commit fc5558e

Browse files
authored
Merge pull request #683 from jeremiahjstacey/java-8
Java 8 updates
2 parents 0dc3da1 + 906e55a commit fc5558e

15 files changed

+310
-222
lines changed

.snyk

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,2 @@
11
# Snyk (https://snyk.io) policy file, patches or ignores known vulnerabilities.
22
version: v1.14.0
3-
ignore:
4-
SNYK-JAVA-COMMONSIO-1277109:
5-
- commons-io:commons-io:
6-
reason: ESAPI cannot upgrade past the current commons-io version and still maintain Java 7 compatibility
7-
expires: '2025-12-30T00:00:00.000Z'

CONTRIBUTING-TO-ESAPI.txt

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -46,10 +46,9 @@ Overview:
4646
autocrlf = input
4747

4848
Required Software:
49-
We use Maven for building. Maven 3.1 or later is required. You also need
50-
JDK 7 or later. (We generally use JDK 8, but compile ESAPI only to require
51-
JDK 7, which means our code can't yet use any features exclusive to Java 8
52-
or later.) [Note: If you use JDK 9 or later, there will be multiple
49+
We use Maven for building. Maven 3.3.9 or later is required. You also need
50+
JDK 8 or later.
51+
[Note: If you use JDK 9 or later, there will be multiple
5352
failures when you try to run 'mvn test' as well as some general warnings.
5453
See ESAPI GitHub issue #496 for details.]
5554

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ You will find that GitHub repository at [https://github.com/ESAPI/esapi-java-leg
2929
<b>IMPORTANT NOTES:</b>
3030
The default branch for ESAPI legacy is now the 'develop' branch (rather than the 'main' (formerly 'master') branch), where future development, bug fixes, etc. will now be done. The 'main' branch is now marked as "protected"; it reflects the latest stable ESAPI release (2.1.0.1 as of this date). Note that this change of making the 'develop' branch the default may affect any pull requests that you were intending to make.
3131

32-
Also, the <i>minimal</i> baseline Java version to use ESAPI is Java 7. (This was changed from Java 6 during the 2.2.0.0 release.)
32+
Also, the <i>minimal</i> baseline Java version to use ESAPI is Java 8. (This was changed from Java 7 during the 2.4.0.0 release.)
3333

3434
# Where can I find ESAPI 3.x?
3535
[https://github.com/ESAPI/esapi-java](https://github.com/ESAPI/esapi-java)

pom.xml

Lines changed: 76 additions & 130 deletions
Large diffs are not rendered by default.

src/main/java/org/owasp/esapi/reference/DefaultHTTPUtilities.java

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -583,39 +583,40 @@ public void update(long pBytesRead, long pContentLength, int pItems) {
583583
upload.setProgressListener(progressListener);
584584

585585
List<FileItem> items = upload.parseRequest(request);
586-
for (FileItem item : items)
587-
{
588-
if (!item.isFormField() && item.getName() != null && !(item.getName().equals("")))
589-
{
586+
for (FileItem item : items)
587+
{
588+
if (!item.isFormField() && item.getName() != null && !(item.getName().equals("")))
589+
{
590590
String[] fparts = item.getName().split("[\\/\\\\]");
591591
String filename = fparts[fparts.length - 1];
592592

593-
if (!ESAPI.validator().isValidFileName("upload", filename, allowedExtensions, false))
594-
{
593+
if (!ESAPI.validator().isValidFileName("upload", filename, allowedExtensions, false))
594+
{
595595
throw new ValidationUploadException("Upload only simple filenames with the following extensions " + allowedExtensions, "Upload failed isValidFileName check");
596596
}
597597

598598
logger.info(Logger.SECURITY_SUCCESS, "File upload requested: " + filename);
599599
File f = new File(finalDir, filename);
600-
if (f.exists())
601-
{
600+
if (f.exists())
601+
{
602602
String[] parts = filename.split("\\/.");
603603
String extension = "";
604-
if (parts.length > 1)
605-
{
604+
if (parts.length > 1)
605+
{
606606
extension = parts[parts.length - 1];
607607
}
608608
String filenm = filename.substring(0, filename.length() - extension.length());
609609
f = File.createTempFile(filenm, "." + extension, finalDir);
610610
}
611+
611612
item.write(f);
612-
newFiles.add(f);
613+
newFiles.add(f);
613614
// delete temporary file
614615
item.delete();
615616
logger.fatal(Logger.SECURITY_SUCCESS, "File successfully uploaded: " + f);
616-
if (session != null)
617-
{
618-
session.setAttribute("progress", Long.toString(0));
617+
if (session != null)
618+
{
619+
session.setAttribute("progress", Long.toString(0));
619620
}
620621
}
621622
}

src/main/java/org/owasp/esapi/waf/internal/InterceptingHTTPServletRequest.java

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
import java.util.Enumeration;
2525
import java.util.Vector;
2626

27+
import javax.servlet.ReadListener;
2728
import javax.servlet.ServletInputStream;
2829
import javax.servlet.http.HttpServletRequest;
2930
import javax.servlet.http.HttpServletRequestWrapper;
@@ -171,18 +172,37 @@ public Enumeration getDictionaryParameterNames() {
171172
private class RAFInputStream extends ServletInputStream {
172173

173174
RandomAccessFile raf;
175+
boolean isDone = false;
174176

175177
public RAFInputStream(RandomAccessFile raf) throws IOException {
176178
this.raf = raf;
177179
this.raf.seek(0);
178180
}
179181

180182
public int read() throws IOException {
181-
return raf.read();
183+
int rval = raf.read();
184+
isDone = rval == -1;
185+
return rval;
182186
}
183187

184188
public synchronized void reset() throws IOException {
185189
raf.seek(0);
190+
isDone=false;
191+
}
192+
193+
@Override
194+
public boolean isFinished() {
195+
return isDone;
196+
}
197+
198+
@Override
199+
public boolean isReady() {
200+
return false;
201+
}
202+
203+
@Override
204+
public void setReadListener(ReadListener readListener) {
205+
//NO-OP. Unused in this scope
186206
}
187207
}
188208

src/main/java/org/owasp/esapi/waf/internal/InterceptingServletOutputStream.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
import java.io.RandomAccessFile;
2222

2323
import javax.servlet.ServletOutputStream;
24+
import javax.servlet.WriteListener;
2425

2526
/**
2627
* This class was inspired by ModSecurity for Java by Ivan Ristic. We hook
@@ -161,4 +162,14 @@ public void close() throws IOException {
161162

162163
}
163164

165+
@Override
166+
public boolean isReady() {
167+
return os.isReady();
168+
}
169+
170+
@Override
171+
public void setWriteListener(WriteListener writeListener) {
172+
os.setWriteListener(writeListener);
173+
}
174+
164175
}

src/test/java/org/owasp/esapi/http/MockHttpServletRequest.java

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@
4646
import javax.servlet.http.HttpServletRequest;
4747
import javax.servlet.http.HttpServletResponse;
4848
import javax.servlet.http.HttpSession;
49+
import javax.servlet.http.HttpUpgradeHandler;
4950
import javax.servlet.http.Part;
5051

5152
/**
@@ -737,4 +738,19 @@ public DispatcherType getDispatcherType() {
737738
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
738739
}
739740

741+
@Override
742+
public long getContentLengthLong() {
743+
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
744+
}
745+
746+
@Override
747+
public String changeSessionId() {
748+
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
749+
}
750+
751+
@Override
752+
public <T extends HttpUpgradeHandler> T upgrade(Class<T> handlerClass) throws IOException, ServletException {
753+
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
754+
}
755+
740756
}

src/test/java/org/owasp/esapi/http/MockHttpServletResponse.java

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
import java.util.Locale;
2525

2626
import javax.servlet.ServletOutputStream;
27+
import javax.servlet.WriteListener;
2728
import javax.servlet.http.Cookie;
2829
import javax.servlet.http.HttpServletResponse;
2930

@@ -279,6 +280,16 @@ public ServletOutputStream getOutputStream() throws IOException {
279280
public void write(int b) throws IOException {
280281
body.append((char)b);
281282
}
283+
284+
@Override
285+
public boolean isReady() {
286+
return false;
287+
}
288+
289+
@Override
290+
public void setWriteListener(WriteListener writeListener) {
291+
//NO-OP
292+
}
282293
};
283294
}
284295

@@ -369,5 +380,10 @@ public void dump() {
369380
public Collection<String> getHeaders(String string) {
370381
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
371382
}
383+
384+
@Override
385+
public void setContentLengthLong(long len) {
386+
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
387+
}
372388

373389
}

src/test/java/org/owasp/esapi/http/MockServletContext.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -693,4 +693,9 @@ public ClassLoader getClassLoader() {
693693
public void declareRoles(String... strings) {
694694
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
695695
}
696+
697+
@Override
698+
public String getVirtualServerName() {
699+
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
700+
}
696701
}

0 commit comments

Comments
 (0)