Skip to content

Commit 4e0d6d0

Browse files
committed
upload protected with pac4j auth error fix #361
1 parent 6bbc0b4 commit 4e0d6d0

3 files changed

Lines changed: 44 additions & 1 deletion

File tree

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
package org.jooby.issues;
2+
3+
import org.jooby.Upload;
4+
import org.jooby.pac4j.Auth;
5+
import org.jooby.test.ServerFeature;
6+
import org.junit.Test;
7+
8+
public class Issue361 extends ServerFeature {
9+
10+
{
11+
use(new Auth().form());
12+
13+
get("/", () -> "OK");
14+
15+
post("/api/protected/upload", req -> {
16+
Upload file = req.file("myfile");
17+
return file.name();
18+
});
19+
}
20+
21+
@Test
22+
public void shouldPac4jAuthContextShouldNotFailWithFileUploads() throws Exception {
23+
request()
24+
.get("/auth?username=test&password=test")
25+
.expect("OK");
26+
27+
request()
28+
.post("/api/protected/upload")
29+
.multipart()
30+
.add("username", "test")
31+
.add("password", "test")
32+
.file("myfile", "<xml></xml>".getBytes(), "application/xml", "pom.xml")
33+
.expect(200);
34+
}
35+
36+
}

jooby-netty/src/main/java/org/jooby/internal/netty/NettyRequest.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -258,6 +258,8 @@ private Multimap<String, String> decodeParams() throws IOException {
258258
switch (field.getHttpDataType()) {
259259
case FileUpload:
260260
files.put(name, new NettyUpload((FileUpload) field, tmpdir));
261+
// excludes upload from param names.
262+
break;
261263
default:
262264
params.put(name, field.getString());
263265
break;

jooby-undertow/src/main/java/org/jooby/internal/undertow/UndertowRequest.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,12 @@ public String path() {
9191
public List<String> paramNames() {
9292
ImmutableList.Builder<String> builder = ImmutableList.<String> builder();
9393
builder.addAll(exchange.getQueryParameters().keySet());
94-
form.forEach(builder::add);
94+
form.forEach(v -> {
95+
// excludes upload from param names.
96+
if (!form.getFirst(v).isFile()) {
97+
builder.add(v);
98+
}
99+
});
95100
return builder.build();
96101
}
97102

0 commit comments

Comments
 (0)