/// <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);
        }
예제 #2
0
        public void EnableSecurity(IServerUserRepository repository,
                                   int tokenLifetime = 3, string tokenCryptPassword = "")
        {
            TokenCryptPassword = tokenCryptPassword;
            UserRepository     = repository;
            TokenLifeTime      = tokenLifetime;

            RegisterController("AuthorizationController", typeof(AuthorizationController));

            List <IHandlerInterceptor> list = new List <IHandlerInterceptor>();

            if (Interceptors.Count > 0)
            {
                Interceptors.ForEach(i => list.Add(i));
                Interceptors.Clear();
            }

            RegisterInterceptor(new SecurityTokenInterceptor());
            RegisterInterceptor(new UserRoleValidationInterceptor());

            if (list.Count > 0)
            {
                list.ForEach(i => RegisterInterceptor(i));
            }
        }
예제 #3
0
 public BasicSecurityDefinitions(IServerUserRepository repository,
                                 int tokenLifetime,
                                 string tokenCryptPassword)
 {
     Repository              = repository;
     this.TokenLifeTime      = tokenLifetime;
     this.TokenCryptPassword = tokenCryptPassword;
 }
예제 #4
0
 public UserDataService(IServerRepository serverRepository, IUserRepository userRepository,
                        IServerUserRepository serverUserRepository, IBotRoleRepository botRoleRepository,
                        IOptions <DiscordConfiguration> config)
 {
     _serverRepository     = serverRepository;
     _userRepository       = userRepository;
     _serverUserRepository = serverUserRepository;
     _botRoleRepository    = botRoleRepository;
     _config = config.Value;
 }
예제 #5
0
        public void EnableSecurity(IServerUserRepository userRepository, int tokenLifetime = 3, string tokenCryptPassword = "")
        {
            if (coreServer.IsLoadBalanceEnabled())
            {
                throw new InvalidOperationException("Authentication features cannot be enabled on a load balancing server");
            }

            if (securityEnabled)
            {
                throw new Exception("Aready enabled.");
            }

            controllerManager.RegisterController(typeof(AuthorizationController));
            interceptorManager.AddInterceptor(new SecurityTokenInterceptor());
            interceptorManager.AddInterceptor(new UserRoleValidationInterceptor());

            definitions = new BasicSecurityDefinitions(userRepository,
                                                       tokenLifetime,
                                                       tokenCryptPassword);

            securityEnabled = true;
        }
예제 #6
0
 public ServerUserServices(IServerUserRepository dal)
 {
     base._baseDal = dal;
     this._dal     = dal;
 }