public async Task <bool> RegisterUser(User user, UsernameCredentials credentials, Preferences preferences)
        {
            AuthResponse?auth = await this.Service.Register(user, credentials);

            bool success = auth != null;

            if (success)
            {
                if (!this.keychain.Save(credentials, this.Service.Endpoint))
                {
                    this.logger.LogError("Failed to save username credentials to keychain");
                }

                this.Service.AuthToken = auth !.Token;
                // The server doesn't currently send email, but we reference it immediately after creating an account,
                // so just fill it in from the input
                auth.User.Email ??= user.Email;
                if (auth.User.PreferencesId != null)
                {
                    preferences.Id     = auth.User.PreferencesId;
                    preferences.UserId = auth.User.Id;
                    await this.Service.Save(preferences);
                }

                this.userSettings.SetUsernameForId(credentials.Username, auth.User.Id);
                await this.Signin(auth.User, preferences);
            }

            return(success);
        }
        public async Task <bool> RegisterUserAsync(User user, UsernameCredentials credentials, Preferences preferences, bool registeredViaLoginForm)
        {
            AuthResponse?auth = await this.Service.Register(user, credentials);

            bool success = auth is not null;

            if (success)
            {
                if (!this.keychain.Save(credentials, this.Service.Endpoint))
                {
                    this.logger.LogError("Failed to save username credentials to keychain");
                }

                this.Service.AuthToken = auth !.Token;
                // The server doesn't currently send email, but we reference it immediately after creating an account,
                // so just fill it in from the input
                auth.User.Email ??= user.Email;
                if (auth.User.PreferencesId is not null)
                {
                    preferences.Id     = auth.User.PreferencesId;
                    preferences.UserId = auth.User.Id;
                    // OBSERVATION: we do not check to see if the save to the server was successful
                    _ = await this.Service.SaveAsync(preferences);
                }

                this.userSettings.SetUsernameForId(credentials.Username, auth.User.Id);
                await this.SignInAsync(auth.User, preferences, registeredViaLoginForm);
            }

            return(success);
        }
        /// <summary>
        /// Perform the method
        /// </summary>
        /// <returns></returns>
        private async Task Login()
        {
            ErrorLabel.Visibility = Visibility.Hidden;
            SetFieldsEnabled(false);
            var credentials = new UsernameCredentials(UsernameField.Text, PasswordField.Password);
            var success     = false;

            try
            {
                success = await session.Authenticate(credentials);
            }
            catch (Session.BadRequestException e)
            {
                logger.LogWarning(e, "Bad login request");
            }
            if (!success)
            {
                ErrorLabel.Visibility = Visibility.Visible;
                ErrorLabel.Focus(); // Makes narrator read the error label
                SetFieldsEnabled(true);
            }
            else
            {
                _ = session.ApplyAllPreferences();
                Close();
            }
        }
 public OrionInfoServiceCompressed(string username, string password, bool v3 = false)
 {
     _endpoint           = v3 ? Settings.Default.OrionV3EndpointPathCompressed : Settings.Default.OrionEndpointPathCompressed;
     _endpointConfigName = "OrionTcpBindingCompressed";
     _binding            = new CustomBinding("CompressedUserName");
     _credentials        = new UsernameCredentials(username, password);
 }
