コード例 #1
0
        private void btnRoles_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                txtRoles.Text = String.Empty;

                SLPrincipal.Logout();
                SLPrincipal.Login("TestUser", "1234", (o, e2) =>
                {
                    if (Csla.ApplicationContext.User.IsInRole("User") &&
                        Csla.ApplicationContext.User.IsInRole("Admin") &&
                        !Csla.ApplicationContext.User.IsInRole("invalidrole"))
                    {
                        txtRoles.Text = "Pass";
                    }
                    else
                    {
                        txtRoles.Text = "Fail";
                    }
                });
            }
            catch
            {
                txtRoles.Text = "Fail";
            }
        }
コード例 #2
0
        private void btnSuccessfulLogin_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                txtSuccessfulLogin.Text = String.Empty;

                SLPrincipal.Logout();
                SLPrincipal.Login("TestUser", "1234", (o, e2) =>
                {
                    if (Csla.ApplicationContext.User.Identity.Name == "TestUser" &&
                        Csla.ApplicationContext.User.Identity.IsAuthenticated)
                    {
                        txtSuccessfulLogin.Text = "Pass";
                    }
                    else
                    {
                        txtSuccessfulLogin.Text = "Fail";
                    }
                });
            }
            catch (Exception ex)
            {
                txtSuccessfulLogin.Text = "Fail " + ex.Message;;
            }
        }
コード例 #3
0
ファイル: Page.xaml.cs プロジェクト: RobRobertsCE/MVVM
        private void btnAuthorizationB_Click(object sender, RoutedEventArgs e)
        {
            txtAuthorizationB.Text = String.Empty;

            SLPrincipal.Logout();
            SLPrincipal.Login("TestUser", "1234", "ClassARole", (o, e2) =>
            {
                bool pass = true;

                try
                {
                    ClassA classA = new ClassA();
                    try
                    {
                        classA.A = "test";
                        pass     = false;
                    }
                    catch (SecurityException ex)
                    { }
                    classA.B = "test";
                    if (classA.B != "test")
                    {
                        pass = false;
                    }

                    ClassB classB = new ClassB();
                    try
                    {
                        classB.A = "test";
                        pass     = false;
                    }
                    catch (SecurityException ex)
                    { }
                    classB.B = "test";
                    if (classB.B != "test")
                    {
                        pass = false;
                    }
                }
                catch (Exception ex)
                {
                    pass = false;
                }

                if (pass)
                {
                    txtAuthorizationB.Text = "Pass";
                }
                else
                {
                    txtAuthorizationB.Text = "Fail";
                }
            });
        }
コード例 #4
0
ファイル: Page.xaml.cs プロジェクト: RobRobertsCE/MVVM
        private void btnContextTest_Click(object sender, RoutedEventArgs e)
        {
            txtAuthorizationD.Text = String.Empty;
            bool pass = true;

            SLPrincipal.Logout();
            SLPrincipal.Login("TestUser", "1234", "ClassARole;PropertyARole", (o, e2) =>
            {
                Csla.ApplicationContext.GlobalContext["Test"]       = "testValue";
                Csla.ApplicationContext.ClientContext["TestClient"] = "testClientValue";
                ClassA.Fetch((o3, e3) =>
                {
                    try
                    {
                        if (e3.Object == null || e3.Error != null || (e3.Object.A != "test" && e3.Object.B != "test"))
                        {
                            pass = false;
                        }
                        if (pass)
                        {
                            if ((string)Csla.ApplicationContext.GlobalContext["Test"] != "GlobalChangedByPortal")
                            {
                                pass = false;
                            }
                            if ((string)Csla.ApplicationContext.ClientContext["TestClient"] != "testClientValue")
                            {
                                pass = false;
                            }
                            if (e3.Object.GlobalContext != "testValue")
                            {
                                pass = false;
                            }
                            if (e3.Object.ClientContext != "testClientValue")
                            {
                                pass = false;
                            }
                        }
                        if (pass)
                        {
                            txtContextTest.Text = "Pass";
                        }
                        else
                        {
                            txtContextTest.Text = "Fail";
                        }
                    }
                    catch (Exception ex)
                    {
                        txtContextTest.Text = "Fail";
                    }
                });
            });
        }
