示例#1
0
        protected override async void OnStart()
        {
            if (IsOnStartCalled)
            {
                return;
            }

            var config = AppConfig.GetConfig();

            AppCenter.Start(
                $"ios={config.AppCenteriOSKey};android={config.AppCenterAndroidKey};",
                typeof(Analytics),
                typeof(Crashes),
                typeof(Push));

            Analytics.TrackEvent("AppStarted", new Dictionary <string, string>()
            {
                { nameof(config.AppCenterAndroidKey), config.AppCenterAndroidKey },
                { nameof(config.AppCenteriOSKey), config.AppCenteriOSKey },
                { nameof(config.RealmServerUrl), config.RealmServerUrl },
                { nameof(config.RealmDatabase), config.RealmDatabase },
                { "TimeZone", TimeZoneInfo.Local.ToSerializedString() }
            });

            await RealmService.InitializeCloudSync(config.RealmServerUrl, config.RealmDatabase);

            IsOnStartCalled = true;
        }
示例#2
0
文件: App.xaml.cs 项目: vadlit/App
        public App()
        {
            var language = LanguageService.GetCurrentLanguage();

            AppResources.Culture = new CultureInfo(language.GetLanguageCode());

            var savedAppVersion   = Portable.Helpers.Settings.AppVersion;
            var currentAppVersion = DependencyService.Get <IAppVersionProvider>().AppVersion;

            bool overwrite = savedAppVersion != currentAppVersion;

            RealmService.Initialize(overwrite);

            Portable.Helpers.Settings.AppVersion = currentAppVersion;

            this.InitializeComponent();

            // Update Audit on startup
            Task.Run(UpdateService.UpdateAudit);

            AppCenter.Start(
                $"ios={IosAppCenterKey};android={AndroidAppCenterKey};",
                typeof(Analytics),
                typeof(Crashes));

            Console.WriteLine("AuditUpdate. AppCenter InstallId: " + AppCenter.GetInstallIdAsync().Result);

            this.MainPage = new BottomTabbedPage();
        }
示例#3
0
文件: Program.cs 项目: unchase/App
        public static async Task Main()
        {
            RealmService.InitializeOfflineDatabase();

            var config = AppConfig.GetConfig();

            await RealmService.InitializeCloudSync(config.RealmServerUrl, config.RealmDatabase);
        }
示例#4
0
        /// <summary>Initializes new instance of TestContext.</summary>
        public TestContext()
        {
            ConnectedUsers = new List<User>();
            Entities = new List<object>();
            Service = new RealmService(new TestProtocol());
            Client = NewRealmClient();

            Service.UserConnectionStateChanged += OnUserConnectionStateChanged;
        }
示例#5
0
        private List <Grouping <string, AboutPageItem> > GetAboutItems()
        {
            var aboutPageItems = new List <Grouping <string, AboutPageItem> >();

            aboutPageItems.Add(new Grouping <string, AboutPageItem>("Friends", new AboutPageItem[] {
                new AboutPageItem
                {
                    AboutItemType = AboutItemType.Friends
                }
            }));

            var communities = RealmService.Get <CommunityModel>();
            var sessions    = RealmService.Get <MeetupModel>();
            var communitiesWithFirstSessionDate = communities.Join(
                sessions,
                c => c.Id,
                s => s.CommunityID,
                (c, s) => new
            {
                Community        = c,
                FirstSessionDate = s.Sessions.OrderBy(session => session.StartTime).FirstOrDefault()?.StartTime
            }).OrderBy(x => x.FirstSessionDate).GroupBy(x => x.Community.Id).Select(x => x.First());

            aboutPageItems.Add(new Grouping <string, AboutPageItem>("OurCommunities", communitiesWithFirstSessionDate.Select(x => new AboutPageItem
            {
                Community     = x.Community,
                AboutItemType = AboutItemType.Community
            })));

            var aboutAppItems = new Model.MenuItem[]
            {
                new Model.MenuItem {
                    Name = "CreatedBy", Parameter = "CreatedBy"
                },
                new Model.MenuItem {
                    Name = "IssueTracker", Parameter = "IssueTracker"
                },
                new Model.MenuItem {
                    Name = "TechnologyUsed", Parameter = "TechnologyUsed"
                },
            };

            aboutPageItems.Add(new Grouping <string, AboutPageItem>("AboutApp", aboutAppItems.Select(x => new AboutPageItem
            {
                MenuItem      = x,
                AboutItemType = AboutItemType.MenuItem
            })));

            aboutPageItems.Add(new Grouping <string, AboutPageItem>("Settings", new AboutPageItem[] {
                new AboutPageItem
                {
                    AboutItemType = AboutItemType.Settings
                }
            }));

            return(aboutPageItems);
        }