Beispiel #5
0
 public NCMInfoService(string username, string password)
 {
     _endpoint           = Settings.Default.NCMEndpointPath;
     _endpointConfigName = "NCMTcpBinding_InformationServicev2";
     _binding            = new NetTcpBinding("TransportMessage");
     _credentials        = new UsernameCredentials(username, password);
 }
        /// <summary>
        /// Perform the method
        /// </summary>
        /// <returns></returns>
        private async Task Login()
        {
            this.ErrorLabel.Visibility = Visibility.Hidden;
            this.SetFieldsEnabled(false);
            var credentials = new UsernameCredentials(this.UsernameBox.Text, this.PasswordBox.Password);
            var success     = false;

            try
            {
                success = await this.session.Authenticate(credentials);
            }
            catch (HttpService.BadRequestException e)
            {
                this.logger.LogWarning(e, "Bad login request");
            }
            if (!success)
            {
                this.ErrorLabel.Visibility = Visibility.Visible;
                this.ErrorLabel.Focus(); // Makes narrator read the error label
                this.SetFieldsEnabled(true);
            }
            else
            {
                this.Close();
            }
        }
        /// <summary>
        /// Perform the method
        /// </summary>
        /// <returns></returns>
        private async Task Login()
        {
            this.ErrorLabel.Visibility = Visibility.Hidden;
            this.SetFieldsEnabled(false);
            UsernameCredentials?credentials = new UsernameCredentials(this.UsernameField.Text, this.PasswordField.Password);
            bool success = false;

            try
            {
                success = await this.morphicSession.Authenticate(credentials);
            }
            catch (HttpService.BadRequestException e)
            {
                this.logger.LogWarning(e, "Bad login request");
            }
            if (!success)
            {
                this.ErrorLabel.Visibility = Visibility.Visible;
                this.ErrorLabel.Focus(); // Makes narrator read the error label
                this.SetFieldsEnabled(true);
            }
            else if (this.ApplyPreferences)
            {
                _ = this.morphicSession.ApplyAllPreferences();
                this.Close();
            }
            else
            {
                this.OnComplete();
            }
        }
        /// <summary>
        /// Perform the method
        /// </summary>
        /// <returns></returns>
        private async Task Login()
        {
            this.ErrorLabel.Visibility = Visibility.Hidden;
            this.SetFieldsEnabled(false);
            UsernameCredentials?credentials = new UsernameCredentials(this.UsernameField.Text, this.PasswordField.Password);
            bool success = false;

            try
            {
                success = await this.morphicSession.Authenticate(credentials, true);
            }
            catch (HttpService.BadRequestException e)
            {
                this.logger.LogWarning(e, "Bad login request");
            }
            if (!success)
            {
                this.ErrorLabel.Visibility = Visibility.Visible;
                // OBSERVATION: this may not be the best option, as the user then needs to figure out how to get back to the password field; setting focus to the Password field would be ideal if we can also make narrator read this error label
                this.ErrorLabel.Focus(); // Makes narrator read the error label
                this.SetFieldsEnabled(true);
            }
            else if (this.ApplyPreferencesAfterLogin)
            {
                // login successful
                await App.Current.Countly_RecordEventAsync("signIn");

                _ = this.morphicSession.ApplyAllPreferences();
                this.Close();
            }
            else
            {
                this.OnComplete();
            }
        }
Beispiel #9
0
        private CEUtil(string ceUri, string osName, string ceUser, string password, LogMsg logMsg)
        {
#if (P8_451)
            // P8 4.5 authentication
            UsernameToken token = new UsernameToken(ceUser, password, PasswordOption.SendPlainText);
            UserContext.SetProcessSecurityToken(token);
#else
            // P8 5.0 authentication
            UsernameCredentials cred = new UsernameCredentials(ceUser, password);
            ClientContext.SetProcessCredentials(cred);
#endif
            conn = Factory.Connection.GetConnection(ceUri);
            isCredentialsEstablished = true;

            // Get domain name
            PropertyFilter pf = new PropertyFilter();
            pf.AddIncludeProperty(0, null, null, "Name", null);
            pf.AddIncludeProperty(0, null, null, "Id", null);
            domain = Factory.Domain.FetchInstance(conn, null, null);
            objStore = Factory.ObjectStore.FetchInstance(domain, osName, null);

            // Successfully initialized CEUtil object: save singleton instance
            this.logMsg = logMsg;
            gCEUtil = this;
        }
        public async Task <bool> RegisterUser(User user, UsernameCredentials credentials, Preferences preferences)
        {
            var auth = await Service.Register(user, credentials);

            if (auth != null)
            {
                if (!keychain.Save(credentials, Service.Endpoint))
                {
                    logger.LogError("Failed to save username creds to keychain");
                }
                AuthToken = auth.Token;
                // The server doesn't currently send email, but we reference it immedately after creating an account,
                // so just fill it in from the input
                auth.User.Email = auth.User.Email ?? user.Email;
                if (auth.User.PreferencesId is string preferencesId)
                {
                    preferences.Id     = preferencesId;
                    preferences.UserId = auth.User.Id;
                    await Service.Save(preferences);
                }
                userSettings.SetUsernameForId(credentials.Username, auth.User.Id);
                await Signin(auth.User, preferences);

                return(true);
            }
            return(false);
        }
Beispiel #11
0
 public UsernameRegistration(UsernameCredentials credentials, User user)
 {
     Username  = credentials.Username;
     Password  = credentials.Password;
     Email     = credentials.Username;
     FirstName = user.FirstName;
     LastName  = user.LastName;
 }
Beispiel #12
0
 public OrionHttpsInfoService(string username, string password, bool v3 = false)
 {
     _protocolName       = "https";
     _endpoint           = v3 ? Settings.Default.OrionV3HttpsEndpointPath : Settings.Default.OrionHttpsEndpointPath;
     _endpointConfigName = "OrionHttpBinding_InformationServicev2";
     _binding            = new BasicHttpBinding("SWIS.Over.HTTP");
     _credentials        = new UsernameCredentials(username, password);
 }
