Exemplo n.º 1
0
        private MinIdpUserData processResponse(Guid rel, JsonDataMap response)
        {
            if (ComponentEffectiveLogLevel < MessageType.Trace)
            {
                WriteLog(MessageType.DebugA, nameof(processResponse), "#100 Got response", related: rel, pars: response.ToJson(JsonWritingOptions.CompactASCII));
            }

            var got = response.UnwrapPayloadObject();

            if (got == null)
            {
                return(null);
            }

            var dataMap = got as JsonDataMap;

            if (dataMap == null)
            {
                if (got is string ciphered && ciphered.IsNotNullOrWhiteSpace())
                {
                    if (ComponentEffectiveLogLevel < MessageType.Trace)
                    {
                        WriteLog(MessageType.DebugA, nameof(processResponse), "#150 Deciphering", related: rel, pars: ciphered);
                    }

                    var deciphered = MessageProtectionAlgorithm.NonNull(nameof(MessageProtectionAlgorithm))
                                     .UnprotectObject(ciphered);

                    if (deciphered == null)//returns null if message could not be deciphered
                    {
                        WriteLog(MessageType.Critical, nameof(processResponse), StringConsts.SECURITY_IDP_RESPONSE_DECIPHER_ERROR, related: rel);
                    }

                    dataMap = deciphered as JsonDataMap;
                }
                else
                {
                    var etext = StringConsts.SECURITY_IDP_PROTOCOL_ERROR.Args("unsupported `data` of type `{0}`".Args(got.GetType().Name));

                    if (ComponentEffectiveLogLevel < MessageType.Trace)
                    {
                        WriteLog(MessageType.DebugError, nameof(processResponse), "#155 " + etext, related: rel);
                    }

                    throw new SecurityException(etext);
                }
            }