示例#6
0
 public static IList <SubscriptionModel> GetDefaultCommunitySubscriptionsByRealm(Realm realm)
 {
     return(DefaultCommunitySubscriptions.Union(RealmService.Get <CommunityModel>(realm).Select(x => new SubscriptionModel
     {
         Community = x,
         IsSelected = true,
         LoadedPosts = 100,
         Type = SocialMediaType.Vkontakte
     })).ToList());
 }
        public ToDoListPageViewModel(INavigationService navigationService,
                                     RealmService realmService
                                     )
            : base(navigationService)
        {
            Title        = AppResources.ViewATitle;
            RealmService = realmService;

            Tasks      = new RangedObservableCollection <ToDoListItemViewModel>();
            AddCommand = new DelegateCommand(AddTask);
        }
示例#8
0
        public App()
        {
            var language = LanguageService.GetCurrentLanguage();

            AppResources.Culture = new CultureInfo(language.GetLanguageCode());

            RealmService.Initialize();

            this.InitializeComponent();

#if RELEASE
            AppCenter.Start(
                "ios=1e7f311f-1055-4ec9-8b00-0302015ab8ae;android=6f9a7703-8ca4-477e-9558-7e095f7d20aa;",
                typeof(Analytics),
                typeof(Crashes));
#endif

            this.MainPage = new BottomTabbedPage();
        }
示例#9
0
        protected void RunServiceTests()
        {
            var realmService = RealmService.GetInstance <Models.Person>();

            realmService.Write(() =>
            {
                realmService.Add(new Person {
                    Name = "Greg"
                });
                realmService.Add(new Person {
                    Name = "Jim"
                });
                realmService.Add(new Person {
                    Name = "Bob"
                });
            });

            // OR

            var personsRealm = new PersonsRealmService();

            personsRealm.Write(() =>
            {
                personsRealm.Add(new Person {
                    Name = "Jan"
                });
                personsRealm.Add(new Person {
                    Name = "June"
                });
                personsRealm.Add(new Person {
                    Name = "Jinny"
                });
            });

            var persons = personsRealm.GetAll().ToList();

            personsRealm.Write(() =>
            {
                personsRealm.RemoveAll();
            });
        }
示例#10
0
        protected void RunEventTests()
        {
            var realmService    = RealmService.GetInstance <Models.Person>();
            var realmServiceTwo = RealmService.GetInstance <Models.Person>();

            realmService.WriteFinished += (sender, args) =>
            {
                var msg = "Woohoo!";
            };

            realmServiceTwo.WriteFinished += (sender, args) =>
            {
                var msg = "Woohoo!";
            };

            realmService.Write(() =>
            {
                realmService.Add(new Person {
                    Name = "Greg"
                });
                realmService.Add(new Person {
                    Name = "Jim"
                });
                realmService.Add(new Person {
                    Name = "Bob"
                });
            });

            realmServiceTwo.Write(() =>
            {
                realmService.Add(new Person {
                    Name = "Greg"
                });
                realmService.Add(new Person {
                    Name = "Jim"
                });
                realmService.Add(new Person {
                    Name = "Bob"
                });
            });
        }