Beispiel #13
0
 public OrionInfoService(string username, string password, bool isSwisV3 = false)
 {
     _isSwisV3           = isSwisV3;
     _endpoint           = isSwisV3 ? Settings.Default.OrionV3EndpointPath : Settings.Default.OrionEndpointPath;
     _endpointConfigName = "OrionTcpBinding_InformationServicev2";
     _binding            = new NetTcpBinding("TransportMessage");
     _credentials        = new UsernameCredentials(username, password);
 }
Beispiel #14
0
 private CEConnection(string sUri, string sObjectStore, string sUserName, string sPassword)
 {
     System.Net.ServicePointManager.ServerCertificateValidationCallback = (a, b, c, d) => true;
     UsernameCredentials cred = new UsernameCredentials(sUserName, sPassword);
     ClientContext.SetProcessCredentials(cred);
     this.conn = Factory.Connection.GetConnection(sUri);
     this._domain = Factory.Domain.FetchInstance(this.conn, null, null);
     this.objectStore = Factory.ObjectStore.FetchInstance(this._domain, sObjectStore, null);
 }
Beispiel #15
0
        public JavaHttpInfoService(string username, string password)
        {
            _endpointConfigName = "JavaHttpBinding_InformationServicev2";
            _endpoint           = Settings.Default.JavaEndpointPath;

            _binding      = new WSHttpBinding("javaBinding");
            _protocolName = "https";
            _credentials  = new UsernameCredentials(username, password);

            ServicePointManager.ServerCertificateValidationCallback = ValidateRemoteCertificate;
        }
        /// <summary>
        /// An async method for actually doing the registration submission
        /// </summary>
        /// <returns></returns>
        private async Task Submit()
        {
            // TODO: show activity indicator
            this.UpdateValidation();
            this.SetFieldsEnabled(false);
            var user = new User();

            user.Email = this.UsernameField.Text;
            var credentials  = new UsernameCredentials(this.UsernameField.Text, this.PasswordField.Password);
            var success      = false;
            var errorMessage = "";

            try
            {
                success = await this.morphicSession.RegisterUser(user, credentials, this.Preferences);
            }
            catch (AuthService.BadPasswordException)
            {
                errorMessage = "Your password is too easily guessed.  Please use another.";
            }
            catch (AuthService.ExistingEmailException)
            {
                errorMessage = "We recognize your email.  Use the 'Already have an account?' link below.";
            }
            catch (AuthService.ExistingUsernameException)
            {
                errorMessage = "We recognize your email.  Use the 'Already have an account?' link below.";
            }
            catch (AuthService.InvalidEmailException)
            {
                errorMessage = "Please provide a valid email address";
            }
            if (success)
            {
                MessageBox.Show("Your account was created.\n\nPlease check your email for further instructions.");
                this.Completed?.Invoke(this, new EventArgs());
            }
            else
            {
                if (errorMessage == "")
                {
                    errorMessage = "We could not complete the request.  Please try again.";
                }
                this.ErrorLabel.Visibility = Visibility.Visible;
                this.ErrorLabel.Content    = errorMessage;
                this.ErrorLabel.Focus(); // Causes screen reader to read label
                this.SetFieldsEnabled(true);
            }
        }
        public async Task <bool> Authenticate(UsernameCredentials credentials)
        {
            var auth = await Service.Authenticate(credentials);

            if (auth != null)
            {
                keychain.Save(credentials, Service.Endpoint);
                AuthToken = auth.Token;
                userSettings.SetUsernameForId(credentials.Username, auth.User.Id);
                await Signin(auth.User);

                return(true);
            }
            return(false);
        }
Beispiel #18
0
        public async Task <bool> Authenticate(UsernameCredentials credentials)
        {
            AuthResponse?auth = await this.Service.Authenticate(credentials);

            bool success = auth != null;

            if (success)
            {
                this.keychain.Save(credentials, this.Service.Endpoint);
                this.Service.AuthToken = auth !.Token;
                this.userSettings.SetUsernameForId(credentials.Username, auth.User.Id);
                await this.Signin(auth.User);
            }
            return(success);
        }
