Last active
August 29, 2015 14:16
-
-
Save guih/d108102a5d5d5cec0e73 to your computer and use it in GitHub Desktop.
Groovy GoodData SSO Example
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
// This is a GoodData SSO implementation example with Groovy language following the article https://developer.gooddata.com/article/gooddata-pgp-single-sign-on | |
// 1. Download and install GnuPG for your platform from https://www.gnupg.org/download/ | |
// 2 Setup your keystore following https://developer.gooddata.com/article/how-to-generate-public-private-key-pair | |
def SSO_PROVIDER = "resultadosdigitais.com.br" | |
def signerEmail = "signer@resultadosdigitais.com.br" | |
def signerPassword = "myPassw0r4" | |
def projectUserEmail = "account+123@rdstation.com.br" | |
def projectId = "xapasdpas123aspasdas" | |
def dashboardId = "123" | |
def dashboardUrl = java.net.URLEncoder.encode("/dashboard.html?#project=/gdc/projects/${projectId}&dashboard=/gdc/md/${projectId}/obj/${dashboardId}") | |
def expirationInSeconds = 2 * 3600 // 2 hours, 10 min < expiration < 36 hours | |
def tempFilesDir = new File("/tmp") | |
def userCredentialsFile = new File(tempFilesDir, "user_credentials.json") | |
def signedFile = new File(tempFilesDir, "signed.gpg") | |
def signedAndEncryptedFile = new File(tempFilesDir, "signed_and_encrypted.gpg") | |
userCredentialsFile.withWriter { out -> | |
out.write("{\"email\": \"${projectUserEmail}\", \"validity\": ${new Date().time + expirationInSeconds}}") | |
} | |
"gpg -u ${signerEmail} --passphrase ${signerPassword} --output ${signedFile.getPath()} --armor --yes --always-trust --sign ${userCredentialsFile.getPath()}".execute().waitFor() | |
"gpg --recipient security@gooddata.com --output ${signedAndEncryptedFile.getPath()} --armor --yes --always-trust --encrypt ${signedFile.getPath()}".execute().waitFor() | |
// Use the parameter --homedir if your gnuPG install is in a different directory or the Path environment is not properly set | |
// "gpg --homedir ${yourGnuPgCustomInstallationPath} -u ${signerEmail} --passphrase ${signerPassword} --recipient security@gooddata.com --output ${signedAndEncryptedFile.getPath()} --armor --yes --always-trust --sign --encrypt ${userCredentialsFile.getPath()}".execute().waitFor() | |
// Single command version below | |
// "gpg -u ${signerEmail} --passphrase ${signerPassword} --recipient security@gooddata.com --output ${signedAndEncryptedFile.getPath()} --armor --yes --always-trust --sign --encrypt ${userCredentialsFile.getPath()}".execute().waitFor() | |
// Abbreviated form below | |
// "gpg -u ${signerEmail} --passphrase ${signerPassword} -r security@gooddata.com -o ${signedAndEncryptedFile.getPath()} -a --yes --always-trust -s -e ${userCredentialsFile.getPath()}".execute().waitFor() | |
def sessionId = signedAndEncryptedFile.withReader { input -> | |
java.net.URLEncoder.encode(input.getText()) | |
} | |
signedFile.delete() | |
userCredentialsFile.delete() | |
signedAndEncryptedFile.delete() | |
def iframeSrc = "https://secure.gooddata.com/gdc/account/customerlogin?sessionId=${sessionId}&serverURL=${SSO_PROVIDER}&targetURL=${dashboardUrl}" | |
"""<iframe src="${iframeSrc}"/>""" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment