예제 #1
0
 public VoterController(ESDB ctxt, IWebHostEnvironment env, PersistentCommissionManager manager, IDataProtectionProvider provider, IConfiguration configuration)
 {
     _context            = ctxt;
     contentRootPath     = env.ContentRootPath;
     _manager            = manager;
     _manager.Expiration = TimeSpan.FromMinutes(3); // Should be added to configuration
     dataprotection      = provider;
     Configuration       = configuration;
 }
예제 #2
0
        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            services.AddSingleton <PersistentCommissionManager>();

            services.AddLocalization(options => options.ResourcesPath = "Resources");

            services.AddMvc()
            .AddViewLocalization(LanguageViewLocationExpanderFormat.Suffix)
            .AddDataAnnotationsLocalization();

            services.AddAuthentication(OpenIdConnectDefaults.AuthenticationScheme)
            .AddMicrosoftIdentityWebApp(Configuration.GetSection("AzureAd"));
            //.AddAzureAD(options => Configuration.Bind("AzureAd", options));

            services.AddDbContext <ESDB>(o => {
                o.UseSqlServer(Configuration.GetConnectionString("ESDB"));
            });

            services.Configure <OpenIdConnectOptions>(OpenIdConnectDefaults.AuthenticationScheme, opt =>
            {
                var onTokenValidated        = opt.Events.OnTokenValidated;
                opt.Events.OnTokenValidated = (
                    async ctxt =>
                {
                    var opt = new DbContextOptionsBuilder <ESDB>();

                    using (var esdb = new ESDB(opt.UseSqlServer(Configuration.GetConnectionString("ESDB")).Options))
                    {
                        onTokenValidated?.Invoke(ctxt);
                        var roles = await EligereRoles.ComputeRoles(esdb, "AzureAD", ctxt.Principal.Identity.Name);
                        var claims = new List <Claim>();
                        roles.ForEach(r => claims.Add(new Claim(ClaimTypes.Role, r)));
                        var appIdentity = new ClaimsIdentity(claims, "EligereIdentity");
                        ctxt.Principal.AddIdentity(appIdentity);
                    }
                });
            });

            services.AddDataProtection()
            .SetApplicationName("Eligere")
            .PersistKeysToFileSystem(new DirectoryInfo(evsKeyPath));

            services.AddControllersWithViews(options =>
            {
                var policy = new AuthorizationPolicyBuilder()
                             .RequireAuthenticatedUser()
                             .Build();
                options.Filters.Add(new AuthorizeFilter(policy));
            });
            services.AddRazorPages()
            .AddMicrosoftIdentityUI();
            IdentityModelEventSource.ShowPII = true;
        }
예제 #3
0
        internal async static Task <bool> InconsistentRoles(ClaimsPrincipal user, ESDB esdb, string provider, string username)
        {
            var roles = await ComputeRoles(esdb, provider, username);

            foreach (var r in roles)
            {
                if (!user.IsInRole(r))
                {
                    return(true);
                }
            }
            return(false);
        }
예제 #4
0
        internal async static Task <List <string> > ComputeRoles(ESDB esdb, string provider, string username)
        {
            var roles = new List <string>();

            roles.Add(AuthenticatedUser);

            var u = from l in esdb.UserLogin where provider == l.Provider && username == l.UserId select l;

            if (await u.CountAsync() == 1) // Should be either 0 or 1
            {
                roles.Add(AuthenticatedPerson);
                var user = u.First();
                var q    = from s in esdb.ElectionStaff
                           join r in esdb.ElectionRole on s.ElectionRoleFk equals r.Id
                           where s.PersonFk == user.PersonFk
                           select r.Label;

                await q.ForEachAsync(r => roles.Add(r)); // Assumption: the role in the DB table match constants in this class

                var elections   = from e in esdb.Election where e.PollEndDate > DateTime.Today select e;
                var isCandidate = await(from e in elections join bn in esdb.BallotName on e.Id equals bn.ElectionFk join c in esdb.EligibleCandidate on bn.Id equals c.BallotNameFk where c.PersonFk == user.PersonFk select c).AnyAsync();
                var isVoter     = await(from e in elections join v in esdb.Voter on e.Id equals v.ElectionFk where v.PersonFk == user.PersonFk select v).AnyAsync();
                var isRemoteIdentificationOfficer = await(from e in elections join psc in esdb.PollingStationCommission on e.Id equals psc.ElectionFk join ro in esdb.RemoteIdentificationCommissioner on psc.Id equals ro.PollingStationCommissionFk where ro.PersonFk == user.PersonFk select ro).AnyAsync();
                var isPresident = await(from e in elections join c in esdb.PollingStationCommission on e.Id equals c.ElectionFk join com in esdb.PollingStationCommissioner on c.PresidentFk equals com.Id where com.PersonFk == user.PersonFk select c).AnyAsync();
                var isMember    = await(from e in elections join c in esdb.PollingStationCommission on e.Id equals c.ElectionFk join com in esdb.PollingStationCommissioner on c.Id equals com.PollingStationCommissionFk where com.PersonFk == user.PersonFk select c).AnyAsync();

                if (isCandidate)
                {
                    roles.Add(Candidate);
                }
                if (isPresident)
                {
                    roles.Add(PollingStationPresident);
                }
                if (isVoter)
                {
                    roles.Add(Voter);
                }
                if (isMember)
                {
                    roles.Add(PollingStationStaff);
                }
                if (isRemoteIdentificationOfficer)
                {
                    roles.Add(RemoteIdentificationOfficer);
                }
            }

            return(roles);
        }
예제 #5
0
        // ToDo: Add digital signature, add priority to the entry and notification to guardians
        public static async void Log(ESDB ctxt, Models.DB.Person p, String AccountProvider, String UserId, String text)
        {
            var log = new Models.DB.Log()
            {
                Id = Guid.NewGuid(),
                AccountProvider = AccountProvider,
                PersonFk        = p.Id,
                UserId          = UserId,
                TimeStamp       = DateTime.Now,
                LogEntry        = text
            };
            await ctxt.Log.AddAsync(log);

            await ctxt.SaveChangesAsync();
        }
예제 #6
0
        static void Main(string[] args)
        {
            using (var test = new ESDB(true))
            {
                var x = test.LoadDatabase("voitures", true);

                /// Make an insert
                var insertId = x.Insert(new { first_name = "clint", last_name = "mourlevat", age = 29 });

                /// Search one by tag
                var t = x.SearchOne(new { id = "5fd73f1a-ab0f-4112-bf7c-7549f6ed0aa0", lol = 30 });

                Console.WriteLine(t.first_name);

                /// Export all the db in zip file
                test.Export("lol.zip");
            }
        }
예제 #7
0
 public ElectionsController(ESDB context)
 {
     _context = context;
 }
예제 #8
0
 public HomeController(ILogger <HomeController> logger, ESDB context)
 {
     _logger  = logger;
     _context = context;
 }
예제 #9
0
 public PeopleController(ESDB context)
 {
     _context = context;
 }
예제 #10
0
 public PSCommissionController(ESDB ctxt, PersistentCommissionManager manager, IConfiguration configuration)
 {
     _context      = ctxt;
     Configuration = configuration;
     _manager      = manager;
 }
예제 #11
0
 public EligereESAPI(ESDB ctxt, IWebHostEnvironment env, IDataProtectionProvider provider)
 {
     _context        = ctxt;
     contentRootPath = env.ContentRootPath;
     dataProtector   = provider;
 }
예제 #12
0
 public SetupController(ESDB ctxt, IWebHostEnvironment env)
 {
     _context        = ctxt;
     contentRootPath = env.ContentRootPath;
 }