コード例 #5
0
ファイル: Page.xaml.cs プロジェクト: RobRobertsCE/MVVM
        private void btnAuthorizationC_Click(object sender, RoutedEventArgs e)
        {
            txtAuthorizationC.Text = String.Empty;

            SLPrincipal.Logout();
            SLPrincipal.Login("TestUser", "1234", "PropertyARole", (o, e2) =>
            {
                bool pass = true;
                try
                {
                    ClassB classB = new ClassB();
                    classB.A      = "test";
                    classB.B      = "test";
                    if (classB.A != "test" || classB.B != "test")
                    {
                        pass = false;
                    }
                    if (pass == true)
                    {
                        ClassA classA = new ClassA();
                        classA.A      = "test";
                        classA.B      = "test";
                        classA.Saved += ((savedObj, savedArgs) =>
                        {
                            if (savedArgs.Error != null)
                            {
                                txtAuthorizationC.Text = "Pass";
                            }
                            else
                            {
                                txtAuthorizationC.Text = "Fail";
                            };
                        }
                                         );
                        classA.BeginSave();
                    }
                    else
                    {
                        txtAuthorizationC.Text = "Fail";
                    }
                }
                catch (Exception ex)
                {
                    txtAuthorizationC.Text = "Fail";
                }
            }
                              );
        }
コード例 #6
0
ファイル: Page.xaml.cs プロジェクト: RobRobertsCE/MVVM
        private void btnAuthorizationD_Click(object sender, RoutedEventArgs e)
        {
            txtAuthorizationD.Text = String.Empty;

            SLPrincipal.Logout();
            SLPrincipal.Login("", (o, e2) =>
            {
                bool pass = true;

                try
                {
                    try
                    {
                        ClassD1 classD1 = new ClassD1();
                        pass            = false;
                    }
                    catch (SecurityException ex)
                    { }

                    ClassD2 classD2 = new ClassD2();
                    try
                    {
                        classD2.A = "test";
                        pass      = false;
                    }
                    catch (SecurityException ex)
                    { }
                    classD2.B = "test";
                    if (classD2.B != "test")
                    {
                        pass = false;
                    }
                }
                catch (Exception ex)
                {
                    pass = false;
                }

                if (pass)
                {
                    txtAuthorizationD.Text = "Pass";
                }
                else
                {
                    txtAuthorizationD.Text = "Fail";
                }
            });
        }
コード例 #7
0
ファイル: Page.xaml.cs プロジェクト: RobRobertsCE/MVVM
 private void btnSuccessfulLogin_Click(object sender, RoutedEventArgs e)
 {
     txtSuccessfulLogin.Text = String.Empty;
     SLPrincipal.Logout();
     SLPrincipal.Login((o, e2) =>
     {
         if (Csla.ApplicationContext.User.Identity.IsAuthenticated)
         {
             txtSuccessfulLogin.Text = "Pass";
         }
         else
         {
             txtSuccessfulLogin.Text = "Fail";
         }
     });
 }
コード例 #8
0
ファイル: Page.xaml.cs プロジェクト: RobRobertsCE/MVVM
        private void btnRolesUnsuccessful_Click(object sender, RoutedEventArgs e)
        {
            txtRolesUnsuccessful.Text = String.Empty;

            SLPrincipal.Logout();
            SLPrincipal.Login((o, e2) =>
            {
                if (!Csla.ApplicationContext.User.IsInRole("shouldNotMatch"))
                {
                    txtRolesUnsuccessful.Text = "Pass";
                }
                else
                {
                    txtRolesUnsuccessful.Text = "Fail";
                }
            });
        }
