internal static bool AddUserToDatabase(string identity, dynamic documentStore)
        {
            var database = documentStore.DefaultDatabase ?? "<system>";

            var credentials = documentStore.Credentials as NetworkCredential;
            if (credentials != null && !string.IsNullOrWhiteSpace(credentials.UserName) && !string.IsNullOrWhiteSpace(credentials.Password))
            {
                logger.InfoFormat("Skipping adding user '{0}' to RavenDB, because credentials were provided via connection string", identity);
                return false;
            }

            logger.Info(string.Format("Adding user '{0}' to raven. Instance:'{1}', Database:'{2}'.", identity, documentStore.Url, database));

            var systemCommands = documentStore
                .DatabaseCommands
                .ForSystemDatabase();
            JsonDocument existing = systemCommands.Get("Raven/Authorization/WindowsSettings");

            WindowsAuthDocument windowsAuthDocument;
            if (existing == null)
            {
                windowsAuthDocument = new WindowsAuthDocument();
            }
            else
            {
                windowsAuthDocument = existing
                    .DataAsJson
                    .JsonDeserialization<WindowsAuthDocument>();
            }
            AddOrUpdateAuthUser(windowsAuthDocument, identity, database);

            var ravenJObject = RavenJObject.FromObject(windowsAuthDocument);

            return InvokePut(systemCommands, ravenJObject);
        }
예제 #2
0
        internal static void AddUserToDatabase(string identity, DocumentStore documentStore)
        {
            var database = documentStore.DefaultDatabase ?? "<system>";

            logger.InfoFormat(string.Format("Adding user '{0}' to raven. Instance:'{1}', Database:'{2}'.", identity, documentStore.Url, database));

            var systemCommands = documentStore
                                 .DatabaseCommands
                                 .ForSystemDatabase();
            var existing = systemCommands.Get("Raven/Authorization/WindowsSettings");

            WindowsAuthDocument windowsAuthDocument;

            if (existing == null)
            {
                windowsAuthDocument = new WindowsAuthDocument();
            }
            else
            {
                windowsAuthDocument = existing
                                      .DataAsJson
                                      .JsonDeserialization <WindowsAuthDocument>();
            }
            AddOrUpdateAuthUser(windowsAuthDocument, identity, database);

            var ravenJObject = RavenJObject.FromObject(windowsAuthDocument);

            systemCommands.Put("Raven/Authorization/WindowsSettings", null, ravenJObject, new RavenJObject());
        }
        public static void AddUserToDatabase(IDocumentStore documentStore, string username)
        {
            var systemCommands = documentStore
                                 .DatabaseCommands
                                 .ForSystemDatabase();
            WindowsAuthDocument windowsAuthDocument = GetWindowsAuthDocument(systemCommands);

            AddOrUpdateAuthUser(windowsAuthDocument, username, "<system>");

            var ravenJObject = RavenJObject.FromObject(windowsAuthDocument);

            systemCommands.Put("Raven/Authorization/WindowsSettings", null, ravenJObject, new RavenJObject());
        }
예제 #4
0
        static void AddOrUpdateAuthUser(WindowsAuthDocument windowsAuthDocument, string identity, string tenantId)
        {
            var windowsAuthForUser = windowsAuthDocument
                .RequiredUsers
                .FirstOrDefault(x => x.Name == identity);
            if (windowsAuthForUser == null)
            {
                windowsAuthForUser = new WindowsAuthData
                {
                    Name = identity
                };
                windowsAuthDocument.RequiredUsers.Add(windowsAuthForUser);
            }
            windowsAuthForUser.Enabled = true;

            AddOrUpdateDataAccess(windowsAuthForUser, tenantId);
        }
        static void AddOrUpdateAuthUser(WindowsAuthDocument windowsAuthDocument, string identity, string tenantId)
        {
            var windowsAuthForUser = windowsAuthDocument
                                     .RequiredUsers
                                     .FirstOrDefault(x => x.Name == identity);

            if (windowsAuthForUser == null)
            {
                windowsAuthForUser = new WindowsAuthData
                {
                    Name = identity
                };
                windowsAuthDocument.RequiredUsers.Add(windowsAuthForUser);
            }
            windowsAuthForUser.Enabled = true;

            AddOrUpdateDataAccess(windowsAuthForUser, tenantId);
        }