Beispiel #1
0
        protected override void ProcessRecord()
        {
            var vgw = new CreateVirtualGatewayNetworkConnection
            {
                AuthenticationMethod        = AuthenticationMethod.ToString(),
                DestinationIpAddress        = DestinationIpAddress,
                DestinationPrefix           = DestinationPrefix,
                MainModeDiffieHellmanGroup  = DiffieHellmanGroup.ToString(),
                MainModeEncryptionAlgorithm = EncryptionAlgorithm.ToString(),
                MainModeIntegrityAlgorithm  = IntegrityAlgorithm.ToString(),
                MainModeSALifeTimeKiloBytes = MainModeSALifeTimeKiloBytes,
                MainModeSALifeTimeSeconds   = MainModeSALifeTimeSeconds,
                QuickModeAuthenticationTransformationConstant = AuthenticationTranformationConstant.ToString(),
                QuickModeCipherTransformationConstant         = CipherTransformationConstant.ToString(),
                QuickModeIdleDisconnectSeconds = QuickModeIdleDisconnectSeconds,
                QuickModePerfectForwardSecrecy = PerfectForwardSecrecy.ToString(),
                QuickModeSALifeTimeKiloBytes   = QuickModeSALifeTimeKiloBytes,
                QuickModeSALifeTimeSeconds     = QuickModeSALifeTimeSeconds,
                Name         = Name,
                SharedSecret = SharedSecret
            };

            var job = Create(Connection, vgw, VirtualGatewayId);


            if (Wait)
            {
                WriteObject(WaitJobFinished(job.Id, Connection, VirtualGatewayId));
            }
            else
            {
                WriteObject(job);
            }
        }
Beispiel #2
0
        /// <summary>
        /// Authenticate to authenticate a client with a given method.
        /// </summary>
        /// <param name="method">Authentication method to use.</param>
        /// <param name="data">Data provided by the client for authentication.</param>
        /// <returns>Returns whether authentication was successful.</returns>
        public bool TryAuthenticate(AuthenticationMethod method, string data, out string serializedToken)
        {
            serializedToken = null;
            if (Providers.TryGetValue(method, out IAuthenticationProvider provider))
            {
                if (provider.TryAuthenticate(data, out string subject, out IEnumerable <Role> roles, out IEnumerable <Right> rights))
                {
                    List <Claim> claims = new List <Claim>
                    {
                        // Add subject
                        new Claim(JwtRegisteredClaimNames.Sub, subject)
                    };

                    // Add role claims
                    foreach (Role role in roles)
                    {
                        claims.Add(new Claim("role", ((int)role).ToString(), ClaimValueTypes.Integer32));
                    }

                    // Add right claims
                    foreach (Right right in rights)
                    {
                        claims.Add(new Claim("rights", right.Id));
                    }

                    // Generate token
                    JwtSecurityToken token = new JwtSecurityToken(JwtIssuer, null, claims, expires: DateTime.Now.Add(JwtLifetime), signingCredentials: SigningCredentials);
                    serializedToken = new JwtSecurityTokenHandler().WriteToken(token);
                    return(true);
                }
                return(false);
            }
            else
            {
                throw new Exception($"Missing authentication provider for authentication method '{method.ToString()}'.");
            }
        }
Beispiel #3
0
        private void UpdateComponents()
        {
            ClearFields();
            loseFocus();

            btnAddNewUser.Enabled         = _globalState != State.UserManagement_AddUser;
            btnRemoveUserOrCancel.Enabled = true;
            listUsers.Enabled             = _globalState == State.UserManagement;
            //btnClose.Enabled = _globalState != State.UserManagement_AddUser;

            // Multiple States
            acceptMagStripeInput = checkIfMagStripeNeeded();

            // Refresh and Update Bluetooth Lists
            RefreshBTDeviceLists(null, EventArgs.Empty);


            switch (_globalState)
            {
            case State.UserManagement:

                _selectedUser = (User)listUsers.SelectedItem;

                txtStatus.Text                 = $"Hi {_currentUser.Name}. Click on a user for details and actions.";
                btnRemoveUserOrCancel.Text     = "Remove user";
                tbxUserName.Text               = _selectedUser.Name;
                tbxUserPhone.Text              = _selectedUser.PhoneNumber;
                cbxUserPermission.SelectedItem = _selectedUser.PermissionLevel.ToString();

                AuthenticationMethod primary   = _selectedUser.AuthenticationMethods.Primary;
                AuthenticationMethod secondary = _selectedUser.AuthenticationMethods.Secondary;
                cbxPrimAuth.SelectedItem = primary.ToString();
                cbxSecAuth.SelectedItem  = secondary.ToString();
                switch (primary)
                {
                case Card card:
                    cbxPrimAuth.SelectedIndex = 0;
                    tbxCard.Text = card.Id;
                    break;

                case BluetoothDevice btDevice:
                    cbxPrimAuth.SelectedIndex = 1;
                    if (!cbxBTSelect1.Items.Contains(btDevice))
                    {
                        cbxBTSelect1.Items.Insert(0, btDevice);
                        cbxBTSelect1.SelectedIndex = 0;
                        cbxBTSelect2.Items.Insert(0, btDevice);
                        cbxBTSelect2.SelectedIndex = 0;
                    }
                    break;
                }
                ModifyPrimaryAuthConfiguration(cbxPrimAuth, EventArgs.Empty);

                switch (secondary)
                {
                case BluetoothDevice btDevice:
                    cbxSecAuth.SelectedIndex = 0;
                    if (!cbxBTSelect2.Items.Contains(btDevice))
                    {
                        cbxBTSelect1.Items.Insert(0, btDevice);
                        cbxBTSelect1.SelectedIndex = 0;
                        cbxBTSelect2.Items.Insert(0, btDevice);
                        cbxBTSelect2.SelectedIndex = 0;
                    }
                    break;

                case Pin pin:
                    cbxSecAuth.SelectedIndex = 1;
                    tbxPin.Text = pin.PinValue;
                    break;
                }
                ModifySecondaryAuthConfiguration(cbxSecAuth, EventArgs.Empty);
                break;

            case State.UserManagement_AddUser:
                txtStatus.Text             = "Creating a new user:"******"Cancel";
                ClearFields();
                ClearComboBoxes();
                UserInputValidation();
                break;

            default:
                break;
            }
        }
Beispiel #4
0
 public void TrackSignUpEvent(AuthenticationMethod authenticationMethod)
 {
     track(signupEventName, authenticationMethodParameter, authenticationMethod.ToString());
 }
Beispiel #5
0
 public void TrackLoginEvent(AuthenticationMethod authenticationMethod)
 {
     track(loginEventName, authenticationMethodParameter, authenticationMethod.ToString());
 }