Example #1
0
         public AuthenticationLogDto(AuthenticationLog log)
         {
             Id           = log.Id;
             Type         = (TypeKey)Enum.Parse(typeof(TypeKey), log.GetType().ShortDisplayName());
             Time         = log.Time;
             Sim          = log.Sim;
             SimAndDevice = log switch
             {
                 SimAndDeviceAuthenticationSuccessLog a => a.SimAndDevice,
                 SimAndDeviceAuthenticationFailureLog _ => null,
                 MultiFactorAuthenticationSuccessLog _ => null,
                 MultiFactorAuthenticationFailureLog a => a.SimAndDevice,
                 DeauthenticationLog _ => null,
                                                      _ => null
             };
             MultiFactor = log switch
             {
                 SimAndDeviceAuthenticationSuccessLog _ => null,
                 SimAndDeviceAuthenticationFailureLog _ => null,
                 MultiFactorAuthenticationSuccessLog a => a.MultiFactor,
                 MultiFactorAuthenticationFailureLog _ => null,
                 DeauthenticationLog a => a.MultiFactor,
                                                      _ => null
             };
         }
     }
 }
Example #2
0
        public ListingMineTests(CustomWebApplicationFactoryWithMariaDb <JinCreek.Server.Admin.Startup> factory)
        {
            _client  = factory.CreateClient();
            _context = factory.Services.GetService <IServiceScopeFactory>().CreateScope().ServiceProvider.GetService <MainDbContext>();

            Utils.RemoveAllEntities(_context);

            _context.Add(_org1    = Utils.CreateOrganization(code: 1, name: "org1"));
            _context.Add(_org2    = Utils.CreateOrganization(code: 2, name: "org2"));
            _context.Add(_domain1 = new Domain {
                Id = Guid.NewGuid(), Name = "domain1", OrganizationCode = _org1.Code
            });
            _context.Add(_domain2 = new Domain {
                Id = Guid.NewGuid(), Name = "domain2", OrganizationCode = _org2.Code
            });
            _context.Add(_user0 = new SuperAdmin {
                AccountName = "user0", Name = "", Password = Utils.HashPassword("user0")
            });                                                                                                                 // スーパー管理者
            _context.Add(_user1 = new UserAdmin {
                AccountName = "user1", Name = "", Password = Utils.HashPassword("user1"), Domain = _domain1
            });                                                                                                                                   // ユーザー管理者
            _context.Add(_user2 = new GeneralUser {
                AccountName = "xuser2a", Name = "", Domain = _domain1
            });
            _context.Add(_simGroup1 = Utils.CreateSimGroup(organization: _org1, name: "simGroup1", isolatedNw1IpPool: "isolatedNw1IpPool"));
            _context.Add(_simGroup2 = Utils.CreateSimGroup(organization: _org2, name: "simGroup2", isolatedNw1IpPool: "isolatedNw1IpPool"));
            _context.Add(_sim1A     = new Sim {
                SimGroup = _simGroup1, Msisdn = "1", Imsi = "1a", IccId = "1a", UserName = "******", Password = "******"
            });
            _context.Add(_sim1B = new Sim {
                SimGroup = _simGroup1, Msisdn = "0123456789", Imsi = "1b", IccId = "1b", UserName = "******", Password = "******"
            });
            _context.Add(_sim2 = new Sim {
                SimGroup = _simGroup2, Msisdn = "2", Imsi = "2", IccId = "2", UserName = "******", Password = "******"
            });
            _context.Add(_device1    = Utils.CreateDevice(domain: _domain1, name: "device1"));
            _context.Add(_device2    = Utils.CreateDevice(domain: _domain1, name: "xdevice2a"));
            _context.Add(_simDevice1 = new SimAndDevice {
                Id = Guid.NewGuid(), SimId = _sim1A.Id, Device = _device1, IsolatedNw2Ip = ""
            });
            _context.Add(_simDevice2 = new SimAndDevice {
                Id = Guid.NewGuid(), SimId = _sim1A.Id, Device = _device2, IsolatedNw2Ip = ""
            });
            _context.Add(_multiFactor1 = new MultiFactor {
                Id = Guid.NewGuid(), SimAndDevice = _simDevice1, EndUserId = _user1.Id, ClosedNwIp = ""
            });
            _context.Add(_multiFactor2 = new MultiFactor {
                Id = Guid.NewGuid(), SimAndDevice = _simDevice2, EndUserId = _user2.Id, ClosedNwIp = ""
            });

            //_context.Add(new SimAndDeviceAuthenticationSuccessLog { Id = Guid.NewGuid(), SimAndDevice = _simDevice1 });
            //_context.Add(new SimAndDeviceAuthenticationFailureLog { Id = Guid.NewGuid(), Sim = _sim1 });
            //_context.Add(new MultiFactorAuthenticationSuccessLog { Id = Guid.NewGuid(), MultiFactor = _factorCombination1 });
            //_context.Add(new MultiFactorAuthenticationFailureLog { Id = Guid.NewGuid(), SimAndDevice = _simDevice1 });
            //_context.Add(new DeauthenticationLog { Id = Guid.NewGuid(), MultiFactor = _factorCombination1 });
            _context.SaveChanges();
        }
 private void CreateMultiFactorRecords()
 {
     MultiFactor1 = new MultiFactor()
     {
         SimAndDevice = SimAndDevice1,
         EndUser      = GeneralUser1,
         ClosedNwIp   = "192.168.20.1",
         StartDate    = CurrentDateTimeForStart.Item1,
         EndDate      = CurrentDateTimeForStart.Item2,
     };
 }
        public ActionResult <MultiFactor> PostMultiFactor(RegisterParam param)
        {
            var simDevice       = _userRepository.GetSimAndDevice((Guid)param.SimAndDeviceId);
            var endUser         = _userRepository.GetEndUser((Guid)param.UserId);
            var availablePeriod = endUser.AvailablePeriods.OrderByDescending(a => a.StartDate).FirstOrDefault();

            if (param.StartDate < simDevice.StartDate || param.StartDate > simDevice.EndDate || availablePeriod?.StartDate > param.StartDate || availablePeriod?.EndDate < param.StartDate)
            {
                ModelState.AddModelError(nameof(param.StartDate), Messages.OutOfDate);
            }
            if (param.EndDate < simDevice.StartDate || param.EndDate > simDevice.EndDate || availablePeriod?.StartDate > param.EndDate || availablePeriod?.EndDate < param.EndDate)
            {
                ModelState.AddModelError(nameof(param.EndDate), Messages.OutOfDate);
            }
            if (!ModelState.IsValid)
            {
                return(ValidationProblem(ModelState));
            }
            if (_context.MultiFactor.Any(s => s.SimAndDevice.Id == simDevice.Id && s.EndUser.Id == endUser.Id))
            {
                ModelState.AddModelError(nameof(MultiFactor), Messages.Duplicate);
            }
            if (!ModelState.IsValid)
            {
                return(ValidationProblem(ModelState));
            }
            var multiFactor = new MultiFactor()
            {
                SimAndDevice = simDevice,
                EndUser      = endUser,
                StartDate    = (DateTime)param.StartDate,
                EndDate      = param.EndDate,
                ClosedNwIp   = param.ClosedNwIp
            };

            try
            {
                _userRepository.Create(multiFactor);
            }
            catch (DbUpdateException)
            {
                throw;
            }

            return(CreatedAtAction("GetMultiFactor", new { id = multiFactor.Id }, multiFactor));
        }
        public void Case05()
        {
            var multiFactor = new MultiFactor
            {
                Id             = Guid.NewGuid(),
                SimAndDeviceId = _simDevice1.Id,
                EndUserId      = _user1.Id,
                ClosedNwIp     = "127.0.0.1",
                StartDate      = DateTime.Parse("2020-02-01"),
            };

            _context.Add(multiFactor);
            _context.SaveChanges();
            var(response, _, json) = Utils.Get(_client, $"{Url}/{multiFactor.Id}", "user1", "user1", 1, _domain1.Name); // ユーザー管理者
            Assert.Equal(HttpStatusCode.OK, response.StatusCode);
            Assert.Equal(multiFactor.Id, json["id"]);
            Assert.Equal(multiFactor.SimAndDevice.Sim.Msisdn, json["simAndDevice"]["sim"]["msisdn"]);
            Assert.Equal(multiFactor.SimAndDevice.Device.Name, json["simAndDevice"]["device"]["name"]);
            Assert.Equal(multiFactor.EndUser.AccountName, json["endUser"]["accountName"]);
            Assert.Equal(multiFactor.StartDate.ToString("yyyy-MM-dd"), json["startDate"]);
            Assert.Empty(json["endDate"]);
            Assert.Equal(multiFactor.ClosedNwIp, json["closedNwIp"]);
        }
        public InquiryMineTests(CustomWebApplicationFactory <JinCreek.Server.Admin.Startup> factory)
        {
            _client  = factory.CreateClient();
            _context = factory.Services.GetService <IServiceScopeFactory>().CreateScope().ServiceProvider.GetService <MainDbContext>();

            Utils.RemoveAllEntities(_context);

            _context.Add(_org1    = Utils.CreateOrganization(code: 1, name: "org1"));
            _context.Add(_org2    = Utils.CreateOrganization(code: 2, name: "org2"));
            _context.Add(_domain1 = new Domain {
                Id = Guid.NewGuid(), Name = "domain01", OrganizationCode = _org1.Code
            });
            _context.Add(_domain2 = new Domain {
                Id = Guid.NewGuid(), Name = "domain02", OrganizationCode = _org2.Code
            });
            _context.Add(_userGroup1 = new UserGroup {
                Id = Guid.NewGuid(), Name = "userGroup1", DomainId = _domain1.Id
            });
            _context.Add(_userGroup2 = new UserGroup {
                Id = Guid.NewGuid(), Name = "userGroup2", DomainId = _domain2.Id
            });
            _context.Add(_user0 = new SuperAdmin {
                AccountName = "user0", Password = Utils.HashPassword("user0")
            });                                                                                                      // スーパー管理者
            _context.Add(_user1 = new UserAdmin {
                AccountName = "user1", Password = Utils.HashPassword("user1"), DomainId = _domain1.Id
            });                                                                                                                             // ユーザー管理者
            _context.Add(_user2 = new GeneralUser()
            {
                AccountName = "user2", DomainId = _domain2.Id
            });
            _context.Add(_simGroup1 = new SimGroup
            {
                Id                      = Guid.NewGuid(),
                Name                    = "simGroup1",
                Organization            = _org1,
                Apn                     = "apn",
                AuthenticationServerIp  = "AuthServerIpAddress",
                IsolatedNw1IpPool       = "Nw1IpAddressPool",
                IsolatedNw1SecondaryDns = "Nw1SecondaryDns",
                IsolatedNw1IpRange      = "Nw1IpAddressRange",
                IsolatedNw1PrimaryDns   = "Nw1PrimaryDns",
                NasIp                   = "NasIpAddress",
                UserNameSuffix          = "UserNameSuffix",
                PrimaryDns              = "PrimaryDns",
                SecondaryDns            = "SecondaryDns"
            });
            _context.Add(_simGroup2 = new SimGroup {
                Id = Guid.NewGuid(), Name = "simGroup2", OrganizationCode = _org2.Code
            });
            _context.Add(_sim1 = new Sim {
                SimGroup = _simGroup1, Msisdn = "msisdn01", Imsi = "imsi01", IccId = "iccid01", UserName = "******", Password = "******"
            });
            _context.Add(_sim2 = new Sim {
                SimGroup = _simGroup1, Msisdn = "msisdn01", Imsi = "imsi01", IccId = "iccid01", UserName = "******", Password = "******"
            });                                                                                                                                                         //他組織
            _context.Add(_deviceGroup1 = new DeviceGroup {
                Id = Guid.NewGuid(), DomainId = _domain1.Id, Name = "deviceGroup1"
            });
            _context.Add(_device1 = new Device {
                Id = Guid.NewGuid(), DomainId = _domain1.Id, Name = "device1", ManagedNumber = "2", UseTpm = true, WindowsSignInListCacheDays = 1
            });
            _context.Add(_device1 = new Device {
                Id = Guid.NewGuid(), DomainId = _domain2.Id, Name = "device2", ManagedNumber = "2", UseTpm = true, WindowsSignInListCacheDays = 1
            });                                                                                                                                                                       //他組織
            _context.Add(_simDevice1 = new SimAndDevice {
                SimId = _sim1.Id, DeviceId = _device1.Id
            });
            _context.Add(_simDevice2 = new SimAndDevice {
                SimId = _sim2.Id, DeviceId = _device1.Id
            });                                                                                        // sim 他組織
            //_context.Add(_simDevice3 = new SimAndDevice { SimId = _sim1.Id, DeviceId = _device2.Id }); // 端末 他組織
            _context.Add(_multiFactor2 = new MultiFactor {
                Id = Guid.NewGuid(), SimAndDeviceId = _simDevice1.Id, EndUserId = _user2.Id
            });                                                                                                                            //User他組織
            _context.SaveChanges();
        }
        public DeleteMineTests(CustomWebApplicationFactoryWithMariaDb <Admin.Startup> factory)
        {
            _client  = factory.CreateClient();
            _context = factory.Services.GetService <IServiceScopeFactory>().CreateScope().ServiceProvider.GetService <MainDbContext>();
            Utils.RemoveAllEntities(_context);

            _context.Add(_org1    = Utils.CreateOrganization(code: 1, name: "org1"));
            _context.Add(_org2    = Utils.CreateOrganization(code: 2, name: "org2"));
            _context.Add(_domain1 = new Domain {
                Id = Guid.NewGuid(), Name = "domain01", Organization = _org1
            });
            _context.Add(_domain2 = new Domain {
                Id = Guid.NewGuid(), Name = "domain02", Organization = _org2
            });
            _context.Add(_userGroup1 = new UserGroup {
                Id = Guid.NewGuid(), Name = "userGroup1", Domain = _domain1
            });
            _context.Add(_userGroup2 = new UserGroup {
                Id = Guid.NewGuid(), Name = "userGroup2", Domain = _domain2
            });

            _context.Add(_user1 = new SuperAdmin {
                AccountName = "user0", Name = "user0", Password = Utils.HashPassword("user0")
            });                                                                                                                      // スーパー管理者
            _context.Add(_user2 = new UserAdmin {
                AccountName = "user1", Name = "user1", Password = Utils.HashPassword("user1"), Domain = _domain1
            });                                                                                                                                        // ユーザー管理者
            _context.Add(_user3 = new GeneralUser {
                AccountName = "user2", Name = "user2", DomainId = _domain1.Id
            });
            _context.Add(_user4 = new GeneralUser {
                AccountName = "user4", Name = "user4", DomainId = _domain2.Id
            });

            _context.Add(_simGroup1 = Utils.CreateSimGroup(name: "simGroup1", organization: _org1, isolatedNw1IpPool: "IsolatedNw1IpPool"));
            _context.Add(_simGroup2 = Utils.CreateSimGroup(name: "simGroup2", organization: _org2, isolatedNw1IpPool: "IsolatedNw1IpPool"));
            _context.Add(_sim1      = new Sim() // 組織 : '自組織
            {
                Msisdn   = "msisdn01",
                Imsi     = "imsi01",
                IccId    = "iccid01",
                UserName = "******",
                Password = "******",
                SimGroup = _simGroup1
            });
            _context.Add(_sim2 = new Sim() // 組織 : '他組織
            {
                Msisdn   = "1002",
                Imsi     = "1002",
                IccId    = "1002",
                UserName = "******",
                Password = "******",
                SimGroup = _simGroup2
            });
            _context.Add(_device1 = new Device()
            {
                LteModule     = null,
                Domain        = _domain1,
                Name          = "device01",
                UseTpm        = true,
                ManagedNumber = "001",
                WindowsSignInListCacheDays = 1,
            });
            _context.Add(_simDevice1 = new SimAndDevice()
            {
                Sim                    = _sim1,
                Device                 = _device1,
                IsolatedNw2Ip          = "127.0.0.1/18",
                AuthenticationDuration = 1,
                StartDate              = DateTime.Parse("2020-02-01"),
                EndDate                = DateTime.Parse("2020-02-09")
            });
            _context.Add(_multiFactor1 = new MultiFactor
            {
                SimAndDeviceId = _simDevice1.Id,
                EndUserId      = _user3.Id,
                ClosedNwIp     = "127.0.0.1",
                StartDate      = DateTime.Now,
                EndDate        = DateTime.Now
            });
            _context.Add(_multiFactor2 = new MultiFactor // 他組織
            {
                SimAndDeviceId = _simDevice1.Id,
                EndUserId      = _user4.Id,
                ClosedNwIp     = "127.0.0.1",
                StartDate      = DateTime.Now,
                EndDate        = DateTime.Now
            });
            _context.SaveChanges();
        }
