示例#1
0
        public async Task <IActionResult> AuthorizeAPIKey([FromForm] AuthorizeApiKeysViewModel viewModel)
        {
            await SetViewModelValues(viewModel);

            AdjustVMForAuthorization(viewModel);
            var ar = HandleCommands(viewModel);

            if (ar != null)
            {
                return(ar);
            }

            for (int i = 0; i < viewModel.PermissionValues.Count; i++)
            {
                if (viewModel.PermissionValues[i].Forbidden && viewModel.Strict)
                {
                    viewModel.PermissionValues[i].Value = false;
                    ModelState.AddModelError($"{viewModel.PermissionValues}[{i}].Value",
                                             $"The permission '{viewModel.PermissionValues[i].Title}' is required for this application.");
                }

                if (viewModel.PermissionValues[i].StoreMode == AddApiKeyViewModel.ApiKeyStoreMode.Specific &&
                    !viewModel.SelectiveStores)
                {
                    viewModel.PermissionValues[i].StoreMode = AddApiKeyViewModel.ApiKeyStoreMode.AllStores;
                    ModelState.AddModelError($"{viewModel.PermissionValues}[{i}].Value",
                                             $"The permission '{viewModel.PermissionValues[i].Title}' cannot be store specific for this application.");
                }
            }

            if (!ModelState.IsValid)
            {
                return(View(viewModel));
            }

            switch (viewModel.Command.ToLowerInvariant())
            {
            case "no":
                return(RedirectToAction("APIKeys"));

            case "yes":
                var key = await CreateKey(viewModel, (viewModel.ApplicationIdentifier, viewModel.RedirectUrl?.Authority));

                if (viewModel.RedirectUrl != null)
                {
                    return(Redirect(GetRedirectToApplicationUrl(viewModel.RedirectUrl, key)));
                }

                TempData.SetStatusMessageModel(new StatusMessageModel()
                {
                    Severity = StatusMessageModel.StatusSeverity.Success,
                    Html     = $"API key generated! <code class='alert-link'>{key.Id}</code>"
                });
                return(RedirectToAction("APIKeys", new { key = key.Id }));

            default:
                return(View(viewModel));
            }
        }
        private void TestPartition(string type, CreateKey createKey, int totalKeys)
        {
            var tableName = TestUtils.TypeToTableName("simple_", type);

            _session.Execute(string.Format("CREATE TABLE IF NOT EXISTS {0}(id {1} PRIMARY KEY, data varchar)", tableName, type));
            _session.Cluster.Metadata.RefreshSchema();
            Trace.TraceInformation("Created table {0}", tableName);
            var ps = _session.Prepare(string.Format("INSERT INTO {0} (id, data) VALUES (?, ?)", tableName));

            for (int i = 0; i != totalKeys; ++i)
            {
                _session.Execute(ps.Bind(createKey(i), CreateData(i)));
            }

            ps = _session.Prepare(string.Format("SELECT data FROM {0} WHERE id = ?", tableName));

            for (int i = 0; i != totalKeys; ++i)
            {
                var rs    = _session.Execute(ps.Bind(createKey(i)));
                var count = 0;
                foreach (var row in rs)
                {
                    var data = row.GetValue <string>("data");
                    Assert.AreEqual(data, CreateData(i));
                    ++count;
                }
                Assert.AreEqual(count, 1);
            }
            _session.Execute(string.Format("DROP TABLE {0}", tableName));
        }
        void ReleaseDesignerOutlets()
        {
            if (CancelButton != null)
            {
                CancelButton.Dispose();
                CancelButton = null;
            }

            if (CreateKey != null)
            {
                CreateKey.Dispose();
                CreateKey = null;
            }

            if (FilePath != null)
            {
                FilePath.Dispose();
                FilePath = null;
            }

            if (KeyLength != null)
            {
                KeyLength.Dispose();
                KeyLength = null;
            }

            if (OkButton != null)
            {
                OkButton.Dispose();
                OkButton = null;
            }

            if (OpenFileButton != null)
            {
                OpenFileButton.Dispose();
                OpenFileButton = null;
            }

            if (PrivateKeyOptions != null)
            {
                PrivateKeyOptions.Dispose();
                PrivateKeyOptions = null;
            }

            if (PrivateKeyTextView != null)
            {
                PrivateKeyTextView.Dispose();
                PrivateKeyTextView = null;
            }
        }
        private void TestPrimitive(string type, CreateKey createKey, int totalKeys = TotalKeys)
        {
            Trace.TraceInformation("Testing {0}, keys: {1}", type, totalKeys);
            var preMetrics = _cluster.FetchMetrics();

            TestPartition(type, createKey, totalKeys);
            var postMetrics = _cluster.FetchMetrics();
            var localReads  = postMetrics.localRead - preMetrics.localRead;
            var localWrites = postMetrics.localWrite - preMetrics.localWrite;
            var oldColor    = Console.ForegroundColor;

            Trace.TraceInformation("Local reads = {0}, local writes = {1}", localReads, localWrites);
            Trace.TraceInformation("Remote reads = {0}, remote writes = {1}", postMetrics.remoteRead - preMetrics.remoteRead, postMetrics.remoteWrite - preMetrics.remoteWrite);
            Assert.Greater(localReads * 10, totalKeys * 7);
            Assert.Greater(localWrites * 10, totalKeys * 7);
        }
