Skip to content

Commit 78e1c67

Browse files
authored
Merge pull request #868 from swagger-api/security-fixes
fix temp file creation
2 parents dddb3f3 + 536870f commit 78e1c67

File tree

7 files changed

+18
-17
lines changed

7 files changed

+18
-17
lines changed

src/main/java/io/swagger/codegen/v3/generators/java/AbstractJavaCodegen.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -211,7 +211,7 @@ public void processOpts() {
211211
apiDocTemplateFiles.put("api_doc.mustache", ".md");
212212

213213
if (additionalProperties.containsKey(SUPPORT_JAVA6)) {
214-
this.setSupportJava6(Boolean.valueOf(additionalProperties.get(SUPPORT_JAVA6).toString()));
214+
this.setSupportJava6(false); // JAVA 6 not supported
215215
}
216216
additionalProperties.put(SUPPORT_JAVA6, supportJava6);
217217

src/main/java/io/swagger/codegen/v3/generators/java/JavaClientCodegen.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,13 +82,12 @@ public JavaClientCodegen() {
8282
cliOptions.add(CliOption.newBoolean(PARCELABLE_MODEL, "Whether to generate models for Android that implement Parcelable with the okhttp-gson library."));
8383
cliOptions.add(CliOption.newBoolean(USE_PLAY_WS, "Use Play! Async HTTP client (Play WS API)"));
8484
cliOptions.add(CliOption.newString(PLAY_VERSION, "Version of Play! Framework (possible values \"play24\", \"play25\")"));
85-
cliOptions.add(CliOption.newBoolean(SUPPORT_JAVA6, "Whether to support Java6 with the Jersey1 library."));
8685
cliOptions.add(CliOption.newBoolean(USE_BEANVALIDATION, "Use BeanValidation API annotations"));
8786
cliOptions.add(CliOption.newBoolean(PERFORM_BEANVALIDATION, "Perform BeanValidation"));
8887
cliOptions.add(CliOption.newBoolean(USE_GZIP_FEATURE, "Send gzip-encoded requests"));
8988
cliOptions.add(CliOption.newBoolean(USE_RUNTIME_EXCEPTION, "Use RuntimeException instead of Exception"));
9089

91-
supportedLibraries.put("jersey1", "HTTP client: Jersey client 1.19.4. JSON processing: Jackson 2.10.1. Enable Java6 support using '-DsupportJava6=true'. Enable gzip request encoding using '-DuseGzipFeature=true'.");
90+
supportedLibraries.put("jersey1", "HTTP client: Jersey client 1.19.4. JSON processing: Jackson 2.10.1. Enable gzip request encoding using '-DuseGzipFeature=true'.");
9291
supportedLibraries.put("feign", "HTTP client: OpenFeign 9.4.0. JSON processing: Jackson 2.10.1");
9392
supportedLibraries.put("jersey2", "HTTP client: Jersey client 2.26. JSON processing: Jackson 2.10.1");
9493
supportedLibraries.put("okhttp-gson", "HTTP client: OkHttp 2.7.5. JSON processing: Gson 2.8.1. Enable Parcelable models on Android using '-DparcelableModel=true'. Enable gzip request encoding using '-DuseGzipFeature=true'.");

src/main/java/io/swagger/codegen/v3/generators/java/JavaJerseyServerCodegen.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,6 @@ public JavaJerseyServerCodegen() {
4545
library.setDefault(DEFAULT_JERSEY_LIBRARY);
4646

4747
cliOptions.add(library);
48-
cliOptions.add(CliOption.newBoolean(SUPPORT_JAVA6, "Whether to support Java6 with the Jersey1/2 library."));
4948
cliOptions.add(CliOption.newBoolean(USE_TAGS, "use tags for creating interface and controller classnames"));
5049
}
5150

src/main/resources/handlebars/Java/libraries/jersey2/ApiClient.mustache

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ import java.io.InputStream;
2828

2929
{{^supportJava6}}
3030
import java.nio.file.Files;
31+
import java.nio.file.Paths;
3132
import java.nio.file.StandardCopyOption;
3233
{{/supportJava6}}
3334
{{#supportJava6}}
@@ -651,9 +652,9 @@ public class ApiClient {
651652
}
652653

653654
if (tempFolderPath == null)
654-
return File.createTempFile(prefix, suffix);
655+
return Files.createTempFile(prefix, suffix).toFile();
655656
else
656-
return File.createTempFile(prefix, suffix, new File(tempFolderPath));
657+
return Files.createTempFile(Paths.get(tempFolderPath), prefix, suffix).toFile();
657658
}
658659

659660
/**
@@ -689,7 +690,7 @@ public class ApiClient {
689690
}
690691

691692
Invocation.Builder invocationBuilder = target.request();
692-
693+
693694
if (accept != null) {
694695
invocationBuilder = invocationBuilder.accept(accept);
695696
}

src/main/resources/handlebars/Java/libraries/okhttp-gson/ApiClient.mustache

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ import java.io.File;
2424
import java.io.IOException;
2525
import java.io.InputStream;
2626
import java.io.UnsupportedEncodingException;
27+
import java.nio.file.Files;
28+
import java.nio.file.Paths;
2729
import java.lang.reflect.Type;
2830
import java.net.URLConnection;
2931
import java.net.URLEncoder;
@@ -829,9 +831,9 @@ public class ApiClient {
829831
}
830832

831833
if (tempFolderPath == null)
832-
return File.createTempFile(prefix, suffix);
834+
return Files.createTempFile(prefix, suffix).toFile();
833835
else
834-
return File.createTempFile(prefix, suffix, new File(tempFolderPath));
836+
return Files.createTempFile(Paths.get(tempFolderPath), prefix, suffix).toFile();
835837
}
836838

837839
/**
@@ -981,7 +983,7 @@ public class ApiClient {
981983
* @param formParams The form parameters
982984
* @param authNames The authentications to apply
983985
* @param progressRequestListener Progress request listener
984-
* @return The HTTP request
986+
* @return The HTTP request
985987
* @throws ApiException If fail to serialize the request body object
986988
*/
987989
public Request buildRequest(String path, String method, List<Pair> queryParams, List<Pair> collectionQueryParams, Object body, Map<String, String> headerParams, Map<String, Object> formParams, String[] authNames, ProgressRequestBody.ProgressRequestListener progressRequestListener) throws ApiException {

src/main/resources/handlebars/Java/libraries/resteasy/ApiClient.mustache

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import java.io.InputStream;
88
import java.io.UnsupportedEncodingException;
99
import java.net.URLEncoder;
1010
import java.nio.file.Files;
11+
import java.nio.file.Paths;
1112
import java.text.DateFormat;
1213
import java.text.SimpleDateFormat;
1314
import java.util.ArrayList;
@@ -447,7 +448,7 @@ public class ApiClient {
447448
public Entity<?> serialize(Object obj, Map<String, Object> formParams, String contentType) throws ApiException {
448449
Entity<?> entity = null;
449450
if (contentType.startsWith("multipart/form-data")) {
450-
MultipartFormDataOutput multipart = new MultipartFormDataOutput();
451+
MultipartFormDataOutput multipart = new MultipartFormDataOutput();
451452
//MultiPart multiPart = new MultiPart();
452453
for (Entry<String, Object> param: formParams.entrySet()) {
453454
if (param.getValue() instanceof File) {
@@ -553,9 +554,9 @@ public class ApiClient {
553554
}
554555

555556
if (tempFolderPath == null)
556-
return File.createTempFile(prefix, suffix);
557+
return Files.createTempFile(prefix, suffix).toFile();
557558
else
558-
return File.createTempFile(prefix, suffix, new File(tempFolderPath));
559+
return Files.createTempFile(Paths.get(tempFolderPath), prefix, suffix).toFile();
559560
}
560561

561562
/**
@@ -589,7 +590,7 @@ public class ApiClient {
589590
}
590591

591592
Invocation.Builder invocationBuilder = target.request();
592-
593+
593594
if (accept != null) {
594595
invocationBuilder = invocationBuilder.accept(accept);
595596
}

src/test/java/io/swagger/codegen/v3/generators/GeneratorRunner.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
import java.io.File;
1313
import java.io.InputStream;
14+
import java.nio.file.Files;
1415
import java.util.List;
1516

1617
/**
@@ -67,9 +68,7 @@ public static File getOutFolder(String path, boolean delete) {
6768

6869
public static File getTmpFolder() {
6970
try {
70-
File outputFolder = File.createTempFile("codegentest-", "-tmp");
71-
outputFolder.delete();
72-
outputFolder.mkdir();
71+
File outputFolder = Files.createTempDirectory("codegentest-").toFile();
7372
outputFolder.deleteOnExit();
7473
return outputFolder;
7574
} catch (Exception e) {

0 commit comments

Comments
 (0)