Decoding to SAML from encoded XML String

Not applicable
We have encoded string, fZLNasMwEIRfxehuW1biP5EYCqFgSHtoSg+9FEVeJwZbUqR1msev7DSQ9pDraL4ZdtDKiaE3fKsPesQ3OI3gMLgMvXJ8flmT0SquhescV2IAx1Hy3dPLlrOIcmM1aql7coc8JoRzYLHTigT1Zk2+aMH2GYVCNlCyXLYsE+0S8ixtila2krZi36RZAbIkwQdY58k18UEed26EWjkUCr1EkzykeZiU70nCGeUs+yTBxl/TKYEzdUQ0jscxejEUpjt8R1JbEyH0oLSNlI5RSRf28xbxOSHVajqIz022uvHCmEgr8LZO+YQhnkzxACgagSJOC1pki1V8j15zXv0a9SZ41nYQ+HimSemasJ2t3EyHOwSFpCrzcskYpcVvwzX02mD4Dtw0Ua0auFRWqnGZ4Klr2jJpUsV6CYzpxfl4Zf/Zb+Kfv1D9AA==

Decoded Response:

<samlp:LogoutRequest xmlns:samlp="urn:oasis:names:tc:SAML:2.0:protocol" xmlns:saml="urn:oasis:names:tc:SAML:2.0:assertion" ID="_082b60e8cde927cf26af4e765d8fcfc0fabd568ec9" Version="2.0" IssueInstant="2017-07-19T11:20:26Z" Destination="https://test-apigw.corp.telenor.no/tncs-logout/v1"><saml:Issuer>https://app.onelogin.com/saml/metadata/580863</saml:Issuer><saml:NameID Format="urn:oasis:names:tc:SAML:2.0:nameid-format:persistent">979422008</saml:NameID><samlp:SessionIndex>rcnu41tqidf91d5n2lce22o3vh</samlp:SessionIndex></samlp:LogoutRequest>

which when decoded using online editor return SAML Response. How to achieve this in APIGEE.

can we use node module in Apigee.

If anyone can share the sample code developed in Javascript, Node.JS or Java Callout for implementing this transformation.

1 1 4,232
1 REPLY 1

That encoding for SAML is .... deflated, then base64 encoded.

So to reverse that you would need to base64 decode, then Inflate.

You could do it with

  • nodejs
  • a Java callout

I think I would prefer to do it with a Java callout. It's pretty simple. Like this.

public ExecutionResult execute (final MessageContext msgCtxt,
                                final ExecutionContext execContext) {
    try {
        String inputVariableName = getInput(msgCtxt);
        String outputVariableName = getOutput(msgCtxt);
        String encodedString = msgCtxt.getVariable(inputVariableName);
        // base64-Decode the String into bytes
        byte[] decoded = BaseEncoding.base64().decode(encodedString);
        // Decompress the bytes
        byte[] decompressed = decompress(decoded);
        // Decode the bytes into a String
        String outputString = new String(decompressed, 0, decompressed.length, "UTF-8");
        msgCtxt.setVariable(outputVariableName, outputString);
        return ExecutionResult.SUCCESS;


    }
    catch (java.lang.Exception exc1) {
        msgCtxt.setVariable(varName("error"), exc1.getMessage());
        msgCtxt.setVariable(varName("stacktrace"), ExceptionUtils.getStackTrace(exc1));
        // The following would go to stdout of Message processor
        // System.out.println("Exception:" + exc1.toString());
        // exc1.printStackTrace();
        return ExecutionResult.ABORT;
    }
}

See attached for a working example.

apigee-edge-java-callout-samldecoder-20170901-1848.zip