public static bool Validate(ServerCallContext context)
        {
            Metadata.Entry metadataEntry = context.RequestHeaders.FirstOrDefault(m =>
                                                                                 String.Equals(m.Key, ActiveDirectoryCredentialsFactory.AuthorizationHeader, StringComparison.Ordinal));

            if (metadataEntry.Equals(default(Metadata.Entry)) || metadataEntry.Value == null)
            {
                return(false);
            }

            string authorizationHeaderValue = Encoding.UTF8.GetString(Convert.FromBase64String(metadataEntry.Value));

            if (String.IsNullOrWhiteSpace(authorizationHeaderValue))
            {
                return(false);
            }

            var splitedString = authorizationHeaderValue.Split(':');

            if (splitedString.Length < 3)
            {
                return(false);
            }

            string userName = splitedString[0];
            string password = splitedString[1];
            string domain   = splitedString[2];

            return(ValidateLdapCredentials(userName, password, domain));
        }
Ejemplo n.º 2
0
        private DistributedTracingData getDistributedTracingData(ServerCallContext context)
        {
            Metadata.Entry         metadataEntry          = context.RequestHeaders.FirstOrDefault(m => String.Equals(m.Key.ToLower(), "elastic-apm-traceparent", StringComparison.Ordinal));
            DistributedTracingData distributedTracingData = null;

            if (metadataEntry != null && !metadataEntry.Equals(default(Metadata.Entry)) && metadataEntry.Value != null)
            {
                distributedTracingData = DistributedTracingData.TryDeserializeFromString(metadataEntry.Value);
            }
            return(distributedTracingData);
        }
        public async static Task <Session> GetSession(this ServerCallContext context)
        {
            Metadata.Entry metadataEntry = context.RequestHeaders.FirstOrDefault(m => String.Equals(m.Key, "session_id", StringComparison.Ordinal));

            if (metadataEntry.Equals(default(Metadata.Entry)) || metadataEntry.Value == null)
            {
                Log.Information($"GetSession value is null");
                return(null);
            }
            Log.Information($"SessionId value is {metadataEntry.Value}, url{context.Method}, peer{context.Peer}");

            var session = await Session.GetSession(metadataEntry.Value);

            if (session == null)
            {
                Log.Warning($"lost session, url{context.Method}, peer{context.Peer}, session_id{metadataEntry.Value}");
            }
            return(session);
        }
        private IIncomingRemoteCallTracer getTracer(Grpc.Core.ServerCallContext context, string methodname)
        {
            try {
                Metadata.Entry metadataEntry = context.RequestHeaders.FirstOrDefault(m => String.Equals(m.Key, "x-dynatrace"));

                if (metadataEntry.Equals(default(Metadata.Entry)) || metadataEntry.Value == null)
                {
                    Console.WriteLine("No x-dynatrace header found in the request.");
                    return(null);
                }

                string incomingDynatraceStringTag = metadataEntry.Value;
                IIncomingRemoteCallTracer incomingRemoteCallTracer = oneAgentSdk.TraceIncomingRemoteCall(methodname, "CartService", "grpc://cartservice/" + methodname);
                incomingRemoteCallTracer.SetDynatraceStringTag(incomingDynatraceStringTag);
                incomingRemoteCallTracer.SetProtocolName("gRPC");

                return(incomingRemoteCallTracer);
            } catch (Exception e) {
                Console.WriteLine(e.ToString());
                return(null);
            }
        }