From 8e327aa24b301afef79c8e312b2332bca634af2e Mon Sep 17 00:00:00 2001 From: Luca Milanesio Date: Mon, 9 Feb 2015 20:14:13 +0000 Subject: [PATCH] Support for Secure SPNEGO kerberos negotiation Ability to integrate with a SPNEGO-protected REST API with KerberosV5 ticket preemptive authentication. --- .../codegen/languages/ScalaClientCodegen.java | 7 ++++++- .../src/main/resources/scala/apiInvoker.mustache | 14 ++++++++++++-- 2 files changed, 18 insertions(+), 3 deletions(-) diff --git a/modules/swagger-codegen/src/main/java/com/wordnik/swagger/codegen/languages/ScalaClientCodegen.java b/modules/swagger-codegen/src/main/java/com/wordnik/swagger/codegen/languages/ScalaClientCodegen.java index 697114f79bf7..892ef2de99c1 100644 --- a/modules/swagger-codegen/src/main/java/com/wordnik/swagger/codegen/languages/ScalaClientCodegen.java +++ b/modules/swagger-codegen/src/main/java/com/wordnik/swagger/codegen/languages/ScalaClientCodegen.java @@ -12,6 +12,9 @@ public class ScalaClientCodegen extends DefaultCodegen implements CodegenConfig protected String artifactId = "swagger-client"; protected String artifactVersion = "1.0.0"; protected String sourceFolder = "src/main/java"; + protected String authScheme = ""; + protected boolean authPreemptive = false; + protected boolean asyncHttpClient = !authScheme.isEmpty(); public String getName() { return "scala"; @@ -43,7 +46,9 @@ public class ScalaClientCodegen extends DefaultCodegen implements CodegenConfig additionalProperties.put("groupId", groupId); additionalProperties.put("artifactId", artifactId); additionalProperties.put("artifactVersion", artifactVersion); - additionalProperties.put("asyncHttpClient", false); + additionalProperties.put("asyncHttpClient", asyncHttpClient); + additionalProperties.put("authScheme", authScheme); + additionalProperties.put("authPreemptive", authPreemptive); supportingFiles.add(new SupportingFile("pom.mustache", "", "pom.xml")); supportingFiles.add(new SupportingFile("apiInvoker.mustache", diff --git a/modules/swagger-codegen/src/main/resources/scala/apiInvoker.mustache b/modules/swagger-codegen/src/main/resources/scala/apiInvoker.mustache index b8f588a9aa0b..cb6ab2798f96 100644 --- a/modules/swagger-codegen/src/main/resources/scala/apiInvoker.mustache +++ b/modules/swagger-codegen/src/main/resources/scala/apiInvoker.mustache @@ -38,7 +38,9 @@ object ScalaJsonUtil { class ApiInvoker(val mapper: ObjectMapper = ScalaJsonUtil.getJsonMapper, httpHeaders: HashMap[String, String] = HashMap(), hostMap: HashMap[String, Client] = HashMap(), - asyncHttpClient: Boolean = false) { + asyncHttpClient: Boolean = false, + authScheme: String = "", + authPreemptive: Boolean = false) { var defaultHeaders: HashMap[String, String] = httpHeaders @@ -167,6 +169,12 @@ class ApiInvoker(val mapper: ObjectMapper = ScalaJsonUtil.getJsonMapper, import org.sonatype.spice.jersey.client.ahc.AhcHttpClient val config: DefaultAhcConfig = new DefaultAhcConfig() + if (!authScheme.isEmpty) { + val authSchemeEnum = Realm.AuthScheme.valueOf(authScheme) + config.getAsyncHttpClientConfigBuilder + .setRealm(new Realm.RealmBuilder().setScheme(authSchemeEnum) + .setUsePreemptiveAuth(authPreemptive).build) + } AhcHttpClient.create(config) } case _ => Client.create() @@ -176,7 +184,9 @@ class ApiInvoker(val mapper: ObjectMapper = ScalaJsonUtil.getJsonMapper, object ApiInvoker extends ApiInvoker(mapper = ScalaJsonUtil.getJsonMapper, httpHeaders = HashMap(), hostMap = HashMap(), - asyncHttpClient = {{asyncHttpClient}}) + asyncHttpClient = {{asyncHttpClient}}, + authScheme = {{authScheme}}, + authPreemptive = {{authPreemptive}}) class ApiException(val code: Int, msg: String) extends RuntimeException(msg)