Ejemplo n.º 1
0
        public void TestUsernameToString()
        {
            var expected = "*****@*****.**";

            var usernamedomain = UsernameDomain.Parse(expected);

            Assert.AreEqual(expected, usernamedomain.ToString());
        }
Ejemplo n.º 2
0
        public void TestUsernameUsername()
        {
            var test     = "*****@*****.**";
            var expected = "test";

            var usernamedomain = UsernameDomain.Parse(test);

            Assert.AreEqual(expected, usernamedomain.Username);
        }
Ejemplo n.º 3
0
        public void TestUsernameToStringStripAdditional2()
        {
            var username = "******";
            var expected = "*****@*****.**";

            var usernamedomain = UsernameDomain.Parse(username, true);

            Assert.AreEqual(expected, usernamedomain.ToString());
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Proxy iPass authentication to an external server
        /// </summary>
        /// <param name="rawusername"></param>
        /// <param name="password"></param>
        /// <returns></returns>
        public PacketCode?ProxyAuthentication(String rawusername, String password)
        {
            using (var db = _contextFactory.GetContext())
            {
                var usernamedomain = UsernameDomain.Parse(rawusername, true);
                var server         = db.Roamservers.FirstOrDefault(o => o.domain == usernamedomain.Domain);
                if (server != null)
                {
                    _log.Debug($"Found proxy server {server.host} for username {rawusername}");

                    if (!String.IsNullOrEmpty(server.rewritedomain))
                    {
                        usernamedomain.Domain = server.rewritedomain;
                        _log.Debug($"Rewriting username from {rawusername} to {usernamedomain}");
                        rawusername = usernamedomain.FullUsername;
                    }

                    ProcessStartInfo startinfo;
                    if (server.uselegacy)
                    {
                        startinfo = ProxyAuthenticationSsl(rawusername, password, server.host);
                    }
                    else
                    {
                        startinfo = ProxyAuthenticationNew(rawusername, password, server.host);
                    }

                    using (var process = new Process
                    {
                        StartInfo = startinfo
                    })
                    {
                        var sb = new StringBuilder();
                        process.OutputDataReceived += (sender, args) => sb.AppendLine(args.Data);
                        process.Start();
                        process.BeginOutputReadLine();
                        process.StandardInput.WriteLine();  // Exits the script
                        process.WaitForExit();
                        var content = sb.ToString();

                        _log.Debug(content);

                        if (content.Contains("Status: accept"))
                        {
                            return(PacketCode.AccessAccept);
                        }
                        if (content.Contains("LDAP User found but memberOf validation failed"))
                        {
                            _log.Warn($"MemberOf failed for user {rawusername}");
                        }
                        if (content.Contains("Message: LDAP search found no entries for this user"))
                        {
                            _log.Warn($"Username {rawusername} not found");
                        }
                        if (content.Contains("Status: reject"))
                        {
                            _log.Warn($"Got reject for user {rawusername} from proxy");
                        }

                        if (!(content.Contains("reject") || content.Contains("accept")))
                        {
                            _log.Error($"Invalid proxy response: {content}");
                            throw new InvalidOperationException("Something went wrong with proxy");
                        }
                    }

                    return(PacketCode.AccessReject);
                }
            }

            return(null);
        }