示例#5
0
    public void CommandListKeyWithTwoKey()
    {
        string keyName = "KeyOther";

        createRSAKey();
        CreateKey createKey = new CreateKey();

        createKey.setCommand(START_OF_COMMAND_CREATE + keyName + END_OF_COMMAND);
        Assert.AreEqual(true, createKey.verifyCommand());
        Assert.AreEqual(KEY_CREATION_MESSAGE + keyName, createKey.action());

        ListKey listKey = new ListKey();

        listKey.setCommand("RSA LIST");
        Assert.AreEqual(true, listKey.verifyCommand());
        Assert.AreEqual("\nKeys: " + "\n" + KEY_NAME + "\n" + keyName, listKey.action());
    }
示例#6
0
        public async Task <ReturnResult> AddKey([FromBody] CreateKey request)
        {
            if (int.Parse(request.SectionID) <= 0)
            {
                throw new AppException("栏目不能为空");
            }
            if (string.IsNullOrWhiteSpace(request.Name))
            {
                throw new AppException("名称不能为空");
            }

            int        iUID       = LoginManager.GetUserID();
            var        mapper     = new MapperConfiguration(x => x.CreateMap <CreateKey, KeyContent>()).CreateMapper();
            KeyContent keyContent = mapper.Map <KeyContent>(request);

            keyContent.CreateUserID = iUID;
            keyContent = await KeyManager.EncryptKey(keyContent);

            return(ReturnResult.ResultCalculation(() => KeyContentManager.Insert(keyContent)));
        }
示例#7
0
        public static void Create(string Username, string Password, string Domain, string ComputerName, object Hive, string Subkey, object Access)
        {
            try
            {
                if (CheckAccess.Check(Username, Password, Domain, ComputerName, Hive, Subkey, Access))
                {
                    CreateKey.Create(Username, Password, Domain, ComputerName, Hive, Subkey);
                }

                else
                {
                    Console.WriteLine($"[-] Error: Do not have permissions to SubKeys keys for {Subkey}");
                    Environment.Exit(1);
                }
            }

            catch (Exception e)
            {
                Console.WriteLine($"[-] Error: {e.Message}");
            }
        }
