コード例 #1
0
        protected override Schema.User ValidateLogin(int sessionID, SessionInfo sessionInfo)
        {
            if (sessionInfo == null)
            {
                throw new ServerException(ServerException.Codes.SessionInformationRequired);
            }

            if (String.Equals(sessionInfo.UserID, SystemUserID, StringComparison.OrdinalIgnoreCase))
            {
                if (!IsEngine && (sessionID != SystemSessionID))
                {
                    throw new ServerException(ServerException.Codes.CannotLoginAsSystemUser);
                }

                return(_systemUser);
            }
            else
            {
                Schema.User user = ((ServerCatalogDeviceSession)_systemProcess.CatalogDeviceSession).ResolveUser(sessionInfo.UserID);
                if (String.Compare(Schema.SecurityUtility.DecryptPassword(user.Password), sessionInfo.Password, true) != 0)
                {
                    throw new ServerException(ServerException.Codes.InvalidPassword);
                }

                return(user);
            }
        }
コード例 #2
0
ファイル: Plan.cs プロジェクト: laszlo-kiss/Dataphor
 public void UpdateSecurityContexts(Schema.User user)
 {
     for (int index = 0; index < _securityContexts.Count; index++)
     {
         if (_securityContexts[index].User.ID == user.ID)
         {
             _securityContexts[index].SetUser(user);
         }
     }
 }
コード例 #3
0
ファイル: Engine.cs プロジェクト: cybernetics/Dataphor
        protected bool _firstRun;         // Indicates whether or not this is the first time this server has run on the configured store

        /*
         *      Catalog Startup ->
         *              Catalog startup occurs in 5 phases
         *                      Bootstrap ->
         *                              Creates the SystemUser and CatalogDevice, then connects the SystemSession and opens a device session with the catalog device
         *                      Core ->
         *                              Creates the core catalog objects required to compile D4 statements. These objects are programmatically created by the
         *                              server and include the Admin user, User role, Temp device, ApplicationTransaction device and the Server-level rights.
         *                      Base ->
         *                              These are the basic objects required to facilitate caching and D4 compilation. These objects are created by running
         *                              the DataTypes.d4 script, and include the majority of the system data types. All the objects created up to this phase
         *                              constitute the base objects that will always be present in any given instance of a Dataphor Server, and are used as
         *                              the default set of cached objects.
         *                      System ->
         *                              The system objects are all the remaining objects in the System library, and are created by running the SystemCatalog.d4
         *                              script. These objects are only created on a first-time run for a given catalog store.
         *                      Load ->
         *                              The load phase finishes preparing the server to compile and run D4 statements by restoring server state.
         */
        private void InitializeCatalog()
        {
            LogMessage("Initializing Catalog...");

            // Create the Catalog device
            // Note that this must be the first object created to avoid the ID being different on subsequent loads
            Schema.Object.SetNextObjectID(0);
            _catalogDevice = CreateCatalogDevice();

            // Create the system user
            _systemUser = new Schema.User(SystemUserID, "System User", String.Empty);

            // Create the system library
            _systemLibrary       = new Schema.LoadedLibrary(SystemLibraryName);
            _systemLibrary.Owner = _systemUser;
            LoadSystemAssemblies();
            _catalog.LoadedLibraries.Add(_systemLibrary);

            // Load available libraries
            LoadAvailableLibraries();

            // Connect the System Session
            if (_systemSession != null)
            {
                _systemSession.Dispose();
                _systemProcess = null;
            }
            _systemSession = (ServerSession)InternalConnect(SystemSessionID, new SessionInfo(_systemUser.ID, _systemUser.Password, SystemLibraryName));
            _systemSession.SessionInfo.UsePlanCache = false;
            _systemProcess = (ServerProcess)((IServerSession)_systemSession).StartProcess(new ProcessInfo(_systemSession.SessionInfo));
            _systemProcess.SuppressWarnings = true;

            // Register the Catalog device
            _catalogDevice.Owner           = _systemUser;
            _catalogDevice.Library         = _systemLibrary;
            _catalogDevice.ClassDefinition = new ClassDefinition("System.CatalogDevice");
            _catalogDevice.Start(_systemProcess);
            _catalogDevice.Register(_systemProcess);

            _firstRun = DetermineFirstRun();

            // If this is a repository or there are no objects in the catalog, register, else resolve
            InternalInitializeCatalog();

            // Bind the native type references to the system data types
            BindNativeTypes();

            LogMessage("Catalog Initialized.");
        }
