Пример #1
0
 public RenderPartialExpression <TViewModel> RequiresAccessTo(params string[] roles)
 {
     if (_isAuthorized)
     {
         _isAuthorized = PrincipalRoles.IsInRole(roles);
     }
     return(this);
 }
Пример #2
0
        public void authorized_link_to_positive_directly_against_endpoint_service()
        {
            execute(page => {
                PrincipalRoles.SetCurrentRolesForTesting("Role1");

                return(page.AuthorizedLinkTo(svc => svc.EndpointFor <ConventionEndpoint>(x => x.get_authorized_data())));
            });

            theResult.ShouldEqual("<a href=\"/authorized/data\"></a>");
        }
Пример #3
0
        public void authorized_link_to_negative_directly_against_endpoint_service()
        {
            execute(page =>
            {
                PrincipalRoles.SetCurrentRolesForTesting("Role2");

                return(page.AuthorizedLinkTo(svc => svc.EndpointFor <ConventionEndpoint>(x => x.get_authorized_data())));
            });

            theResult.ShouldBe(string.Empty);
        }
Пример #4
0
        public void read_role_off_principal()
        {
            var principal = new GenericPrincipal(new GenericIdentity("somebody"), new string[] { "a", "b" });

            Thread.CurrentPrincipal = principal;

            PrincipalRoles.Current.ShouldBeTheSameAs(principal);

            PrincipalRoles.IsInRole("a").ShouldBeTrue();
            PrincipalRoles.IsInRole("c").ShouldBeFalse();
        }
Пример #5
0
        public void link_to_by_input_model_that_passes_authorization()
        {
            execute(page => {
                PrincipalRoles.SetCurrentRolesForTesting("Role1");

                return(page.LinkTo(new SecuredInput {
                    Name = "Max"
                }));
            });

            theResult.ShouldEqual("<a href=\"/secured/by/role/Max\"></a>");
        }
Пример #6
0
        public void link_to_by_input_model_that_does_not_pass_authorization()
        {
            execute(page =>
            {
                PrincipalRoles.SetCurrentRolesForTesting("Role2");

                return(page.LinkTo(new SecuredInput {
                    Name = "Max"
                }));
            });

            theResult.ShouldBeEmpty();
        }
Пример #7
0
 public FormLineExpression <T> EditableForRole(params string[] roles)
 {
     return(Editable(PrincipalRoles.IsInRole(roles)));
 }
 public void SetUp()
 {
     PrincipalRoles.SetCurrentRolesForTesting("a", "b");
 }
Пример #9
0
        public void edit_if_the_user_does_not_have_a_role()
        {
            PrincipalRoles.SetCurrentRolesForTesting();

            expression.EditableForRole("admin").ToString().ShouldNotContain("input");
        }
Пример #10
0
        // TODO -- will need something more generic later.  Maybe.
        public ExtensionsExpression OnlyForRoles(params string[] roles)
        {
            Func <bool> filter = () => PrincipalRoles.IsInRole(roles);

            return(register(g => g.FilterLast(filter)));
        }
Пример #11
0
 public static HtmlTag RequiresAccessTo(this HtmlTag tag, params string[] roleName)
 {
     return(tag.Authorized(tag.Authorized() && PrincipalRoles.IsInRole(roleName)));
 }
Пример #12
0
 public static bool CanView(Type type)
 {
     return(PrincipalRoles.IsInRole(SecurableNameForViewing(type)));
 }
Пример #13
0
 public static bool CanCreate(Type type)
 {
     return(PrincipalRoles.IsInRole(SecurableNameForCreation(type)));
 }