Last active
September 29, 2020 21:48
-
-
Save kianting/ad059fe0077dc096706561c46fa9942b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.net.*; | |
import java.io.*; | |
import groovy.json.JsonSlurper | |
import groovy.json.JsonOutput | |
def queryParameterAsObject(sQueryParameter){ | |
def retVal = [:]; | |
def arrParam = sQueryParameter.split("\\&"); | |
if (arrParam.size() > 1){ | |
arrParam.each{ def keyVal = it?.split('='); | |
if (keyVal.size() > 1){ | |
retVal.put(keyVal[0], keyVal[1]); | |
} | |
}; | |
}else{ | |
def keyVal = arrParam[0].split("="); | |
if (keyVal.size() > 1){ | |
retVal.put(keyVal[0], keyVal[1]); | |
} | |
} | |
return retVal; | |
} | |
def convertObjQueryParamToUnencodedURL(objParam){ | |
def retVal = ""; | |
if (objParam != null){ | |
objParam.each{ | |
retVal += "${it.key}=${it.value}&" | |
} | |
if (retVal.length() > 0) retVal = retVal.substring(0, retVal.length() - 1); | |
} | |
return retVal; | |
} | |
def setQueryParamForGoto(sEncodedRefererUrl, objQueryParam){ | |
def retVal = sEncodedRefererUrl; | |
try{ | |
URL origRefererUrl = new URL(sEncodedRefererUrl); | |
def objOuterQueryParam = queryParameterAsObject(origRefererUrl.getQuery()); | |
println "Referer Url Params:" + JsonOutput.prettyPrint(JsonOutput.toJson(objOuterQueryParam)); | |
def strEncodedGotoUrl = objOuterQueryParam.goto; | |
def strDecodedGotoUrl = java.net.URLDecoder.decode(strEncodedGotoUrl); | |
println "strDecodedGotoUrl: " + strDecodedGotoUrl; | |
URL origDecodedGotoUrl = new URL(strDecodedGotoUrl); | |
def objGotoQueryParam = queryParameterAsObject(origDecodedGotoUrl.getQuery()); | |
println "Decoded Goto Url Params:" + JsonOutput.prettyPrint(JsonOutput.toJson(objGotoQueryParam)); | |
objGotoQueryParam << objQueryParam; | |
println "Appended Additional Claims into Goto Url Params:" + JsonOutput.prettyPrint(JsonOutput.toJson(objGotoQueryParam)); | |
if(strDecodedGotoUrl.split("\\?").size() > 1){ | |
strDecodedGotoUrl = strDecodedGotoUrl.split("\\?")[0] +"?"+ convertObjQueryParamToUnencodedURL(objGotoQueryParam); | |
} | |
println "Appended Additional Claims strDecodedGotoUrl:" + strDecodedGotoUrl; | |
objOuterQueryParam.goto = java.net.URLEncoder.encode(strDecodedGotoUrl); | |
println "Updated Referer Url Params:" + JsonOutput.prettyPrint(JsonOutput.toJson(objOuterQueryParam)); | |
if(sEncodedRefererUrl.split("\\?").size() > 1){ | |
retVal = sEncodedRefererUrl.split("\\?")[0] +"?"+ convertObjQueryParamToUnencodedURL(objOuterQueryParam); | |
} | |
}catch(Exception ex){ | |
ex.printStackTrace(); | |
} | |
return retVal; | |
} | |
//println "test".split("\\&").size(); | |
println setQueryParamForGoto("https://localhost:8446/data-holder/login?goto=https%3A%2F%2Flocalhost%3A8446%2Foauth2%2Fauthorize%3Fresponse_type%3Dcode%2520id_token%26client_id%3Dbudgetguide%26redirect_uri%3Dhttps%253A%252F%252Flocalhost%253A9445%252Fdata-recipient%252Fsuccess%26scope%3Dopenid%2520profile%2520bank%253Aaccounts.basic%253Aread%26state%3DCLIENT_ID_budgetguide%26nonce%3D46e49db5-83d6-4057-98e8-f48e94a48a77%26request%3DeyJhbGciOiJQUzI1NiIsInR5cCI6IkpXVCIsImtpZCI6IjYxNGU1MmUwLWI5MWItNTMzNi04NjVhLTdkNDJhYjFmZmEwYiJ9.eyJhdWQiOiJodHRwczovL2xvY2FsaG9zdDo4NDQ2L29hdXRoMiIsInJlc3BvbnNlX3R5cGUiOiJjb2RlIGlkX3Rva2VuIiwiY2xpZW50X2lkIjoiYnVkZ2V0Z3VpZGUiLCJyZWRpcmVjdF91cmkiOiJodHRwczovL2xvY2FsaG9zdDo5NDQ1L2RhdGEtcmVjaXBpZW50L3N1Y2Nlc3MiLCJzY29wZSI6Im9wZW5pZCBwcm9maWxlIGJhbms6YWNjb3VudHMuYmFzaWM6cmVhZCIsInN0YXRlIjoiQ0xJRU5UX0lEX2J1ZGdldGd1aWRlIiwibm9uY2UiOiI0NmU0OWRiNS04M2Q2LTQwNTctOThlOC1mNDhlOTRhNDhhNzciLCJpYXQiOjE2MDEzMzg1OTAsImV4cCI6MTYwMTMzOTQ5MCwiY2xhaW1zIjp7InNoYXJpbmdfZHVyYXRpb24iOjc3NzYwMDAsImlkX3Rva2VuIjp7ImFjciI6eyJlc3NlbnRpYWwiOnRydWUsInZhbHVlcyI6WyJ1cm46Y2RzLmF1OmNkcjozIl19fSwidXNlcmluZm8iOnsiZ2l2ZW5fbmFtZSI6bnVsbCwiZmFtaWx5X25hbWUiOm51bGx9fX0.Y7z_5EGUZwCgQ4mxrm50myYmFq_D9v47THc0rf9J4dJot7SKclc44i2FiDQEUYEDit7jnGr4V7PIA-P1E6KBQxWFtapqPHCq69mIGLLD05SBGUeUR3vPjJFjYXjGLwTEFm_H-iHMbq5sXrkrUQz7qrh_TXyxOSgZ_ncQTAGqNnW13MFXtbD2P26yqpygocTtw_1aJLuvwQGdh7wdMvUlihhHsFJ-_0pxSbf0d6t4wU3yr5vGzXzkBTPx2Rj_4OXIL7-Uicit8Xi_YhUwQ4B4jW4x2P3EE1Dq_I5eZxKAXJybx5sD3kckHAinMTRDbMewwo6QhFFI4yRR2zqcH_h0Qw%26acr%3Durn%253Acds.au%253Acdr%253A3%26acr_sig%3DVE0xqXOuffx1tOmNeEeygajo6uNNGNdX2JrjXE5Ut34&realm=/&service=CDRWebAuthTree&authIndexType=service", | |
['Kian': 'washere']) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment