Example #1
0
        public void CheckAuthorization <TMessage>(IMessage message) where TMessage : IMessage
        {
            if (message is IAuthenticatedMessage)
            {
                var _securityRules = _dependencyContainer.ResolveSecurityRules <TMessage>();

                if (_securityRules != null)
                {
                    var authenticatedCommand = message as IAuthenticatedMessage;
                    foreach (var securityRule in _securityRules)
                    {
                        if (!securityRule.IsAuthorized(authenticatedCommand.Identity))
                        {
                            throw new UnauthorizedAccessException();
                        }
                    }
                }
            }
        }