コード例 #4
0
 internal ServerSession
 (
     Engine server,
     int sessionID,
     SessionInfo sessionInfo,
     Schema.User user
 ) : base()
 {
     _server           = server;
     _sessionID        = sessionID;
     _sessionInfo      = sessionInfo;
     _sessionObjects   = new Schema.Objects();
     _sessionOperators = new Schema.Objects();
     _user             = user;
     _processes        = new ServerProcesses();
 }
コード例 #5
0
ファイル: Engine.cs プロジェクト: cybernetics/Dataphor
        protected virtual void InternalRegisterCoreSystemObjects()
        {
            // Create the Admin user
            _adminUser = new Schema.User(AdminUserID, "Administrator", String.Empty);

            // Register the System and Admin users
            _systemProcess.CatalogDeviceSession.InsertUser(_systemUser);
            _systemProcess.CatalogDeviceSession.InsertUser(_adminUser);

            _userRole         = new Schema.Role(UserRoleName);
            _userRole.Owner   = _systemUser;
            _userRole.Library = _systemLibrary;
            _systemProcess.CatalogDeviceSession.InsertRole(_userRole);

            // Register the Catalog device
            _systemProcess.CatalogDeviceSession.InsertCatalogObject(_catalogDevice);

            // Create the Temp Device
            _tempDevice                 = new MemoryDevice(Schema.Object.GetNextObjectID(), TempDeviceName);
            _tempDevice.Owner           = _systemUser;
            _tempDevice.Library         = _systemLibrary;
            _tempDevice.ClassDefinition = new ClassDefinition("System.MemoryDevice");
            _tempDevice.ClassDefinition.Attributes.Add(new ClassAttributeDefinition("MaxRowCount", TempDeviceMaxRowCount.ToString()));
            _tempDevice.MaxRowCount = TempDeviceMaxRowCount;
            _tempDevice.Start(_systemProcess);
            _tempDevice.Register(_systemProcess);
            _systemProcess.CatalogDeviceSession.InsertCatalogObject(_tempDevice);

            // Create the A/T Device
            _aTDevice                 = new ApplicationTransactionDevice(Schema.Object.GetNextObjectID(), ATDeviceName);
            _aTDevice.Owner           = _systemUser;
            _aTDevice.Library         = _systemLibrary;
            _aTDevice.ClassDefinition = new ClassDefinition("System.ApplicationTransactionDevice");
            _aTDevice.ClassDefinition.Attributes.Add(new ClassAttributeDefinition("MaxRowCount", ATDeviceMaxRowCount.ToString()));
            _aTDevice.MaxRowCount = ATDeviceMaxRowCount;
            _aTDevice.Start(_systemProcess);
            _aTDevice.Register(_systemProcess);
            _systemProcess.CatalogDeviceSession.InsertCatalogObject(_aTDevice);
        }
コード例 #6
0
ファイル: Engine.cs プロジェクト: cybernetics/Dataphor
        private ServerSession InternalConnect(int sessionID, SessionInfo sessionInfo)
        {
            Schema.User   user    = ValidateLogin(sessionID, sessionInfo);
            ServerSession session = new ServerSession(this, sessionID, sessionInfo, user);

            try
            {
                Schema.LoadedLibrary currentLibrary = null;
                if (sessionInfo.DefaultLibraryName != String.Empty)
                {
                    if (_systemProcess == null)
                    {
                        currentLibrary = _catalog.LoadedLibraries[sessionInfo.DefaultLibraryName];
                    }
                    else
                    {
                        currentLibrary = _systemProcess.CatalogDeviceSession.ResolveLoadedLibrary(sessionInfo.DefaultLibraryName, false);
                    }
                }

                if (currentLibrary == null)
                {
                    currentLibrary = _catalog.LoadedLibraries[GeneralLibraryName];
                }

                session.CurrentLibrary = currentLibrary;

                _sessions.Add(session);
                return(session);
            }
            catch
            {
                session.Dispose();
                throw;
            }
        }
コード例 #7
0
 internal void SetUser(Schema.User user)
 {
     _user = user;
 }
コード例 #8
0
 public SecurityContext(Schema.User user) : base()
 {
     _user = user;
 }
