Пример #1
0
        public static bool IsInRole(this IPrincipal principal, IEnumerable<Role> roles, Account account)
        {
            if (account == null || account.Role.Name.Equals("NotAuthenticated"))
                return false;

            return roles.Any(role => account.Role.Equals(role));
        }
Пример #2
0
 public void CreateAccount(Account account)
 {
     using (var gateway = AccountsGatewayFactory())
     {
         gateway.CreateAccount(account);
     }
 }
Пример #3
0
 private BusinessRuleDescription GenerateRule(Type type, Account account, string name)
 {
     return new BusinessRuleDescription
     {
         ExternalId = Guid.NewGuid(),
         Description = string.Format("Rule for {1} {0}", type.Name, name),
         Name = string.Format("{0}Rule", type.Name),
         Group = BusinessRuleGroup.Permissions,
         Script = string.Empty,
         AccountTestData = new BusinessRuleAccountTestData
         {
             ExternalId = Guid.NewGuid(),
             JsonData = Serialization.ToJson(account)
         },
         Parameters = new List<BusinessRuleParameter>
         {
             new BusinessRuleParameter
             {
                 ExternalId = Guid.NewGuid(),
                 Name = name,
                 Type = type.FullName,
                 TestData = new BusinessRuleTestData
                 {
                     ExternalId = Guid.NewGuid(),
                     JsonData = ApiDescriptionBuilder.FormatType(type, 0, null)
                 }
             }
         }
     };
 }
        public bool Apply(INotificationFilterByNotRequestor filter, Account account, List<Subscription> subscriptions)
        {
            var result = null != subscriptions.SelectMany(o => o.Filters)
                .FirstOrDefault(o => account.ExternalId != filter.RequestorId);

            return result;
        }
        public bool Apply(INotificationFilterForUser filter, Account account, List<Subscription> subscriptions)
        {
            Guid v;

            var result = null != subscriptions.SelectMany(o => o.Filters)
                .Where(o => Guid.TryParse(o.Value, out v))
                .FirstOrDefault(o => filter.AccountId != Guid.Empty && account.ExternalId == filter.AccountId);

            return result;
        }
Пример #6
0
 public RequestPrincipal(Account account)
 {
     if (account != null)
     {
         _account = account;
         Identity = new GenericIdentity(account.Email, "Token");
     }
     else
         Identity = new GenericIdentity(string.Empty);
 }
Пример #7
0
        public Account Authenticate(HttpActionContext actionContext)
        {
            _account = GetAccount(actionContext);
            if (_account != null)
                _principal = new RequestPrincipal(_account);
            else
                _principal = new GenericPrincipal(new GenericIdentity(string.Empty), new string[0]);

            PrincipalSetter.SetPrincipal(_principal, actionContext);
            return _account;
        }
        public bool Apply(INotificationFilterByReleaseWindowIdNotRequestor filter, Account account, List<Subscription> subscriptions)
        {
            Guid v;

            var result = null != subscriptions.SelectMany(o => o.Filters)
                .Where(o => o.Property.Equals(filter.PropertyName(p => p.ReleaseWindowId), StringComparison.InvariantCultureIgnoreCase))
                .Where(o => Guid.TryParse(o.Value, out v))
                .Where(o => account.ExternalId != filter.RequestorId)
                .FirstOrDefault(o => Guid.Parse(o.Value) == filter.ReleaseWindowId);

            return result;
        }
        public bool Apply(INotificationFilterByProduct filter, Account account, List<Subscription> subscriptions)
        {
            var productsLocal = filter.Products.ToArray();

            var t = subscriptions.SelectMany(o => o.Filters)
                .Where(
                    o =>
                        o.Property.Equals(filter.PropertyName(p => p.Products),
                            StringComparison.InvariantCultureIgnoreCase))
                .ToArray();

            Console.WriteLine(t.ToString());

            var result = null !=
                subscriptions.SelectMany(o => o.Filters)
                    .Where(o => o.Property.Equals(filter.PropertyName(p => p.Products), StringComparison.InvariantCultureIgnoreCase))
                    .FirstOrDefault(o => IsStringProductContainsProductItems(o.Value, productsLocal));

            return result;
        }
 public bool Apply(INotificationFilter filter, Account account, List<Subscription> subscriptions)
 {
     return true;
 }