示例#11
0
        public App()
        {
            // workaround for https://github.com/realm/realm-dotnet/issues/1967
            if (Xamarin.Forms.Device.RuntimePlatform != Xamarin.Forms.Device.iOS)
            {
                SyncConfigurationBase.Initialize(UserPersistenceMode.NotEncrypted);
            }

            VersionTracking.Track();

            var language = LanguageService.GetCurrentLanguage();

            AppResources.Culture = new CultureInfo(language.GetLanguageCode());

            if (!IsAppCtorCalled)
            {
                RealmService.InitializeOfflineDatabase();

                IsAppCtorCalled = true;
            }

            this.InitializeComponent();
            this.MainPage = new AppShell();
        }
示例#12
0
        public override async Task <ReadOnlyMemory <byte> > ExecuteCore(IKerberosMessage message, PreAuthenticationContext context)
        {
            // the logic for a TGS-REQ is relatively simple in the primary case where you have a TGT and want
            // to get a ticket to another service. It gets a bit more complicated when you need to do something
            // like a U2U exchange, renew, or get a referral to another realm. Realm referral isn't supported yet.

            // 1. Get the ApReq (TGT) from the PA-Data of the request
            // 2. Decrypt the TGT and extract the client calling identity
            // 3. Find the requested service principal
            // 4. Evaluate whether the client identity should get a ticket to the service
            // 5. Evaluate whether it should do U2U and if so extract that key instead
            // 6. Generate a service ticket for the calling client to the service
            // 7. return to client

            var tgsReq = (KrbTgsReq)message;

            logger.LogInformation("TGS-REQ incoming. SPN = {SPN}", tgsReq.Body.SName.FullyQualifiedName);

            var krbtgtIdentity = await RealmService.Principals.RetrieveKrbtgt();

            var krbtgtKey = await krbtgtIdentity.RetrieveLongTermCredential();

            var servicePrincipal = await RealmService.Principals.Find(tgsReq.Body.SName.FullyQualifiedName);

            // renewal is an odd case here because the SName will be krbtgt
            // does this need to be validated more than the Decrypt call?

            await EvaluateSecurityPolicy(context.Principal, servicePrincipal);

            KerberosKey serviceKey;

            if (tgsReq.Body.KdcOptions.HasFlag(KdcOptions.EncTktInSkey))
            {
                serviceKey = GetUserToUserTicketKey(tgsReq.Body.AdditionalTickets, krbtgtKey);
            }
            else
            {
                serviceKey = await servicePrincipal.RetrieveLongTermCredential();
            }

            var now = RealmService.Now();

            TicketFlags flags = 0;

            if (tgsReq.Body.KdcOptions.HasFlag(KdcOptions.Forwardable))
            {
                flags |= TicketFlags.Forwardable;
            }

            if (context.Ticket.Flags.HasFlag(TicketFlags.PreAuthenticated))
            {
                flags |= TicketFlags.PreAuthenticated;
            }

            var tgsRep = await KrbKdcRep.GenerateServiceTicket <KrbTgsRep>(
                new ServiceTicketRequest
            {
                Principal           = context.Principal,
                EncryptedPartKey    = context.EncryptedPartKey,
                ServicePrincipal    = servicePrincipal,
                ServicePrincipalKey = serviceKey,
                RealmName           = RealmService.Name,
                Addresses           = tgsReq.Body.Addresses,
                RenewTill           = context.Ticket.RenewTill,
                StartTime           = now - RealmService.Settings.MaximumSkew,
                EndTime             = now + RealmService.Settings.SessionLifetime,
                Flags      = flags,
                Now        = now,
                Nonce      = tgsReq.Body.Nonce,
                IncludePac = context.Ticket.AuthorizationData.Any(a => a.Type == AuthorizationDataType.AdIfRelevant)
            }
                );

            return(tgsRep.EncodeApplication());
        }