示例#8
0
        public async Task <IActionResult> AuthorizeAPIKey([FromForm] AuthorizeApiKeysViewModel viewModel)
        {
            await SetViewModelValues(viewModel);

            AdjustVMForAuthorization(viewModel);
            var ar = HandleCommands(viewModel);

            if (ar != null)
            {
                return(ar);
            }

            for (int i = 0; i < viewModel.PermissionValues.Count; i++)
            {
                if (viewModel.PermissionValues[i].Forbidden && viewModel.Strict)
                {
                    viewModel.PermissionValues[i].Value = false;
                    ModelState.AddModelError($"{viewModel.PermissionValues}[{i}].Value",
                                             $"The permission '{viewModel.PermissionValues[i].Title}' is required for this application.");
                }

                if (viewModel.PermissionValues[i].StoreMode == AddApiKeyViewModel.ApiKeyStoreMode.Specific &&
                    !viewModel.SelectiveStores)
                {
                    viewModel.PermissionValues[i].StoreMode = AddApiKeyViewModel.ApiKeyStoreMode.AllStores;
                    ModelState.AddModelError($"{viewModel.PermissionValues}[{i}].Value",
                                             $"The permission '{viewModel.PermissionValues[i].Title}' cannot be store specific for this application.");
                }
            }

            if (!ModelState.IsValid)
            {
                return(View(viewModel));
            }

            var command = viewModel.Command.ToLowerInvariant();

            switch (command)
            {
            case "cancel":
                return(RedirectToAction("APIKeys"));

            case "authorize":
            case "confirm":
                var key = command == "authorize"
                        ? await CreateKey(viewModel, (viewModel.ApplicationIdentifier, viewModel.RedirectUrl?.Authority))
                        : await _apiKeyRepository.GetKey(viewModel.ApiKey);

                if (viewModel.RedirectUrl != null)
                {
                    var permissions = key.GetBlob().Permissions;
                    var redirectVm  = new PostRedirectViewModel()
                    {
                        FormUrl    = viewModel.RedirectUrl.ToString(),
                        Parameters =
                        {
                            new KeyValuePair <string, string>("apiKey", key.Id),
                            new KeyValuePair <string, string>("userId", key.UserId)
                        }
                    };
                    foreach (var permission in permissions)
                    {
                        redirectVm.Parameters.Add(
                            new KeyValuePair <string, string>("permissions[]", permission));
                    }

                    return(View("PostRedirect", redirectVm));
                }

                TempData.SetStatusMessageModel(new StatusMessageModel()
                {
                    Severity = StatusMessageModel.StatusSeverity.Success,
                    Html     = $"API key generated! <code class='alert-link'>{key.Id}</code>"
                });

                return(RedirectToAction("APIKeys", new { key = key.Id }));

            default:
                return(View(viewModel));
            }
        }
        static DeveelDbConnectionStringBuilder()
        {
            defaults = new Dictionary <string, object>();
            defaults.Add(HostKey, DefaultHost);
            defaults.Add(PortKey, DefaultPort);
            defaults.Add(DatabaseKey, DefaultDatabase);
            defaults.Add(UserNameKey, DefaultUserName);
            defaults.Add(PasswordKey, DefaultPassword);
            defaults.Add(SchemaKey, DefaultSchema);
            defaults.Add(PathKey, DefaultPath);
            defaults.Add(CreateKey, DefaultCreate);
            defaults.Add(BootOrCreateKey, DefaultBootOrCreate);
            defaults.Add(ParameterStyleKey, DefaultParameterStyle);
            defaults.Add(VerboseColumnNamesKey, DefaultVerboseColumnName);
            defaults.Add(PersistSecurityInfoKey, DefaultPersistSecurityInfo);
            defaults.Add(RowCacheSizeKey, DefaultRowCacheSize);
            defaults.Add(MaxCacheSizeKey, DefaultMaxCacheSize);
            defaults.Add(FetchSizeKey, DefaultFetchSize);
            defaults.Add(MaxFetchSizeKey, DefaultMaxFetchSize);
            defaults.Add(AutoCommitKey, DefaultAutoCommit);
            defaults.Add(QueryTimeoutKey, DefaultQueryTimeout);

            keymaps = new Dictionary <string, string>(StringComparer.InvariantCultureIgnoreCase);
            keymaps[HostKey.ToUpper()]     = HostKey;
            keymaps["ADDRESS"]             = HostKey;
            keymaps["SERVER"]              = HostKey;
            keymaps[PortKey.ToUpper()]     = PortKey;
            keymaps[DatabaseKey.ToUpper()] = DatabaseKey;
            keymaps["CATALOG"]             = DatabaseKey;
            keymaps["INITIAL CATALOG"]     = DatabaseKey;
            keymaps["DB"] = DatabaseKey;
            keymaps[SchemaKey.ToUpper()]   = SchemaKey;
            keymaps["DEFAULT SCHEMA"]      = SchemaKey;
            keymaps[PathKey.ToUpper()]     = PathKey;
            keymaps["DATA PATH"]           = PathKey;
            keymaps["DATABASE PATH"]       = PathKey;
            keymaps["DATAPATH"]            = PathKey;
            keymaps["DATABASEPATH"]        = PathKey;
            keymaps[CreateKey.ToUpper()]   = CreateKey;
            keymaps[BootOrCreateKey]       = BootOrCreateKey;
            keymaps["BOOT OR CREATE"]      = BootOrCreateKey;
            keymaps["CREATE OR BOOT"]      = BootOrCreateKey;
            keymaps["CREATEORBOOT"]        = BootOrCreateKey;
            keymaps[CreateKey.ToUpper()]   = CreateKey;
            keymaps["CREATE DATABASE"]     = CreateKey;
            keymaps[UserNameKey.ToUpper()] = UserNameKey;
            keymaps["USER"]                             = UserNameKey;
            keymaps["USER NAME"]                        = UserNameKey;
            keymaps["USER ID"]                          = UserNameKey;
            keymaps["USERID"]                           = UserNameKey;
            keymaps["UID"]                              = UserNameKey;
            keymaps[PasswordKey.ToUpper()]              = PasswordKey;
            keymaps["PASS"]                             = PasswordKey;
            keymaps["PWD"]                              = PasswordKey;
            keymaps["SECRET"]                           = PasswordKey;
            keymaps[ParameterStyleKey.ToUpper()]        = ParameterStyleKey;
            keymaps["PARAMSTYLE"]                       = ParameterStyleKey;
            keymaps["PARAMETER STYLE"]                  = ParameterStyleKey;
            keymaps["USEPARMAMETER"]                    = ParameterStyleKey;
            keymaps["USE PARAMETER"]                    = ParameterStyleKey;
            keymaps[VerboseColumnNamesKey.ToUpper()]    = VerboseColumnNamesKey;
            keymaps["VERBOSE COLUMNS"]                  = VerboseColumnNamesKey;
            keymaps["VERBOSE COLUMN NAMES"]             = VerboseColumnNamesKey;
            keymaps["VERBOSECOLUMNS"]                   = VerboseColumnNamesKey;
            keymaps["COLUMNS VERBOSE"]                  = VerboseColumnNamesKey;
            keymaps[PersistSecurityInfoKey.ToUpper()]   = PersistSecurityInfoKey;
            keymaps["PERSIST SECURITY INFO"]            = PersistSecurityInfoKey;
            keymaps[RowCacheSizeKey.ToUpper()]          = RowCacheSizeKey;
            keymaps["ROW CACHE SIZE"]                   = RowCacheSizeKey;
            keymaps["CACHE SIZE"]                       = RowCacheSizeKey;
            keymaps[MaxCacheSizeKey.ToUpper()]          = MaxCacheSizeKey;
            keymaps["MAX CACHE SIZE"]                   = MaxCacheSizeKey;
            keymaps["MAX CACHE"]                        = MaxCacheSizeKey;
            keymaps[QueryTimeoutKey.ToUpper()]          = QueryTimeoutKey;
            keymaps["QUERY TIMEOUT"]                    = QueryTimeoutKey;
            keymaps[IgnoreIdentifiersCaseKey.ToUpper()] = IgnoreIdentifiersCaseKey;
            keymaps["IGNORE CASE"]                      = IgnoreIdentifiersCaseKey;
            keymaps["IGNORE ID CASE"]                   = IgnoreIdentifiersCaseKey;
            keymaps["ID CASE IGNORED"]                  = IgnoreIdentifiersCaseKey;
            keymaps[StrictGetValueKey.ToUpper()]        = StrictGetValueKey;
            keymaps["STRICT"]                           = StrictGetValueKey;
            keymaps["STRICT GETVALUE"]                  = StrictGetValueKey;
            keymaps["STRICT VALUE"]                     = StrictGetValueKey;
            keymaps["STRICTVALUE"]                      = StrictGetValueKey;
            keymaps[FetchSizeKey.ToUpper()]             = FetchSizeKey;
            keymaps["FETCH SIZE"]                       = FetchSizeKey;
            keymaps["ROW COUNT"]                        = FetchSizeKey;
            keymaps["ROWCOUNT"]                         = FetchSizeKey;
            keymaps[MaxFetchSizeKey.ToUpper()]          = MaxFetchSizeKey;
            keymaps["MAX FETCH SIZE"]                   = MaxFetchSizeKey;
            keymaps["MAXFETCHSIZE"]                     = MaxFetchSizeKey;
            keymaps["MAX ROW COUNT"]                    = MaxFetchSizeKey;
            keymaps["MAX ROWCOUNT"]                     = MaxFetchSizeKey;
            keymaps["MAXROWCOUNT"]                      = MaxFetchSizeKey;
            keymaps[AutoCommitKey.ToUpper()]            = AutoCommitKey;
            keymaps["AUTOCOMMIT"]                       = AutoCommitKey;
            keymaps["AUTO-COMMIT"]                      = AutoCommitKey;
            keymaps["AUTO_COMMIT"]                      = AutoCommitKey;
            keymaps["AUTO COMMIT"]                      = AutoCommitKey;
            keymaps["COMMIT AUTO"]                      = AutoCommitKey;
            keymaps["COMMIT_AUTO"]                      = AutoCommitKey;
            keymaps["COMMITAUTO"]                       = AutoCommitKey;
            keymaps["COMMIT-AUTO"]                      = AutoCommitKey;
            keymaps["COMMIT"]                           = AutoCommitKey;
            keymaps["ENLIST"]                           = EnlistKey;
        }
示例#10
0
 public async Task <IReadOnlyList <string> > QueryAsync(CreateKey key) => await _client.QueryAsync(key, _adminCode);
示例#11
0
 public async Task <LicenseKey> CreateKeyAsync(CreateKey key) => await _client.CreateAsync(key, _adminCode);