Example #8
0
        public UpdateTests(CustomWebApplicationFactory <JinCreek.Server.Admin.Startup> factory)
        {
            _client  = factory.CreateClient();
            _context = factory.Services.GetService <IServiceScopeFactory>().CreateScope().ServiceProvider.GetService <MainDbContext>();

            Utils.RemoveAllEntities(_context);

            _context.Add(_org1    = Utils.CreateOrganization(code: 1, name: "org1"));
            _context.Add(_org2    = Utils.CreateOrganization(code: 2, name: "org2"));
            _context.Add(_domain1 = new Domain {
                Id = Guid.NewGuid(), Name = "domain01", Organization = _org1
            });
            _context.Add(_domain2 = new Domain {
                Id = Guid.NewGuid(), Name = "domain02", Organization = _org2
            });
            _context.Add(_userGroup1 = new UserGroup {
                Id = Guid.NewGuid(), Name = "userGroup1", Domain = _domain1
            });
            _context.Add(_userGroup2 = new UserGroup {
                Id = Guid.NewGuid(), Name = "userGroup2", Domain = _domain2
            });

            _context.Add(_user1 = new SuperAdmin {
                AccountName = "user0", Password = Utils.HashPassword("user0")
            });                                                                                                      // スーパー管理者
            _context.Add(_user2 = new UserAdmin()
            {
                AccountName = "user1", Password = Utils.HashPassword("user1"), Domain = _domain1
            });                                                                                                                          // ユーザー管理者
            _context.Add(_user3 = new GeneralUser()
            {
                AccountName = "user2", DomainId = _domain1.Id
            });
            _context.Add(_availablePeriod = new AvailablePeriod()
            {
                EndUser = _user2, EndDate = DateTime.Parse("2021-03-01"), StartDate = DateTime.Parse("2020-02-10")
            });
            _context.Add(_availablePeriod = new AvailablePeriod()
            {
                EndUser = _user3, EndDate = DateTime.Parse("2021-03-01"), StartDate = DateTime.Parse("2020-02-10")
            });
            _context.Add(_simGroup1 = new SimGroup()
            {
                Id                      = Guid.NewGuid(),
                Name                    = "simGroup1",
                Organization            = _org1,
                Apn                     = "apn",
                AuthenticationServerIp  = "AuthenticationServerIp",
                IsolatedNw1IpPool       = "IsolatedNw1IpPool",
                IsolatedNw1SecondaryDns = "IsolatedNw1SecondaryDns",
                IsolatedNw1IpRange      = "IsolatedNw1IpRange",
                IsolatedNw1PrimaryDns   = "IsolatedNw1PrimaryDns",
                NasIp                   = "NasIp",
                PrimaryDns              = "PrimaryDns",
                SecondaryDns            = "SecondaryDns"
            });
            _context.Add(_simGroup2 = new SimGroup
            {
                Id = Guid.NewGuid(), Name = "simGroup2", Organization = _org2, IsolatedNw1IpPool = ""
            });
            _context.Add(_sim1 = new Sim() // 組織 : '自組織
            {
                Msisdn   = "msisdn01",
                Imsi     = "imsi01",
                IccId    = "iccid01",
                UserName = "******",
                Password = "******",
                SimGroup = _simGroup1
            });
            _context.Add(_device1 = new Device()
            {
                LteModule     = null,
                Domain        = _domain1,
                Name          = "device01",
                UseTpm        = true,
                ManagedNumber = "001",
                WindowsSignInListCacheDays = 1,
            });
            _context.Add(_simDevice1 = new SimAndDevice()
            {
                Sim                    = _sim1,
                Device                 = _device1,
                IsolatedNw2Ip          = "127.0.0.1/18",
                AuthenticationDuration = 1,
                StartDate              = DateTime.Parse("2020-02-01"),
                EndDate                = DateTime.Parse("2021-02-01")
            });
            _context.Add(_multiFactor1 = new MultiFactor
            {
                SimAndDeviceId = _simDevice1.Id,
                EndUserId      = _user3.Id,
                ClosedNwIp     = "127.0.0.1",
                StartDate      = DateTime.Now,
                EndDate        = DateTime.Now
            });
            _context.SaveChanges();
        }
 public MultiFactorWrapper(MultiFactor multiFactor)
 {
     _multiFactor = multiFactor ?? throw new ArgumentNullException(nameof(multiFactor));
 }
        /// <summary>
        /// CSVインポート
        /// </summary>
        /// <param name="csv"></param>
        /// <param name="endUser"></param>
        /// <returns></returns>
        private ActionResult <IEnumerable <MultiFactor> > ImportCsv(TextReader csv, EndUser endUser = null)
        {
            // 1. 型変換エラーがあればここで終了する:
            var records = Utils.ParseCsv <CsvRecord, CsvRecordMap>(csv, ModelState);

            if (!ModelState.IsValid)
            {
                return(ValidationProblem(ModelState));
            }

            // 2. バリデーションエラーがあればここで終了する:
            Utils.TryValidateCsvRecords(records, ModelState);
            if (!ModelState.IsValid)
            {
                return(ValidationProblem(ModelState));
            }

            var multiFactors = new List <MultiFactor>();

            using (var transaction = _context.Database.BeginTransaction())
            {
                foreach (var record in records)
                {
                    var simDevice       = _userRepository.GetSimAndDevice((Guid)record.SimAndDeviceId);
                    var user            = _userRepository.GetEndUser((Guid)record.UserId);
                    var availablePeriod = user.AvailablePeriods.OrderByDescending(a => a.StartDate).FirstOrDefault();
                    if (record.StartDate < simDevice.StartDate || record.StartDate > simDevice.EndDate || availablePeriod?.StartDate > record.StartDate || availablePeriod?.EndDate < record.StartDate)
                    {
                        ModelState.AddModelError(nameof(record.StartDate), Messages.OutOfDate);
                    }
                    if (record.EndDate < simDevice.StartDate || record.EndDate > simDevice.EndDate || availablePeriod?.StartDate > record.EndDate || availablePeriod?.EndDate < record.EndDate)
                    {
                        ModelState.AddModelError(nameof(record.EndDate), Messages.OutOfDate);
                    }
                    if (!ModelState.IsValid)
                    {
                        return(ValidationProblem(ModelState));
                    }

                    var multiFactor = _context.MultiFactor
                                      .Include(m => m.SimAndDevice)
                                      .Include(m => m.SimAndDevice.Sim)
                                      .Include(m => m.SimAndDevice.Device)
                                      .Include(m => m.MultiFactorAuthenticated)
                                      .Include(m => m.EndUser)
                                      .Include(m => m.EndUser.Domain)
                                      .Include(m => m.EndUser.Domain.Organization)
                                      .SingleOrDefault(m => m.SimAndDeviceId == simDevice.Id && m.EndUserId == user.Id);
                    if (multiFactor == null) // 多要素がない そしてDeleteはDかdのない 登録
                    {
                        var multiFactor1 = new MultiFactor()
                        {
                            SimAndDevice = simDevice,
                            EndUser      = user,
                            ClosedNwIp   = record.ClosedNwIp,
                            EndDate      = record.EndDate,
                            StartDate    = (DateTime)record.StartDate
                        };
                        _userRepository.Create(multiFactor1);
                        multiFactors.Add(multiFactor1);
                        continue;
                    }

                    if (endUser != null && multiFactor.EndUser.Domain.OrganizationCode != endUser.Domain.Organization.Code)
                    {
                        ModelState.AddModelError("Role", Messages.InvalidRole);
                        return(ValidationProblem(modelStateDictionary: ModelState, statusCode: StatusCodes.Status403Forbidden));
                    }

                    if ("d".Equals(record.Delete) || "D".Equals(record.Delete)) // Dかdか そして 多要素はあり は削除
                    {
                        if (_context.MultiFactorAuthenticated.Any(m => m.MultiFactorId == multiFactor.Id))
                        {
                            ModelState.AddModelError(nameof(MultiFactorAuthenticated), Messages.ChildEntityExists);
                            return(ValidationProblem(ModelState));
                        }
                        if (_context.DeauthenticationLog.Any(f => f.MultiFactor.Id == multiFactor.Id))
                        {
                            ModelState.AddModelError(nameof(DeauthenticationLog), Messages.ChildEntityExists);
                            return(ValidationProblem(ModelState));
                        }

                        if (_context.MultiFactorAuthenticationSuccessLog.Any(f => f.MultiFactor.Id == multiFactor.Id))
                        {
                            ModelState.AddModelError(nameof(MultiFactorAuthenticationSuccessLog), Messages.ChildEntityExists);
                            return(ValidationProblem(ModelState));
                        }
                        _userRepository.RemoveMultiFactor(multiFactor.Id);
                        multiFactors.Add(multiFactor);
                        continue;
                    }
                    //更新
                    multiFactor.ClosedNwIp = record.ClosedNwIp;
                    multiFactor.StartDate  = (DateTime)record.StartDate;
                    multiFactor.EndDate    = record.EndDate;
                    _userRepository.Update(multiFactor);
                    multiFactors.Add(multiFactor);
                }

                transaction.Commit();
            }

            return(Ok(multiFactors));
        }
