diff options
author | Claudio D. Gasparini <claudio.gasparini@intl.att.com> | 2021-03-24 09:43:40 +0100 |
---|---|---|
committer | KAPIL SINGAL <ks220y@att.com> | 2021-03-25 17:00:57 +0000 |
commit | 204ae9b5b21c48054d0d02761ef80b647c7e0473 (patch) | |
tree | 55200aefc8e2d34ea662529de2a8620ea39c2b0a /ms/blueprintsprocessor/modules/commons/rest-lib/src | |
parent | c7bd99a9bf07e3023ab510dfe84fc2acbe74299b (diff) |
Address some pendings items for SSLBasicAuthRestClient
- FIXME under SSLBasicAuthRestClientProperties
- TODO under SSLBasicAuthRestClientPropertiesBuilder
Issue-ID: CCSDK-3235
Signed-off-by: Claudio D. Gasparini <claudio.gasparini@intl.att.com>
Change-Id: If00c7491573c69eb5d3f9192f54c7b384943abf7
Diffstat (limited to 'ms/blueprintsprocessor/modules/commons/rest-lib/src')
5 files changed, 50 insertions, 27 deletions
diff --git a/ms/blueprintsprocessor/modules/commons/rest-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/rest/BlueprintRestLibData.kt b/ms/blueprintsprocessor/modules/commons/rest-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/rest/BlueprintRestLibData.kt index a227cf24e..01011cc83 100644 --- a/ms/blueprintsprocessor/modules/commons/rest-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/rest/BlueprintRestLibData.kt +++ b/ms/blueprintsprocessor/modules/commons/rest-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/rest/BlueprintRestLibData.kt @@ -35,10 +35,9 @@ open class SSLRestClientProperties : RestClientProperties() { var sslKeyPassword: String? = null } -// FIXME("Define basic auth userName and password properties") open class SSLBasicAuthRestClientProperties : SSLRestClientProperties() { - - var basicAuth: BasicAuthRestClientProperties? = null + lateinit var password: String + lateinit var username: String } // FIXME("Define token properties") diff --git a/ms/blueprintsprocessor/modules/commons/rest-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/rest/RestClientPropertiesDSL.kt b/ms/blueprintsprocessor/modules/commons/rest-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/rest/RestClientPropertiesDSL.kt index 45b9e3827..b1692d93a 100644 --- a/ms/blueprintsprocessor/modules/commons/rest-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/rest/RestClientPropertiesDSL.kt +++ b/ms/blueprintsprocessor/modules/commons/rest-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/rest/RestClientPropertiesDSL.kt @@ -77,6 +77,10 @@ open class RestClientRelationshipTemplateBuilder(name: String, description: Stri property(BlueprintConstants.PROPERTY_CONNECTION_CONFIG, BlueprintTypes.tokenAuthRestClientProperties(block)) } + fun sslBasicAuth(block: SSLBasicAuthRestClientPropertiesBuilder.() -> Unit) { + property(BlueprintConstants.PROPERTY_CONNECTION_CONFIG, BlueprintTypes.sslBasicAuthRestClientProperties(block)) + } + fun sslAuth(block: SslAuthRestClientPropertiesAssignmentBuilder.() -> Unit) { property(BlueprintConstants.PROPERTY_CONNECTION_CONFIG, BlueprintTypes.sslRestClientProperties(block)) } @@ -94,6 +98,12 @@ fun BlueprintTypes.tokenAuthRestClientProperties(block: TokenAuthRestClientPrope return assignments.asJsonType() } +fun BlueprintTypes.sslBasicAuthRestClientProperties(block: SSLBasicAuthRestClientPropertiesBuilder.() -> Unit): JsonNode { + val assignments = SSLBasicAuthRestClientPropertiesBuilder().apply(block).build() + assignments[RestClientProperties::type.name] = RestLibConstants.TYPE_SSL_BASIC_AUTH.asJsonPrimitive() + return assignments.asJsonType() +} + fun BlueprintTypes.sslRestClientProperties(block: SslAuthRestClientPropertiesAssignmentBuilder.() -> Unit): JsonNode { val assignments = SslAuthRestClientPropertiesAssignmentBuilder().apply(block).build() assignments[RestClientProperties::type.name] = RestLibConstants.TYPE_SSL_NO_AUTH.asJsonPrimitive() @@ -182,10 +192,32 @@ open class SslAuthRestClientPropertiesAssignmentBuilder : RestClientPropertiesAs open fun sslKeyPassword(sslKeyPassword: JsonNode) { property(SSLRestClientProperties::sslKeyPassword, sslKeyPassword) } + + open fun sslTrustIgnoreHostname(sslTrustIgnoreHostname: String) { + sslTrustIgnoreHostname(sslTrustIgnoreHostname.asJsonPrimitive()) + } + + open fun sslTrustIgnoreHostname(sslTrustIgnoreHostname: JsonNode) { + property(SSLRestClientProperties::sslTrustIgnoreHostname, sslTrustIgnoreHostname) + } } open class SSLBasicAuthRestClientPropertiesBuilder : SslAuthRestClientPropertiesAssignmentBuilder() { - // TODO() + open fun password(password: String) { + password(password.asJsonPrimitive()) + } + + open fun password(password: JsonNode) { + property(SSLBasicAuthRestClientProperties::password, password) + } + + open fun username(username: String) { + username(username.asJsonPrimitive()) + } + + open fun username(username: JsonNode) { + property(SSLBasicAuthRestClientProperties::username, username) + } } open class SSLTokenAuthRestClientPropertiesBuilder : SslAuthRestClientPropertiesAssignmentBuilder() { diff --git a/ms/blueprintsprocessor/modules/commons/rest-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/rest/service/BlueprintRestLibPropertyService.kt b/ms/blueprintsprocessor/modules/commons/rest-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/rest/service/BlueprintRestLibPropertyService.kt index d28bd77db..c6d2ed905 100644 --- a/ms/blueprintsprocessor/modules/commons/rest-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/rest/service/BlueprintRestLibPropertyService.kt +++ b/ms/blueprintsprocessor/modules/commons/rest-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/rest/service/BlueprintRestLibPropertyService.kt @@ -160,20 +160,11 @@ open class BlueprintRestLibPropertyService(private var bluePrintPropertiesServic ) } - private fun sslBasicAuthRestClientProperties(prefix: String): - SSLRestClientProperties { - - val sslProps: SSLBasicAuthRestClientProperties = - bluePrintPropertiesService.propertyBeanType( - prefix, SSLBasicAuthRestClientProperties::class.java - ) - val basicProps: BasicAuthRestClientProperties = - bluePrintPropertiesService.propertyBeanType( - prefix, BasicAuthRestClientProperties::class.java - ) - sslProps.basicAuth = basicProps - return sslProps - } + private fun sslBasicAuthRestClientProperties(prefix: String): SSLRestClientProperties { + return bluePrintPropertiesService.propertyBeanType( + prefix, SSLBasicAuthRestClientProperties::class.java + ) + } private fun sslTokenAuthRestClientProperties(prefix: String): SSLRestClientProperties { diff --git a/ms/blueprintsprocessor/modules/commons/rest-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/rest/service/SSLRestClientService.kt b/ms/blueprintsprocessor/modules/commons/rest-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/rest/service/SSLRestClientService.kt index 86e3ced06..a8d79b6fa 100644 --- a/ms/blueprintsprocessor/modules/commons/rest-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/rest/service/SSLRestClientService.kt +++ b/ms/blueprintsprocessor/modules/commons/rest-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/rest/service/SSLRestClientService.kt @@ -23,6 +23,7 @@ import org.apache.http.impl.client.CloseableHttpClient import org.apache.http.impl.client.HttpClients import org.apache.http.message.BasicHeader import org.apache.http.ssl.SSLContextBuilder +import org.onap.ccsdk.cds.blueprintsprocessor.rest.BasicAuthRestClientProperties import org.onap.ccsdk.cds.blueprintsprocessor.rest.SSLBasicAuthRestClientProperties import org.onap.ccsdk.cds.blueprintsprocessor.rest.SSLRestClientProperties import org.onap.ccsdk.cds.blueprintsprocessor.rest.SSLTokenAuthRestClientProperties @@ -48,7 +49,9 @@ class SSLRestClientService(private val restClientProperties: SSLRestClientProper // set them in auth obj to be consistent. TODO: refactor return when (restClientProperties) { is SSLBasicAuthRestClientProperties -> { - val basicAuthProps = restClientProperties.basicAuth!! + val basicAuthProps = BasicAuthRestClientProperties() + basicAuthProps.username = restClientProperties.username + basicAuthProps.password = restClientProperties.password basicAuthProps.additionalHeaders = restClientProperties.additionalHeaders basicAuthProps.url = restClientProperties.url basicAuthProps.type = restClientProperties.type diff --git a/ms/blueprintsprocessor/modules/commons/rest-lib/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/rest/service/BlueprintRestLibPropertyServiceTest.kt b/ms/blueprintsprocessor/modules/commons/rest-lib/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/rest/service/BlueprintRestLibPropertyServiceTest.kt index 117fbbd25..8843ff71d 100644 --- a/ms/blueprintsprocessor/modules/commons/rest-lib/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/rest/service/BlueprintRestLibPropertyServiceTest.kt +++ b/ms/blueprintsprocessor/modules/commons/rest-lib/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/rest/service/BlueprintRestLibPropertyServiceTest.kt @@ -102,8 +102,8 @@ class BlueprintRestLibPropertyServiceTest { val p: SSLBasicAuthRestClientProperties = properties as SSLBasicAuthRestClientProperties - assertEquals(p.basicAuth!!.username, "admin") - assertEquals(p.basicAuth!!.password, "cds") + assertEquals(p.username, "admin") + assertEquals(p.password, "cds") assertEquals(p.sslTrust, "src/test/resources/keystore.p12") assertEquals(p.sslTrustPassword, "changeit") assertEquals(p.keyStoreInstance, "PKCS12") @@ -151,8 +151,8 @@ class BlueprintRestLibPropertyServiceTest { assertNotNull(properties, "failed to create property bean") val p: SSLBasicAuthRestClientProperties = properties as SSLBasicAuthRestClientProperties - assertEquals("admin", p.basicAuth!!.username) - assertEquals("cds", p.basicAuth!!.password) + assertEquals("admin", p.username) + assertEquals("cds", p.password) assertEquals("src/test/resources/keystore.p12", p.sslTrust) assertEquals("changeit", p.sslTrustPassword) assertEquals("PKCS12", p.keyStoreInstance) @@ -464,10 +464,8 @@ class BlueprintRestLibPropertyServiceTest { "keyStoreInstance" : "PKCS12", "sslTrust" : "src/test/resources/keystore.p12", "sslTrustPassword" : "changeit", - "basicAuth" : { - "username" : "admin", - "password" : "cds" - }$headers + "username" : "admin", + "password" : "cds"$headers } """.trimIndent() |