示例#13
0
        public override ReadOnlyMemory <byte> ExecuteCore(PreAuthenticationContext context)
        {
            // Now that we know who is requesting the ticket we can issue the ticket
            //
            // 3. Find the requested service principal
            // 4. Determine if the requested service principal is in another realm and if so refer them
            // 5. Evaluate whether the client identity should get a ticket to the service
            // 6. Evaluate whether it should do U2U and if so extract that key instead
            // 7. Generate a service ticket for the calling client to the service
            // 8. return to client

            var tgsReq = (KrbTgsReq)context.Message;

            if (context.ServicePrincipal == null)
            {
                // we can't find what they're asking for, but maybe it's in a realm we can transit?

                context.ServicePrincipal = ProposeTransitedRealm(tgsReq, context);
            }

            if (context.ServicePrincipal == null)
            {
                // we have no idea what service they're asking for and
                // there isn't a realm we can refer them to that can issue a ticket

                return(GenerateError(
                           KerberosErrorCode.KDC_ERR_S_PRINCIPAL_UNKNOWN,
                           "",
                           RealmService.Name,
                           tgsReq.Body.SName.FullyQualifiedName
                           ));
            }

            // renewal is an odd case here because the SName will be krbtgt
            // does this need to be validated more than the Decrypt call?

            EvaluateSecurityPolicy(context.Principal, context.ServicePrincipal);

            KerberosKey serviceKey;

            if (tgsReq.Body.KdcOptions.HasFlag(KdcOptions.EncTktInSkey))
            {
                serviceKey = GetUserToUserTicketKey(tgsReq.Body.AdditionalTickets, context);
            }
            else
            {
                serviceKey = context.ServicePrincipal.RetrieveLongTermCredential();
            }

            var now = RealmService.Now();

            TicketFlags flags = 0;

            if (tgsReq.Body.KdcOptions.HasFlag(KdcOptions.Forwardable))
            {
                flags |= TicketFlags.Forwardable;
            }

            if (context.Ticket.Flags.HasFlag(TicketFlags.PreAuthenticated))
            {
                flags |= TicketFlags.PreAuthenticated;
            }

            var includePac = DetectPacRequirement(tgsReq);

            if (includePac == null)
            {
                includePac = context.Ticket?.AuthorizationData?.Any(a => a.Type == AuthorizationDataType.AdIfRelevant) ?? false;
            }

            var tgsRep = KrbKdcRep.GenerateServiceTicket <KrbTgsRep>(
                new ServiceTicketRequest
            {
                KdcAuthorizationKey = context.EvidenceTicketKey,
                Principal           = context.Principal,
                EncryptedPartKey    = context.EncryptedPartKey,
                ServicePrincipal    = context.ServicePrincipal,
                ServicePrincipalKey = serviceKey,
                RealmName           = RealmService.Name,
                Addresses           = tgsReq.Body.Addresses,
                RenewTill           = context.Ticket.RenewTill,
                StartTime           = now - RealmService.Settings.MaximumSkew,
                EndTime             = now + RealmService.Settings.SessionLifetime,
                Flags      = flags,
                Now        = now,
                Nonce      = tgsReq.Body.Nonce,
                IncludePac = includePac ?? false
            }
                );

            return(tgsRep.EncodeApplication());
        }
