public void Test_AccessGranted() { _testHelper.ExpectPermissionReflectorGetRequiredMethodPermissions(_methodInformation, TestAccessTypes.First); _testHelper.ExpectFunctionalSecurityStrategyHasAccess(TestAccessTypes.First, true); _testHelper.ReplayAll(); bool hasAccess = _securityClient.HasStatelessMethodAccess(typeof(SecurableObject), _methodInformation); _testHelper.VerifyAll(); Assert.That(hasAccess, Is.True); }
// 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 Test_AccessGranted() { _testHelper.ReplayAll(); bool hasAccess = _securityClient.HasStatelessMethodAccess(typeof(SecurableObject), "Show"); _testHelper.VerifyAll(); Assert.That(hasAccess, Is.True); }
public void HasAccess_StatelessMethod() { var securityContext = SecurityContext.CreateStateless(typeof(SecurableObject)); var securityContextFactoryStub = MockRepository.GenerateStub <ISecurityContextFactory>(); securityContextFactoryStub.Stub(mock => mock.CreateSecurityContext()).Return(securityContext); _securityProviderStub .Stub(mock => mock.GetAccess(securityContext, _securityPrincipalStub)) .Return(new[] { AccessType.Get(GeneralAccessTypes.Delete) }); var securityClient = new SecurityClient( _securityProviderStub, new PermissionReflector(), _principalProviderStub, new FunctionalSecurityStrategy(), new ReflectionBasedMemberResolver()); var methodInfo = typeof(SecurableObject).GetMethod("Delete", new Type[0]); var hasMethodAccess = securityClient.HasStatelessMethodAccess(typeof(SecurableObject), methodInfo); Assert.That(hasMethodAccess, Is.True); }
public bool HasStatelessAccess(Type functionType) { ArgumentUtility.CheckNotNullAndTypeIsAssignableFrom("functionType", functionType, typeof(WxeFunction)); if (SecurityFreeSection.IsActive) { return(true); } WxeDemandTargetPermissionAttribute attribute = GetPermissionAttribute(functionType); if (attribute == null) { return(true); } WxeDemandMethodPermissionAttributeHelper helper = new WxeDemandMethodPermissionAttributeHelper(functionType, attribute); SecurityClient securityClient = SecurityClient.CreateSecurityClientFromConfiguration(); switch (helper.MethodType) { case MethodType.Instance: return(securityClient.HasStatelessMethodAccess(helper.GetTypeOfSecurableObject(), helper.MethodName)); case MethodType.Static: return(securityClient.HasStaticMethodAccess(helper.SecurableClass, helper.MethodName)); case MethodType.Constructor: return(securityClient.HasConstructorAccess(helper.SecurableClass)); default: throw new InvalidOperationException(string.Format( "Value '{0}' is not supported by the MethodType property of the WxeDemandMethodPermissionAttribute.", helper.MethodType)); } }