Example #1
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;
        }
        /// <summary>
        /// Adds a request interceptor for a specific server controller/action
        /// </summary>
        /// <param name="interceptor">Implementation of Interceptor</param>
        protected void AddInterceptor(IHandlerInterceptor interceptor)
        {
            IInterceptorManagerService manager = Services.GetService <IInterceptorManagerService>();

            manager.AddInterceptor(interceptor);
        }