Example #1
0
        public ControllerService(ControllerSession cs)
        {
            Controller = cs;

            ClockOps    = new ClockOperations(Controller);
            IdentityOps = new IdentityOperations(Controller);
        }
Example #2
0
        /// <summary>
        /// Configure data environment
        /// </summary>
        /// <param name="services">The services collection</param>
        /// <param name="configuration">The configuration instance</param>
        public static IServiceCollection AddRepositories(this IServiceCollection services, IConfiguration configuration)
        {
            // get settings from configuration
            var dataSettings = configuration.BindAs <DataSourceSettings>("DataSource");

            // register settings for future use
            services.AddSingleton(dataSettings);

            // get the SQL sources
            var sources = IdentityOperations.GetSources().Union(DataProtectionOperations.GetSources());

            // build and init new data operations instance
            var dataOps = OperationsInitializer.Init(dataSettings, sources.ToArray());

            // add data operations
            services.AddSingleton(dataOps);

            // add domain repositories
            services.AddSingleton <IAccessGrantRepository, AccessGrantRepository>();
            services.AddSingleton <IConfirmationCodeRepository, ConfirmationCodeRepository>();
            services.AddSingleton <IUserRepository, UserRepository>();
            services.AddSingleton <IProtectionKeyRepository, ProtectionKeyRepository>();

            // chain services
            return(services);
        }
Example #3
0
        public Task Authentication_Validate_Disabled_CSrv()
        {
            return(Test(async() =>
            {
                var services = new ServiceCollection();

                services.Configure <RegistrationOptions>(options => { })
                .AddLogging()
                .AddSenseNetRegistration();

                var provider = services.BuildServiceProvider();
                var context = new DefaultHttpContext {
                    RequestServices = provider
                };
                var root = Content.Create(Repository.Root);
                const string userName = "******";

                var user = await IdentityOperations.CreateLocalUser(root, context, userName, userName, userName + "@example.com");

                // check if the user can log in
                dynamic result = IdentityOperations.ValidateCredentials(root, context, "public\\" + userName, userName);
                Assert.AreEqual(user.Id, result.id);

                // ACTION: disable the user
                user["Enabled"] = false;
                user.SaveSameVersion();

                var thrown = false;
                try
                {
                    // important to look for the user in the appropriate domain
                    IdentityOperations.ValidateCredentials(root, context, "public\\" + userName, userName);
                }
                catch (SenseNetSecurityException)
                {
                    thrown = true;
                }

                Assert.IsTrue(thrown, "Security exception was not thrown, a disabled user could log in.");
            }));
        }
Example #4
0
 public LoginController()
 {
     _idOps = new IdentityOperations();
 }