コード例 #1
0
        public QlikApp(UserParameter parameter)
        {
            if (parameter.UseDesktop)
            {
                return;
            }

            var domainUser = new DomainUser(parameter.UserName);

            if (domainUser == null)
            {
                throw new Exception("The user must a DomainUser like this UserDirectory\\UserId");
            }

            if (!WinAuth.ValidateWinCredentials(domainUser.UserId, parameter.Password))
            {
                throw new Exception("The windows credentials was not correct.");
            }
        }
コード例 #2
0
        public IGlobal GetGlobelContext()
        {
            try
            {
                logger.Debug("Create global context");
                var config = new EnigmaConfigurations()
                {
                    Url          = ConnectUri.AbsoluteUri,
                    CreateSocket = async(Url) =>
                    {
                        var webSocket = new ClientWebSocket();
                        webSocket.Options.Cookies = new CookieContainer();

                        var callback = ServicePointManager.ServerCertificateValidationCallback;
                        if (callback == null)
                        {
                            throw new NotImplementedException(".NET has no certificate check");
                        }

                        var credentials = Config?.Credentials ?? null;
                        var credType    = Config?.Credentials?.Type ?? QlikCredentialType.NONE;
                        switch (credType)
                        {
                        case QlikCredentialType.CERTIFICATE:
                            var domainUser = new DomainUser(credentials.Value);
                            var options    = new CookieConnectionOptions()
                            {
                                CertificatePath = credentials?.Cert ?? null,
                                HeaderName      = "X-Qlik-User",
                                HeaderValue     = $"UserDirectory={domainUser.UserDirectory};UserId={domainUser.UserId}",
                                UseCertificate  = true,
                            };

                            var qlikClientCert = new X509Certificate2();
                            qlikClientCert = qlikClientCert.GetQlikClientCertificate(options.CertificatePath);
                            webSocket.Options.ClientCertificates.Add(qlikClientCert);
                            webSocket.Options.SetRequestHeader(options.HeaderName, options.HeaderValue);
                            logger.Debug($"Credential type: {credentials?.Type}");
                            break;

                        case QlikCredentialType.WINDOWSAUTH:
                            webSocket.Options.Credentials = new NetworkCredential(credentials?.Key, credentials?.Value);
                            logger.Debug($"WinAuth type: {credentials?.Type} with User {credentials?.Key}");
                            break;

                        case QlikCredentialType.SESSION:
                            logger.Debug($"Session-Cookie {credentials?.Key}={credentials?.Value}.");
                            ConnectCookie = new Cookie(credentials?.Key, credentials?.Value)
                            {
                                Secure = true,
                                Domain = ConnectUri.Host,
                                Path   = "/",
                            };
                            webSocket.Options.Cookies.Add(ConnectCookie);
                            logger.Debug($"Session type: {credentials?.Type} with Session {credentials?.Value}");
                            break;

                        case QlikCredentialType.NONE:
                            logger.Debug($"None type: No Authentication.");
                            // No Authentication for DESKTOP and DOCKER
                            break;

                        default:
                            throw new Exception("Unknown Qlik connection type.");
                        }
                        webSocket.Options.KeepAliveInterval = TimeSpan.FromDays(48);
                        await webSocket.ConnectAsync(new Uri(Url), CancellationToken.None);

                        return(webSocket);
                    },
                };

                SocketSession = Enigma.Create(config);
                var globalTask = SocketSession.OpenAsync();
                globalTask.Wait();
                logger.Debug("Found globel context");
                return(Impromptu.ActLike <IGlobal>(globalTask.Result));
            }
            catch (Exception ex)
            {
                logger.Debug(ex, "No Global context");
                return(null);
            }
        }