コード例 #9
0
ファイル: Page.xaml.cs プロジェクト: RobRobertsCE/MVVM
        private void btnUnsuccessfulLogin_Click(object sender, RoutedEventArgs e)
        {
            txtUnsuccessfulLogin.Text = String.Empty;

            SLPrincipal.Logout();
            SLPrincipal.Login("invaliduser", "invalidpassword", "", (o, e2) =>
            {
                if (Csla.ApplicationContext.User.Identity.GetType() == typeof(Csla.Security.UnauthenticatedIdentity) &&
                    !((SLPrincipal.LoginEventArgs)e2).LoginSucceded)
                {
                    txtUnsuccessfulLogin.Text = "Pass";
                }
                else
                {
                    txtUnsuccessfulLogin.Text = "Fail";
                }
            });
        }
コード例 #10
0
ファイル: Page.xaml.cs プロジェクト: RobRobertsCE/MVVM
        private void btnAuthorizationA_Click(object sender, RoutedEventArgs e)
        {
            txtAuthorizationA.Text = String.Empty;

            SLPrincipal.Logout();
            SLPrincipal.Login("ClassARole;PropertyARole", (o, e2) =>
            {
                bool pass = true;

                try
                {
                    ClassA1 classA1 = new ClassA1();
                    classA1.A       = "test";
                    classA1.B       = "test";
                    if (classA1.A != "test" || classA1.B != "test")
                    {
                        pass = false;
                    }

                    ClassA2 classA2 = new ClassA2();
                    classA2.A       = "test";
                    classA2.B       = "test";
                    if (classA2.A != "test" || classA2.B != "test")
                    {
                        pass = false;
                    }
                }
                catch (Exception ex)
                {
                    pass = false;
                }

                if (pass)
                {
                    txtAuthorizationA.Text = "Pass";
                }
                else
                {
                    txtAuthorizationA.Text = "Fail";
                }
            });
        }
コード例 #11
0
        private void btnAuthorizationD_Click(object sender, RoutedEventArgs e)
        {
            txtAuthorizationD.Text = String.Empty;

            SLPrincipal.Logout();
            SLPrincipal.Login("TestUserD", "1234", (o, e2) =>
            {
                bool pass = true;

                var identity = Csla.ApplicationContext.User.Identity as SLIdentity;

                if (identity != null)
                {
                    if (identity.Name != "TestUserD")
                    {
                        pass = false;
                    }
                    if (identity.Extra != "Extra data")
                    {
                        pass = false;
                    }
                    if (identity.MoreData != "Even more data")
                    {
                        pass = false;
                    }
                }
                else
                {
                    pass = false;
                }

                if (pass)
                {
                    txtAuthorizationD.Text = "Pass";
                }
                else
                {
                    txtAuthorizationD.Text = "Fail";
                }
            });
        }
コード例 #12
0
ファイル: Page.xaml.cs プロジェクト: RobRobertsCE/MVVM
        private void btnAuthorizationA_Click(object sender, RoutedEventArgs e)
        {
            txtAuthorizationA.Text = String.Empty;

            SLPrincipal.Logout();
            SLPrincipal.Login("TestUser", "1234", "ClassARole;PropertyARole", (o, e2) =>
            {
                bool pass = true;

                try
                {
                    ClassA classA = new ClassA();
                    classA.A      = "test";
                    classA.B      = "test";
                    if (classA.A != "test" || classA.B != "test")
                    {
                        pass = false;
                    }

                    if (!pass)
                    {
                        throw new Exception();
                    }

                    ClassA.Fetch((o3, e3) =>
                    {
                        try
                        {
                            if (e3.Object == null || (e3.Object.A != "test" && e3.Object.B != "test"))
                            {
                                pass = false;
                            }

                            ClassB classB = new ClassB();
                            classB.A      = "test";
                            classB.B      = "test";
                            if (classB.A != "test" || classB.B != "test")
                            {
                                pass = false;
                            }

                            if (pass)
                            {
                                txtAuthorizationA.Text = "Pass";
                            }
                            else
                            {
                                txtAuthorizationA.Text = "Fail";
                            }
                        }
                        catch (Exception ex)
                        {
                            txtAuthorizationA.Text = "Fail";
                        }
                    });
                }
                catch (Exception ex)
                {
                    pass = false;
                }
            });
        }