示例#14
0
        public void RemoveTests()
        {
            // No Primary Key
            var countriesService = RealmService.GetInstance <Models.Country>();

            countriesService.Write(() =>
            {
                countriesService.RemoveAll();
                countriesService.Add(new Country {
                    Name = "Canada"
                });
            });
            var country1 = countriesService.Get(x => x.Name == "Canada");

            Assert.That(country1, Is.Not.Null);
            countriesService.Write(() =>
            {
                countriesService.Remove(countriesService.Get(x => x.Name == "Canada"));
            });
            country1 = countriesService.Get(x => x.Name == "Canada");
            Assert.That(country1, Is.Null);

            // Primary Key, String
            var paintingsService = RealmService.GetInstance <Models.Painting>();

            paintingsService.Write(() =>
            {
                paintingsService.RemoveAll();
                paintingsService.AddOrUpdate(new Painting {
                    Id = "One", Name = "Gregory"
                });
                paintingsService.AddOrUpdate(new Painting {
                    Id = "Two", Name = "Bertha"
                });
            });
            var painting1 = paintingsService.Find("One");
            var painting2 = paintingsService.Find("Two");

            Assert.That(painting1, Is.Not.Null);
            Assert.That(painting2, Is.Not.Null);
            paintingsService.Write(() =>
            {
                paintingsService.Remove("One");
                paintingsService.Remove("Two");
            });
            painting1 = paintingsService.Find("One");
            painting2 = paintingsService.Find("Two");
            Assert.That(painting1, Is.Null);
            Assert.That(painting2, Is.Null);
            paintingsService.Write(() =>
            {
                paintingsService.RemoveAll();
            });

            // Primary Key, AutoIncrement Disabled
            var animalsService = RealmService.GetInstance <Models.Animal>();

            animalsService.Write(() =>
            {
                animalsService.RemoveAll();
                animalsService.Add(new Animal {
                    Id = 3, Name = "Bertha"
                });
            });
            var animal1 = animalsService.Get(x => x.Name == "Bertha");

            Assert.That(animal1, Is.Not.Null);
            animalsService.Write(() =>
            {
                animalsService.Remove(animalsService.Get(x => x.Name == "Bertha"));
            });
            animal1 = animalsService.Get(x => x.Name == "Bertha");
            Assert.That(animal1, Is.Null);
            animalsService.Write(() =>
            {
                animalsService.RemoveAll();
            });

            // Primary Key, AutoIncrement Enabled
            var personsService = RealmService.GetInstance <Models.Person>();

            personsService.Write(() =>
            {
                personsService.RemoveAll();
                personsService.Add(new Person {
                    Name = "Gregory"
                });
            });
            var person1 = personsService.Get(x => x.Name == "Gregory");

            Assert.That(person1, Is.Not.Null);
            personsService.Write(() =>
            {
                personsService.Remove(personsService.Get(x => x.Name == "Gregory"));
            });
            person1 = personsService.Get(x => x.Name == "Gregory");
            Assert.That(person1, Is.Null);
            personsService.Write(() =>
            {
                personsService.RemoveAll();
            });
        }
