Esempio n. 1
0
        public bool AssertUserHasToken(string userName, string token)
        {
            UserSearchCriteria whereUser = new UserSearchCriteria();
            whereUser.UserName.EqualTo(userName);

            AuthorityTokenSearchCriteria whereToken = new AuthorityTokenSearchCriteria();
            whereToken.Name.EqualTo(token);

            // want this to be as fast as possible - use joins and only select the count
            HqlQuery query = new HqlQuery("select count(*) from User u join u.AuthorityGroups g join g.AuthorityTokens t");
            query.Conditions.AddRange(HqlCondition.FromSearchCriteria("u", whereUser));
            query.Conditions.AddRange(HqlCondition.FromSearchCriteria("t", whereToken));

            // expect exactly one integer result
            return ExecuteHqlUnique<long>(query) > 0;
        }
        public bool AssertUserHasToken(string userName, string token)
        {
            UserSearchCriteria whereUser = new UserSearchCriteria();

            whereUser.UserName.EqualTo(userName);

            AuthorityTokenSearchCriteria whereToken = new AuthorityTokenSearchCriteria();

            whereToken.Name.EqualTo(token);

            // want this to be as fast as possible - use joins and only select the count
            HqlQuery query = new HqlQuery("select count(*) from User u join u.AuthorityGroups g join g.AuthorityTokens t");

            query.Conditions.AddRange(HqlCondition.FromSearchCriteria("u", whereUser));
            query.Conditions.AddRange(HqlCondition.FromSearchCriteria("t", whereToken));

            // expect exactly one integer result
            return(ExecuteHqlUnique <long>(query) > 0);
        }
Esempio n. 3
0
        protected override void Import(AuthorityGroupData data, IUpdateContext context)
        {
            AuthorityGroup group = LoadOrCreateGroup(data.Name, context);

            group.Description = data.Description;
            group.DataGroup   = data.DataGroup;
            if (data.Tokens != null)
            {
                foreach (string token in data.Tokens)
                {
                    AuthorityTokenSearchCriteria where = new AuthorityTokenSearchCriteria();
                    where.Name.EqualTo(token);

                    AuthorityToken authToken = CollectionUtils.FirstElement(context.GetBroker <IAuthorityTokenBroker>().Find(where));
                    if (authToken != null)
                    {
                        group.AuthorityTokens.Add(authToken);
                    }
                }
            }
        }
Esempio n. 4
0
        internal void UpdateAuthorityGroup(AuthorityGroup authorityGroup, AuthorityGroupDetail detail, IPersistenceContext persistenceContext)
        {
            authorityGroup.Name        = detail.Name;
            authorityGroup.Description = detail.Description;
            authorityGroup.DataGroup   = detail.DataGroup;
            authorityGroup.AuthorityTokens.Clear();

            if (detail.AuthorityTokens.Count > 0)
            {
                // process authority tokens
                List <string> tokenNames = CollectionUtils.Map <AuthorityTokenSummary, string>(
                    detail.AuthorityTokens,
                    token => token.Name);

                AuthorityTokenSearchCriteria where = new AuthorityTokenSearchCriteria();
                where.Name.In(tokenNames);
                IList <AuthorityToken> authTokens = persistenceContext.GetBroker <IAuthorityTokenBroker>().Find(where);

                authorityGroup.AuthorityTokens.AddAll(authTokens);
            }
        }
        internal void UpdateAuthorityGroup(AuthorityGroup authorityGroup, AuthorityGroupDetail detail, IPersistenceContext persistenceContext)
        {
            authorityGroup.Name = detail.Name;
            authorityGroup.Description = detail.Description;
            authorityGroup.DataGroup = detail.DataGroup;
			authorityGroup.AuthorityTokens.Clear();

			if (detail.AuthorityTokens.Count > 0)
			{
				// process authority tokens
				List<string> tokenNames = CollectionUtils.Map<AuthorityTokenSummary, string>(
					detail.AuthorityTokens,
					token => token.Name);

				AuthorityTokenSearchCriteria where = new AuthorityTokenSearchCriteria();
				where.Name.In(tokenNames);
				IList<AuthorityToken> authTokens = persistenceContext.GetBroker<IAuthorityTokenBroker>().Find(where);

				authorityGroup.AuthorityTokens.AddAll(authTokens);
			}
        }