Beispiel #19
0
        /// <summary>
        /// Private constructor
        /// </summary>
        /// <param keyName="userName">Username for Connect Engine</param>
        /// <param keyName="password">Password for Connect Engine</param>
        /// <param keyName="uri">URI</param>
        /// <param keyName="osName">Object Store Name</param>
        private CEConnection(string userName, string password, string uri, string osName)
        {
            //logger.Debug("Initializing " + typeof(CEConnection));
            System.Net.ServicePointManager.ServerCertificateValidationCallback = (a, b, c, d) => true;

            UsernameCredentials creds = new UsernameCredentials(userName, password);

            // Associate this ClientContext with the whole process.
            ClientContext.SetProcessCredentials(creds);

            // Get the connection and default domain.
            this._connection = Factory.Connection.GetConnection(uri);
            this._domain = Factory.Domain.GetInstance(this._connection, null);

            // Get an object store.
            this._objectStore = Factory.ObjectStore.FetchInstance(this._domain, osName, null);
        }
        private static InfoServiceProxy ConnectSoap12(Uri address, string username, string password)
        {
            var binding = new WSHttpBinding(SecurityMode.Transport);

            binding.Security.Transport.ClientCredentialType = HttpClientCredentialType.Basic;
            binding.Security.Message.ClientCredentialType   = MessageCredentialType.UserName;
            binding.ReaderQuotas.MaxDepth = 32;
            binding.ReaderQuotas.MaxStringContentLength = int.MaxValue;
            binding.ReaderQuotas.MaxArrayLength         = int.MaxValue;
            binding.MaxReceivedMessageSize             = int.MaxValue;
            binding.AllowCookies                       = true;
            binding.ReaderQuotas.MaxBytesPerRead       = 4096;
            binding.ReaderQuotas.MaxNameTableCharCount = 16384;
            binding.UseDefaultWebProxy                 = true;

            var credentials = new UsernameCredentials(username, password);

            return(new InfoServiceProxy(address, binding, credentials));
        }
Beispiel #21
0
        public void TestSaveLoad()
        {
            var encrypt = new MockEncrypter();
            var options = new KeychainOptions();

            options.Path = Path.Combine(directoryName, "testsave.json");
            var uri      = new Uri("http://www.morphic.org");
            var wronguri = new Uri("http://www.gpii.net");
            var username = new UsernameCredentials("passuser", "password");
            var key      = new KeyCredentials("key");
            var logger   = new LoggerFactory().CreateLogger <Keychain>();
            //TEST SAVING
            var keychain = new Keychain(options, encrypt, logger);

            Assert.True(keychain.Save(username, uri));
            Assert.Equal(1, encrypt.encryptCounter);
            Assert.Equal(0, encrypt.decryptCounter);
            Assert.True(keychain.Save(key, uri, "keyuser"));
            Assert.Equal(2, encrypt.encryptCounter);
            Assert.Equal(0, encrypt.decryptCounter);
            //TEST LOADING
            keychain = new Keychain(options, encrypt, logger);
            Assert.Equal(2, encrypt.encryptCounter);
            Assert.Equal(1, encrypt.decryptCounter);
            //TEST RETRIEVAL
            var newusername = keychain.LoadUsername(uri, "passuser");

            Assert.Equal("passuser", newusername.Username);
            Assert.Equal("password", newusername.Password);
            var newkey = keychain.LoadKey(uri, "keyuser");

            Assert.Equal("key", newkey.Key);
            newusername = keychain.LoadUsername(uri, "notathing");
            newkey      = keychain.LoadKey(uri, "notathing");
            Assert.Null(newusername);
            Assert.Null(newkey);
            //TODO: put any tests for switching usernames and keys here once that does something
            newusername = keychain.LoadUsername(wronguri, "passuser");
            newkey      = keychain.LoadKey(wronguri, "keyuser");
            Assert.Null(newusername);
            Assert.Null(newkey);
        }