Example #11
0
        public InquiryTests(CustomWebApplicationFactoryWithMariaDb <JinCreek.Server.Admin.Startup> factory)
        {
            _client  = factory.CreateClient();
            _context = factory.Services.GetService <IServiceScopeFactory>().CreateScope().ServiceProvider.GetService <MainDbContext>();

            Utils.RemoveAllEntities(_context);

            _context.Add(_org1    = Utils.CreateOrganization(code: 1, name: "org1"));
            _context.Add(_org2    = Utils.CreateOrganization(code: 2, name: "org2"));
            _context.Add(_domain1 = new Domain {
                Id = Guid.NewGuid(), Name = "domain01", OrganizationCode = _org1.Code
            });
            _context.Add(_domain2 = new Domain {
                Id = Guid.NewGuid(), Name = "domain02", OrganizationCode = _org2.Code
            });
            _context.Add(_userGroup1 = new UserGroup {
                Id = Guid.NewGuid(), Name = "userGroup1", DomainId = _domain1.Id
            });
            _context.Add(_userGroup2 = new UserGroup {
                Id = Guid.NewGuid(), Name = "userGroup2", DomainId = _domain2.Id
            });
            _context.Add(_user0 = new SuperAdmin {
                Name = "", AccountName = "user0", Password = Utils.HashPassword("user0")
            });                                                                                                                 // スーパー管理者
            _context.Add(_user1 = new UserAdmin()
            {
                Name = "", AccountName = "user1", Password = Utils.HashPassword("user1"), Domain = _domain1
            });                                                                                                                                     // ユーザー管理者
            _context.Add(_user2 = new GeneralUser()
            {
                Name = "", AccountName = "user2", DomainId = _domain1.Id
            });
            _context.Add(_user3 = new GeneralUser()
            {
                Name = "", AccountName = "user3", DomainId = _domain1.Id
            });
            _context.Add(_user4 = new GeneralUser()
            {
                Name = "", AccountName = "user4", DomainId = _domain2.Id
            });
            _context.Add(new AvailablePeriod()
            {
                EndUser = _user1, EndDate = DateTime.Parse("2021-03-01"), StartDate = DateTime.Parse("2020-02-10")
            });
            _context.Add(new AvailablePeriod()
            {
                EndUser = _user2, EndDate = DateTime.Parse("2021-03-01"), StartDate = DateTime.Parse("2020-02-10")
            });
            _context.Add(new AvailablePeriod()
            {
                EndUser = _user3, EndDate = DateTime.Parse("2021-03-01"), StartDate = DateTime.Parse("2020-02-10")
            });
            _context.Add(new AvailablePeriod()
            {
                EndUser = _user4, EndDate = DateTime.Parse("2021-03-01"), StartDate = DateTime.Parse("2020-02-10")
            });
            _context.Add(_userGroupEndUser = new UserGroupEndUser()
            {
                EndUser = _user2, UserGroup = _userGroup1
            });
            _context.Add(_simGroup1 = new SimGroup
            {
                Name                    = "simGroup1",
                Organization            = _org1,
                Apn                     = "apn",
                AuthenticationServerIp  = "AuthServerIpAddress",
                IsolatedNw1IpPool       = "Nw1IpAddressPool",
                IsolatedNw1SecondaryDns = "Nw1SecondaryDns",
                IsolatedNw1IpRange      = "Nw1IpAddressRange",
                IsolatedNw1PrimaryDns   = "Nw1PrimaryDns",
                NasIp                   = "NasIpAddress",
                UserNameSuffix          = "UserNameSuffix",
                PrimaryDns              = "PrimaryDns",
                SecondaryDns            = "SecondaryDns"
            });
            _context.Add(_sim1 = new Sim {
                SimGroup = _simGroup1, Msisdn = "msisdn01", Imsi = "imsi01", IccId = "iccid01", UserName = "******", Password = "******"
            });
            _context.Add(_sim2 = new Sim {
                SimGroup = _simGroup1, Msisdn = "msisdn02", Imsi = "imsi02", IccId = "iccid02", UserName = "******", Password = "******"
            });
            _context.Add(_deviceGroup1 = new DeviceGroup {
                DomainId = _domain1.Id, Name = "deviceGroup1"
            });
            _context.Add(_device1 = new Device
            {
                LteModule     = _lte1,
                Domain        = _domain1,
                Name          = "device01",
                UseTpm        = true,
                ManagedNumber = "001",
                ProductName   = "",
                SerialNumber  = "",
                WindowsSignInListCacheDays = 1,
                StartDate = DateTime.Parse("2020-02-07"),
                EndDate   = DateTime.Parse("2021-02-01")
            });
            _context.Add(_device2 = new Device
            {
                LteModule     = _lte1,
                Domain        = _domain1,
                Name          = "device02",
                UseTpm        = true,
                ManagedNumber = "002",
                ProductName   = "",
                SerialNumber  = "",
                WindowsSignInListCacheDays = 1,
                StartDate = DateTime.Parse("2020-02-07"),
                EndDate   = DateTime.Parse("2021-02-01")
            });
            _context.Add(_device3 = new Device
            {
                LteModule     = _lte1,
                Domain        = _domain2,
                Name          = "device02",
                UseTpm        = true,
                ManagedNumber = "002",
                ProductName   = "",
                SerialNumber  = "",
                WindowsSignInListCacheDays = 1,
                StartDate = DateTime.Parse("2020-02-07"),
                EndDate   = DateTime.Parse("2021-02-01")
            });
            _context.Add(_simDevice1 = new SimAndDevice
            {
                SimId                  = _sim1.Id,
                DeviceId               = _device1.Id,
                IsolatedNw2Ip          = "127.0.0.1",
                AuthenticationDuration = 1,
                StartDate              = DateTime.Parse("2020-02-07"),
                EndDate                = DateTime.Parse("2020-03-07"),
            });
            _context.Add(_simDevice2 = new SimAndDevice
            {
                SimId                  = _sim2.Id,
                DeviceId               = _device1.Id,
                IsolatedNw2Ip          = "127.0.0.1",
                AuthenticationDuration = 1,
                StartDate              = DateTime.Parse("2020-02-07"),
                EndDate                = DateTime.Parse("2020-03-07"),
            });
            _context.Add(_simDevice3 = new SimAndDevice
            {
                SimId                  = _sim1.Id,
                DeviceId               = _device2.Id,
                IsolatedNw2Ip          = "127.0.0.1",
                AuthenticationDuration = 1,
                StartDate              = DateTime.Parse("2020-02-07"),
                EndDate                = DateTime.Parse("2020-03-07"),
            });
            _context.Add(_simDevice4 = new SimAndDevice
            {
                SimId                  = _sim2.Id,
                DeviceId               = _device2.Id,
                IsolatedNw2Ip          = "127.0.0.1",
                AuthenticationDuration = 1,
                StartDate              = DateTime.Parse("2020-02-07"),
                EndDate                = DateTime.Parse("2020-03-07"),
            });
            _context.Add(_multiFactor1 = new MultiFactor
            {
                Id             = Guid.NewGuid(),
                SimAndDeviceId = _simDevice1.Id,
                EndUserId      = _user2.Id,
                ClosedNwIp     = "127.0.0.1",
                StartDate      = DateTime.Parse("2020-02-01"),
            });
            _context.Add(_multiFactor2 = new MultiFactor
            {
                Id             = Guid.NewGuid(),
                SimAndDeviceId = _simDevice2.Id,
                EndUserId      = _user2.Id,
                ClosedNwIp     = "127.0.0.1",
                StartDate      = DateTime.Parse("2020-02-01"),
            });
            _context.Add(_multiFactor3 = new MultiFactor
            {
                Id             = Guid.NewGuid(),
                SimAndDeviceId = _simDevice3.Id,
                EndUserId      = _user2.Id,
                ClosedNwIp     = "127.0.0.1",
                StartDate      = DateTime.Parse("2020-02-01"),
            });
            _context.Add(_multiFactor4 = new MultiFactor
            {
                Id             = Guid.NewGuid(),
                SimAndDeviceId = _simDevice4.Id,
                EndUserId      = _user2.Id,
                ClosedNwIp     = "127.0.0.1",
                StartDate      = DateTime.Parse("2020-02-01"),
            });
            _context.Add(_multiFactor5 = new MultiFactor
            {
                Id             = Guid.NewGuid(),
                SimAndDeviceId = _simDevice1.Id,
                EndUserId      = _user3.Id,
                ClosedNwIp     = "127.0.0.1",
                StartDate      = DateTime.Parse("2020-02-01"),
            });
            _context.Add(_multiFactor6 = new MultiFactor
            {
                Id             = Guid.NewGuid(),
                SimAndDeviceId = _simDevice2.Id,
                EndUserId      = _user3.Id,
                ClosedNwIp     = "127.0.0.1",
                StartDate      = DateTime.Parse("2020-02-01"),
            });
            _context.Add(_multiFactor7 = new MultiFactor
            {
                Id             = Guid.NewGuid(),
                SimAndDeviceId = _simDevice3.Id,
                EndUserId      = _user3.Id,
                ClosedNwIp     = "127.0.0.1",
                StartDate      = DateTime.Parse("2020-02-01"),
            });
            _context.Add(_multiFactor8 = new MultiFactor
            {
                Id             = Guid.NewGuid(),
                SimAndDeviceId = _simDevice4.Id,
                EndUserId      = _user3.Id,
                ClosedNwIp     = "127.0.0.1",
                StartDate      = DateTime.Parse("2020-02-01"),
            });
            _context.Add(_multiFactor9 = new MultiFactor
            {
                Id             = Guid.NewGuid(),
                SimAndDeviceId = _simDevice1.Id,
                EndUserId      = _user4.Id,
                ClosedNwIp     = "127.0.0.1",
                StartDate      = DateTime.Parse("2020-02-01"),
            });
            _context.Add(_multiFactor10 = new MultiFactor
            {
                Id             = Guid.NewGuid(),
                SimAndDeviceId = _simDevice2.Id,
                EndUserId      = _user4.Id,
                ClosedNwIp     = "127.0.0.1",
                StartDate      = DateTime.Parse("2020-02-01"),
            });
            _context.Add(_multiFactor11 = new MultiFactor
            {
                Id             = Guid.NewGuid(),
                SimAndDeviceId = _simDevice3.Id,
                EndUserId      = _user4.Id,
                ClosedNwIp     = "127.0.0.1",
                StartDate      = DateTime.Parse("2020-02-01"),
            });
            _context.Add(_multiFactor12 = new MultiFactor
            {
                Id             = Guid.NewGuid(),
                SimAndDeviceId = _simDevice4.Id,
                EndUserId      = _user4.Id,
                ClosedNwIp     = "127.0.0.1",
                StartDate      = DateTime.Parse("2020-02-01"),
            });
            _context.Add(new MultiFactorAuthenticated()
            {
                Expiration = DateTime.Now.AddHours(1.00), MultiFactor = _multiFactor1
            });
            _context.Add(new MultiFactorAuthenticated()
            {
                Expiration = DateTime.Now.AddHours(1.00), MultiFactor = _multiFactor2
            });
            _context.Add(new MultiFactorAuthenticated()
            {
                Expiration = DateTime.Now.AddHours(1.00), MultiFactor = _multiFactor3
            });
            _context.Add(new MultiFactorAuthenticated()
            {
                Expiration = DateTime.Now.AddHours(1.00), MultiFactor = _multiFactor4
            });
            _context.Add(new MultiFactorAuthenticated()
            {
                Expiration = DateTime.Now.AddHours(1.00), MultiFactor = _multiFactor5
            });
            _context.Add(new MultiFactorAuthenticated()
            {
                Expiration = DateTime.Now.AddHours(1.00), MultiFactor = _multiFactor6
            });
            _context.Add(new MultiFactorAuthenticated()
            {
                Expiration = DateTime.Now.AddHours(1.00), MultiFactor = _multiFactor7
            });
            _context.Add(new MultiFactorAuthenticated()
            {
                Expiration = DateTime.Now.AddHours(1.00), MultiFactor = _multiFactor8
            });
            _context.Add(new MultiFactorAuthenticated()
            {
                Expiration = DateTime.Now.AddHours(1.00), MultiFactor = _multiFactor9
            });
            _context.Add(new MultiFactorAuthenticated()
            {
                Expiration = DateTime.Now.AddHours(1.00), MultiFactor = _multiFactor10
            });
            _context.Add(new MultiFactorAuthenticated()
            {
                Expiration = DateTime.Now.AddHours(1.00), MultiFactor = _multiFactor11
            });
            _context.Add(new MultiFactorAuthenticated()
            {
                Expiration = DateTime.Now.AddHours(1.00), MultiFactor = _multiFactor12
            });
            _context.SaveChanges();
        }