public void HasStatelessAccessDenied() { Expect.Call(_mockWxeSecurityAdapter.HasStatelessAccess(typeof(TestFunction))).Return(false); _mockRepository.ReplayAll(); bool hasAccess = WxeFunction.HasAccess(typeof(TestFunction)); _mockRepository.VerifyAll(); Assert.That(hasAccess, Is.False); }
public void HasAccess_ViaDomainObjectParameter_WithFunctionalHasAccessFalse_ReturnsFalse() { FunctionalSecurityStrategyStub .Stub( stub => stub.HasAccess( Arg.Is(typeof(SecurableDomainObject)), Arg.Is(SecurityProviderStub), Arg.Is(SecurityPrincipalStub), Arg <IReadOnlyList <AccessType> > .List.Equal(new[] { TestAccessTypeValue }))) .Return(false); Assert.That(WxeFunction.HasAccess(typeof(FunctionWithSecuredDomainObjectParameter)), Is.False); }
// methods and properties public bool HasAccess(ISecurableObject securableObject, Delegate handler) { if (handler == null) { return(true); } if (SecurityFreeSection.IsActive) { return(true); } List <DemandTargetPermissionAttribute> attributes = GetPermissionAttributes(handler.GetInvocationList()); bool hasAccess = true; foreach (DemandTargetPermissionAttribute attribute in attributes) { switch (attribute.PermissionSource) { case PermissionSource.WxeFunction: hasAccess &= WxeFunction.HasAccess(attribute.FunctionType); break; case PermissionSource.SecurableObject: SecurityClient securityClient = SecurityClient.CreateSecurityClientFromConfiguration(); if (securableObject == null) { hasAccess &= securityClient.HasStatelessMethodAccess(attribute.SecurableClass, attribute.MethodName); } else { hasAccess &= securityClient.HasMethodAccess(securableObject, attribute.MethodName); } break; default: throw new InvalidOperationException(string.Format( "Value '{0}' is not supported by the PermissionSource property of the DemandTargetPermissionAttribute.", attribute.PermissionSource)); } if (!hasAccess) { break; } } return(hasAccess); }
public void HasStatelessAccessGrantedWithoutWxeSecurityProvider() { var serviceLocator = DefaultServiceLocator.Create(); serviceLocator.RegisterMultiple <IWxeSecurityAdapter>(); using (new ServiceLocatorScope(serviceLocator)) { _mockRepository.ReplayAll(); bool hasAccess = WxeFunction.HasAccess(typeof(TestFunction)); _mockRepository.VerifyAll(); Assert.That(hasAccess, Is.True); } }