Beispiel #22
0
        public void EstablishCredentials(String userName, String password, String uri, String osName)
        {
            //IConnection  conn = Factory.Connection.GetConnection(uri);
            //Subject subject = UserContext.createSubject(conn, username, password, null);
            //UserContext.get().pushSubject(subject);

            UsernameCredentials cred = new UsernameCredentials(userName, password);

            // now associate this Credentials with the whole process
            ClientContext.SetProcessCredentials(cred);
            IConnection connection = Factory.Connection.GetConnection(uri);
            IDomain     domain     = Factory.Domain.GetInstance(connection, null);

            isCredetialsEstablished = true;
            os = Factory.ObjectStore.FetchInstance(domain, osName, null);

            //domainName = domain.Name;
            //ost = domain.ObjectStores;
            //SetOSNames();
        }
        private InfoServiceProxy ConnectNetTcp()
        {
            InfoServiceProxy  infoServiceProxy;
            EndpointAddresses addresses = V2.IsPresent ? (EndpointAddresses) new V2EndpointAddresses() : new V3EndpointAddresses();

            if (Trusted.IsPresent)
            {
                var binding = new NetTcpBinding {
                    MaxReceivedMessageSize = int.MaxValue, MaxBufferSize = int.MaxValue
                };
                binding.Security.Mode = SecurityMode.Transport;
                binding.Security.Transport.ClientCredentialType = TcpClientCredentialType.Windows;

                var uri = new Uri(string.Format(addresses.activeDirectory, Hostname ?? "localhost"));

                infoServiceProxy = new InfoServiceProxy(uri, binding, new WindowsCredential());
            }
            else if (Certificate.IsPresent)
            {
                var binding = new NetTcpBinding(SecurityMode.Transport)
                {
                    MaxReceivedMessageSize = int.MaxValue, MaxBufferSize = int.MaxValue
                };
                binding.Security.Mode = SecurityMode.Transport;
                binding.Security.Transport.ClientCredentialType = TcpClientCredentialType.Certificate;
                binding.ReaderQuotas.MaxArrayLength             = int.MaxValue;
                binding.ReaderQuotas.MaxStringContentLength     = int.MaxValue;

                if (Streamed.IsPresent)
                {
                    binding.TransferMode       = TransferMode.Streamed;
                    binding.PortSharingEnabled = true;
                    binding.ReceiveTimeout     = new TimeSpan(15, 0, 0);
                    binding.SendTimeout        = new TimeSpan(15, 0, 0);
                }

                var address = (Streamed && !V2.IsPresent)
                                  ? ((V3EndpointAddresses)addresses).streamedCertificate
                                  : addresses.certificate;

                var uri = new Uri(string.Format(address, Hostname ?? "localhost"));

                ServiceCredentials credentials = new MyCertificateCredential("SolarWinds-Orion", StoreLocation.LocalMachine, StoreName.My);

                infoServiceProxy = new InfoServiceProxy(uri, binding, credentials);
            }
            else
            {
                var binding = new NetTcpBinding {
                    MaxReceivedMessageSize = int.MaxValue, MaxBufferSize = int.MaxValue
                };
                binding.Security.Mode = SecurityMode.TransportWithMessageCredential;
                binding.Security.Message.ClientCredentialType = MessageCredentialType.UserName;

                var uri = new Uri(string.Format(addresses.usernamePassword, Hostname ?? "localhost"));

                string username = string.Empty;
                string password = string.Empty;

                if (IsUserNamePresent)
                {
                    SecureString securePassword = StringToSecureString(Password);
                    Credential = new PSCredential(UserName, securePassword);
                }

                // the credential dialog adds a slash at the beginning, need to strip
                username = Credential.UserName.TrimStart('\\');
                password = SecureStringToString(Credential.Password);

                var credentials = new UsernameCredentials(username, password);

                infoServiceProxy = new InfoServiceProxy(uri, binding, credentials);
            }
            return(infoServiceProxy);
        }
Beispiel #24
0
        /// <summary>
        /// Send a reqeust to authenticate with username based credentials
        /// </summary>
        /// <param name="service"></param>
        /// <param name="usernameCredentials">The username credentials</param>
        /// <returns>An authentication token and user information, or <code>null</code> if the request failed</returns>
        public static async Task <AuthResponse?> AuthenticateUsername(this HttpService service, UsernameCredentials usernameCredentials)
        {
            var body = new AuthUsernameRequest(usernameCredentials.Username, usernameCredentials.Password);

            return(await service.Session.Send <AuthResponse>(() => HttpRequestMessageExtensions.Create(service.Session, "v1/auth/username", HttpMethod.Post, body)));
        }
Beispiel #25
0
        /// <summary>
        /// Send a request to create a new user with a username/password pair
        /// </summary>
        /// <param name="service"></param>
        /// <param name="user">The user to create</param>
        /// <param name="usernameCredentials">The user's username credentials</param>
        /// <returns>An authentication token and user information, or <code>null</code> if the request failed</returns>
        public static async Task <AuthResponse?> Register(this HttpService service, User user, UsernameCredentials usernameCredentials)
        {
            var registration = new UsernameRegistration(usernameCredentials, user);

            try
            {
                return(await service.Session.Send <AuthResponse>(() => HttpRequestMessageExtensions.Create(service.Session, "v1/register/username", HttpMethod.Post, registration)));
            }
            catch (Session.BadRequestException e)
            {
                switch (e.Error)
                {
                case "existing_username":
                    throw new ExistingUsernameException();

                case "existing_email":
                    throw new ExistingEmailException();

                case "malformed_email":
                    throw new InvalidEmailException();

                case "bad_password":
                    throw new BadPasswordException();

                case "short_password":
                    throw new BadPasswordException();
                }
            }
            return(null);
        }