From 2bb79c94758cd6dbb183bb75471c86486722f075 Mon Sep 17 00:00:00 2001 From: haburger Date: Mon, 13 Jan 2025 16:26:02 +0000 Subject: [PATCH] new configuration version --- ...8s-nevisauth-7022472ae407577ae604bbb8.yaml | 2 +- .../default/conf/ensureRecoveryCode.groovy | 32 +++++++++++-------- 2 files changed, 19 insertions(+), 15 deletions(-) diff --git a/DEFAULT-ADN-AGOV-PROJECT/DEFAULT-ADN-AGOV-INV/auth/etc/nevis/k8s-nevisauth-7022472ae407577ae604bbb8.yaml b/DEFAULT-ADN-AGOV-PROJECT/DEFAULT-ADN-AGOV-INV/auth/etc/nevis/k8s-nevisauth-7022472ae407577ae604bbb8.yaml index f6135d7..2d2949f 100644 --- a/DEFAULT-ADN-AGOV-PROJECT/DEFAULT-ADN-AGOV-INV/auth/etc/nevis/k8s-nevisauth-7022472ae407577ae604bbb8.yaml +++ b/DEFAULT-ADN-AGOV-PROJECT/DEFAULT-ADN-AGOV-INV/auth/etc/nevis/k8s-nevisauth-7022472ae407577ae604bbb8.yaml @@ -45,7 +45,7 @@ spec: podDisruptionBudget: maxUnavailable: "50%" git: - tag: "r-500f09f8321aa28d34a7334829af22055902f81b" + tag: "r-5190e6a7cf86a817b73807ecaff4b41c37839349" dir: "DEFAULT-ADN-AGOV-PROJECT/DEFAULT-ADN-AGOV-INV/auth" credentials: "git-credentials" keystores: diff --git a/DEFAULT-ADN-AGOV-PROJECT/DEFAULT-ADN-AGOV-INV/auth/var/opt/nevisauth/default/conf/ensureRecoveryCode.groovy b/DEFAULT-ADN-AGOV-PROJECT/DEFAULT-ADN-AGOV-INV/auth/var/opt/nevisauth/default/conf/ensureRecoveryCode.groovy index 041a9ed..d8b392c 100644 --- a/DEFAULT-ADN-AGOV-PROJECT/DEFAULT-ADN-AGOV-INV/auth/var/opt/nevisauth/default/conf/ensureRecoveryCode.groovy +++ b/DEFAULT-ADN-AGOV-PROJECT/DEFAULT-ADN-AGOV-INV/auth/var/opt/nevisauth/default/conf/ensureRecoveryCode.groovy @@ -1,7 +1,5 @@ import ch.nevis.esauth.auth.engine.AuthResponse -import ch.nevis.idm.client.IdmRestClient -import ch.nevis.idm.client.IdmRestClientFactory -import ch.nevis.idm.client.HTTPRequestWrapper +import ch.nevis.esauth.util.httpclient.api.HttpClient import groovy.json.JsonSlurper import groovy.xml.XmlSlurper @@ -19,7 +17,7 @@ def userAgent = request.getLoginContext()['connection.HttpHeader.user-agent'] ?: -IdmRestClient idmRestClient = IdmRestClientFactory.get(parameters) +HttpClient httpClient = HttpClients.create(parameters) String clientExtId = session.get('ch.adnovum.nevisidm.user.clientExtId') String userExtId = session.get('ch.adnovum.nevisidm.user.extId') @@ -65,21 +63,27 @@ if (outargs.containsKey('out.JWTToken')) { if (!session['agov.new.recovery.code.generated']) { inargs.remove('submit') try { - def postRequest = new HTTPRequestWrapper() - postRequest.addToHeaders('Content-Type', ['application/json']) + def httpResponse = Http.post() + .url(endPoint) + .header("Accept", "application/json") + .header("traceparent", traceparent) + .entity(Http.entity() + .content("{\"userExtId\":\"$userExtId\",\"userSessionId\": \"$sessionId\"}") + .contentType("application/json") + .charSet("utf-8") + .build()) + .build() + .send(httpClient) - postRequest.setPayLoad("{\"userExtId\":\"$userExtId\",\"userSessionId\": \"$sessionId\"}".getBytes('UTF-8')) - - def result = idmRestClient.postWithResponse(endPoint, postRequest) - if (result.getStatusCode() != 200) { - LOG.debug("Payload: ${new String(postRequest.getPayLoad())}") - LOG.debug("Result: ${result}") - LOG.warn("Event='RCVRY-CODE', Requester='${requester}', RequestId='${requestId}', RequestedAq=${requestedAq}, User=${user}, CredentialType='${credentialType}', SourceIp=${sourceIp}, UserAgent='${userAgent}', reason='Failed to create code (http status code ${result.getStatusCode()})") + + if (httpResponse.code() != 200) { + LOG.debug("Result: ${httpResponse}") + LOG.warn("Event='RCVRY-CODE', Requester='${requester}', RequestId='${requestId}', RequestedAq=${requestedAq}, User=${user}, CredentialType='${credentialType}', SourceIp=${sourceIp}, UserAgent='${userAgent}', reason='Failed to create code (http status code ${httpResponse.code()})") response.setResult('failed') return } - def json = new JsonSlurper().parseText(new String(result.getPayLoad(), 'UTF-8')) + def json = new JsonSlurper().parseText(httpResponse.bodyAsString()) notes.setProperty('agov.new.recovery.code', json['recoveryCode']['code'].replaceAll('^(....)(....)(.*)$', '$1-$2-$3')) LOG.debug("agov.new.recovery.code: ${notes['agov.new.recovery.code']}")