示例#15
0
        protected override async Task <ReadOnlyMemory <byte> > ExecuteCore(IKerberosMessage message)
        {
            // the logic for a TGS-REQ is relatively simple in the primary case where you have a TGT and want
            // to get a ticket to another service. It gets a bit more complicated when you need to do something
            // like a U2U exchange, renew, or get a referral to another realm. Realm referral isn't supported yet.

            // 1. Get the ApReq (TGT) from the PA-Data of the request
            // 2. Decrypt the TGT and extract the client calling identity
            // 3. Find the requested service principal
            // 4. Evaluate whether the client identity should get a ticket to the service
            // 5. Evaluate whether it should do U2U and if so extract that key instead
            // 6. Generate a service ticket for the calling client to the service
            // 7. return to client

            var tgsReq = (KrbTgsReq)message;

            var apReq = ExtractApReq(tgsReq);

            var krbtgtIdentity = await RealmService.Principals.RetrieveKrbtgt();

            var krbtgtKey = await krbtgtIdentity.RetrieveLongTermCredential();

            var krbtgtApReqDecrypted = DecryptApReq(apReq, krbtgtKey);

            var principal = await RealmService.Principals.Find(krbtgtApReqDecrypted.Ticket.CName.FullyQualifiedName);

            var servicePrincipal = await RealmService.Principals.Find(tgsReq.Body.SName.FullyQualifiedName);

            // renewal is an odd case here because the SName will be krbtgt
            // does this need to be validated more than the Decrypt call?

            await EvaluateSecurityPolicy(principal, servicePrincipal, krbtgtApReqDecrypted);

            KerberosKey serviceKey;

            if (tgsReq.Body.KdcOptions.HasFlag(KdcOptions.EncTktInSkey))
            {
                serviceKey = GetUserToUserTicketKey(tgsReq.Body.AdditionalTickets, krbtgtKey);
            }
            else
            {
                serviceKey = await servicePrincipal.RetrieveLongTermCredential();
            }

            var now = RealmService.Now();

            var tgsRep = await KrbKdcRep.GenerateServiceTicket <KrbTgsRep>(
                new ServiceTicketRequest
            {
                Principal           = principal,
                EncryptedPartKey    = krbtgtApReqDecrypted.SessionKey,
                ServicePrincipal    = servicePrincipal,
                ServicePrincipalKey = serviceKey,
                RealmName           = RealmService.Name,
                Addresses           = tgsReq.Body.Addresses,
                RenewTill           = krbtgtApReqDecrypted.Ticket.RenewTill,
                StartTime           = now - RealmService.Settings.MaximumSkew,
                EndTime             = now + RealmService.Settings.SessionLifetime,
                Flags = KrbKdcRep.DefaultFlags,
                Now   = now
            }
                );

            return(tgsRep.EncodeApplication());
        }
示例#16
0
        private List <Grouping <string, AboutPageItem> > GetAboutItems()
        {
            var aboutPageItems = new List <Grouping <string, AboutPageItem> >();

            aboutPageItems.Add(new Grouping <string, AboutPageItem>(nameof(AppResources.Friends), new [] {
                new AboutPageItem
                {
                    AboutItemType = AboutItemType.Friends
                }
            }));

            aboutPageItems.Add(new Grouping <string, AboutPageItem>(nameof(AppResources.Subscriptions), new[] {
                new AboutPageItem
                {
                    AboutItemType = AboutItemType.Subscriptions
                }
            }));

            var communities = RealmService.Get <CommunityModel>();
            var sessions    = RealmService.Get <MeetupModel>();
            var communitiesWithFirstSessionDate = communities.Join(
                sessions,
                c => c.Id,
                s => s.CommunityID,
                (c, s) => new
            {
                Community        = c,
                FirstSessionDate = s.Sessions.OrderBy(session => session.StartTime).FirstOrDefault()?.StartTime
            }).OrderBy(x => x.FirstSessionDate).GroupBy(x => x.Community.Id).Select(x => x.First());

            aboutPageItems.Add(new Grouping <string, AboutPageItem>(nameof(AppResources.OurCommunities), communitiesWithFirstSessionDate.Select(x => new AboutPageItem
            {
                Community     = x.Community,
                AboutItemType = AboutItemType.Community
            })));

            var aboutAppItems = new []
            {
                new Model.MenuItem {
                    Name = nameof(AppResources.CreatedBy), Parameter = nameof(AppResources.CreatedBy)
                },
                new Model.MenuItem {
                    Name = nameof(AppResources.IssueTracker), Parameter = nameof(AppResources.IssueTracker)
                },
                new Model.MenuItem {
                    Name = nameof(AppResources.TechnologyUsed), Parameter = nameof(AppResources.TechnologyUsed)
                },
            };

            aboutPageItems.Add(new Grouping <string, AboutPageItem>(nameof(AppResources.AboutApp), aboutAppItems.Select(x => new AboutPageItem
            {
                MenuItem      = x,
                AboutItemType = AboutItemType.MenuItem
            })));

            aboutPageItems.Add(new Grouping <string, AboutPageItem>(nameof(AppResources.Settings), new [] {
                new AboutPageItem
                {
                    AboutItemType = AboutItemType.Settings
                }
            }));

            return(aboutPageItems);
        }