コード例 #9
0
        private string SaveSecurity(ServerProcess process)
        {
            StringBuilder  result       = new StringBuilder();
            IServerProcess localProcess = (IServerProcess)process;
            IServerCursor  cursor;

            // Users
            result.Append("// Users\r\n");

            cursor = localProcess.OpenCursor("select Users { ID }", null);
            try
            {
                using (IRow row = cursor.Plan.RequestRow())
                {
                    while (cursor.Next())
                    {
                        cursor.Select(row);
                        switch ((string)row[0 /*"ID"*/])
                        {
                        case Engine.SystemUserID: break;

                        case Engine.AdminUserID:
                            if (_adminUser.Password != String.Empty)
                            {
                                result.AppendFormat("SetEncryptedPassword('{0}', '{1}');\r\n", _adminUser.ID, _adminUser.Password);
                            }
                            break;

                        default:
                            Schema.User user = process.CatalogDeviceSession.ResolveUser((string)row[0 /*"ID"*/]);
                            result.AppendFormat("CreateUserWithEncryptedPassword('{0}', '{1}', '{2}');\r\n", user.ID, user.Name, user.Password);
                            break;
                        }
                    }
                }
            }
            finally
            {
                localProcess.CloseCursor(cursor);
            }

            result.Append("\r\n");
            result.Append("// Device Users\r\n");

            // DeviceUsers
            cursor = localProcess.OpenCursor("select DeviceUsers join (Devices { ID Device_ID, Name Device_Name }) { User_ID, Device_ID }", null);
            try
            {
                using (IRow row = cursor.Plan.RequestRow())
                {
                    while (cursor.Next())
                    {
                        cursor.Select(row);
                        Schema.User       user       = process.CatalogDeviceSession.ResolveUser((string)row[0 /*"User_ID"*/]);
                        Schema.Device     device     = (Schema.Device)process.CatalogDeviceSession.ResolveCatalogObject((int)row[1 /*"Device_ID"*/]);
                        Schema.DeviceUser deviceUser = process.CatalogDeviceSession.ResolveDeviceUser(device, user);
                        result.AppendFormat("CreateDeviceUserWithEncryptedPassword('{0}', '{1}', '{2}', '{3}', '{4}');\r\n", deviceUser.User.ID, deviceUser.Device.Name, deviceUser.DeviceUserID, deviceUser.DevicePassword, deviceUser.ConnectionParameters);
                    }
                }
            }
            finally
            {
                localProcess.CloseCursor(cursor);
            }

            result.Append("\r\n");
            result.Append("// User Roles\r\n");

            // UserRoles
            cursor = localProcess.OpenCursor("select UserRoles where Role_Name <> 'System.User'", null);
            try
            {
                using (IRow row = cursor.Plan.RequestRow())
                {
                    while (cursor.Next())
                    {
                        cursor.Select(row);

                        result.AppendFormat("AddUserToRole('{0}', '{1}');\r\n", (string)row[0 /*"User_ID"*/], (string)row[1 /*"Role_Name"*/]);
                    }
                }
            }
            finally
            {
                localProcess.CloseCursor(cursor);
            }

            result.Append("\r\n");
            result.Append("// User Right Assignments\r\n");

            // UserRightAssignments
            cursor = localProcess.OpenCursor("select UserRightAssignments", null);
            try
            {
                using (IRow row = cursor.Plan.RequestRow())
                {
                    while (cursor.Next())
                    {
                        cursor.Select(row);

                        if ((bool)row[2 /*"IsGranted"*/])
                        {
                            result.AppendFormat("GrantRightToUser('{0}', '{1}');\r\n", (string)row[1 /*"Right_Name"*/], (string)row[0 /*"User_ID"*/]);
                        }
                        else
                        {
                            result.AppendFormat("RevokeRightFromUser('{0}', '{1}');\r\n", (string)row[1 /*"Right_Name"*/], (string)row[0 /*"User_ID"*/]);
                        }
                    }
                }
            }
            finally
            {
                localProcess.CloseCursor(cursor);
            }

            result.Append("\r\n");
            return(result.ToString());
        }
コード例 #10
0
 public void SetUser(Schema.User user)
 {
     _user = user;
 }
コード例 #11
0
 public LoadingContext(Schema.User user, string libraryName, bool isLoadingContext)
 {
     _user             = user;
     _libraryName      = libraryName;
     _isLoadingContext = isLoadingContext;
 }
コード例 #12
0
 public LoadingContext(Schema.User user, bool isInternalContext)
 {
     _user              = user;
     _libraryName       = String.Empty;
     _isInternalContext = isInternalContext;
 }
コード例 #13
0
 public LoadingContext(Schema.User user, string libraryName) : base()
 {
     _user        = user;
     _libraryName = libraryName;
 }