/// <summary>
        /// Enables authentication features on the current server
        /// </summary>
        /// <param name="repository">Implementation of a ServerUser repository for authentication</param>
        /// <param name="tokenLifetime">Authentication Token lifetime (in minutes)</param>
        /// <param name="tokenCryptPassword">(Optional) A password used to encrypt the data that will make up the authentication Token. If it is an empty string, the authentication service will take care of generating dynamic passwords for each connected client. For the password generation process, see Wiki section on GitHub project</param>
        protected void UseAuthentication(IServerUserRepository repository,
                                         int tokenLifetime = 3, string tokenCryptPassword = "")
        {
            ISecurityManagementService service = Services.GetService <ISecurityManagementService>();

            service.EnableSecurity(repository, tokenLifetime, tokenCryptPassword);
        }
Esempio n. 2
0
        private void Fill(ServerUser user)
        {
            IServiceManager manager = ServiceManager.GetInstance();

            securityManagementService = manager.GetService <ISecurityManagementService>();

            userActivities = new List <UserActivity>();
            User           = user;
            SessionId      = Guid.NewGuid();
            CreatedAt      = DateTime.Now;
            ExpireAt       = CreatedAt.AddMinutes(securityManagementService.GetDefinitions().TokenLifeTime);
        }
        private void Initialize()
        {
            serviceManager  = ServiceManager.GetInstance();
            loggingService  = serviceManager.GetService <ILoggingService>();
            encodingService = serviceManager.GetService <IEncodingConverterService>();
            security        = serviceManager.GetService <ISecurityManagementService>();

            serverSocket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);

            IControllerManager manager = serviceManager.GetService <IControllerManager>();

            manager.RegisterController(typeof(ServerInfoController));

            if (telemetryServicesDisabled)
            {
                string alert = "WARNING!: Disabling telemetry services can bring some extra performance to the server (even if perhaps imperceptible). However it will not be possible to collect metrics to implement improvements in your code";
                Console.ForegroundColor = ConsoleColor.Yellow;
                Console.WriteLine(alert);
                Console.ForegroundColor = ConsoleColor.White;

                serviceManager.Unbind <ITelemetryManagement>();
                loggingService.WriteLog(alert, ServerLogType.ALERT);
            }
            else
            {
                ITelemetryManagement telemetry = serviceManager.GetService <ITelemetryManagement>();
                telemetry.Initialize();
            }

            IEFIManager efiManager = serviceManager.GetService <IEFIManager>();

            efiManager.LoadAll();

            if (_basicProcessorType != null)
            {
                EnableBasicServerProcessorModeInternal();
            }

            try
            {
                Console.WriteLine("Socket App Server - version " + new ServerInfo().ServerVersion);
            }
            catch { }

            Console.WriteLine($"Server started with {configuration.BufferSize} bytes for buffer size \n");
            Console.WriteLine($"Server Encoding: '{configuration.ServerEncoding.EncodingName}'");
            if (configuration.MaxThreadsCount > 0)
            {
                Console.WriteLine($"Server max threads count: " + configuration.MaxThreadsCount);
            }
        }
Esempio n. 4
0
        public ServerInfo()
        {
            IServiceManager            manager            = ServiceManager.GetInstance();
            ISecurityManagementService securityManagement = manager.GetService <ISecurityManagementService>();
            ICoreServerService         coreServer         = manager.GetService <ICoreServerService>("realserver");

            Assembly        assembly = Assembly.GetExecutingAssembly();
            FileVersionInfo fvi      = FileVersionInfo.GetVersionInfo(assembly.Location);
            string          version  = fvi.FileVersion;

            if (coreServer.IsLoadBalanceEnabled())
            {
                IsLoadBanancingServer = true;
            }

            RequiresAuthentication = securityManagement.IsAuthenticationEnabled();
            ServerVersion          = version;
            ServerControllers      = new List <ControllerInfo>();
            MachineName            = Environment.MachineName;
        }
Esempio n. 5
0
        public ActionResult Authorize(string user, string password,
                                      SocketRequest request)
        {
            IServiceManager            manager = ServiceManager.GetInstance();
            ISecurityManagementService service = manager.GetService <ISecurityManagementService>();

            var serverUser = service.Authenticate(user, password);

            if (serverUser == null)
            {
                return(ActionResult.Json(new OperationResult(string.Empty, 500, "Invalid user"), 500, "Invalid user"));
            }
            var token = TokenRepository.Instance.AddToken(serverUser, ref request);

            try
            {
                service.OnSuccessFulAuthentication(token.UserToken);
            }
            catch { }

            return(ActionResult.Json(new OperationResult(token.UserToken, 600, "Authorization success. Use this token to authenticate in next requests.")));
        }