Пример #1
0
        //      internal ss.User GetSuplexUser(bool resolve)
        //{
        //	return this.GetSuplexUser( resolve, true );
        //}

        internal ss.User GetSuplexUser(string userName, bool resolve = false, bool resolveRls = true)
        {
            ss.User user = new ss.User()
            {
                Name = userName,
                CreateUnresolvedName = true
            };
            if (resolve)
            {
                user.DataAccessor = _da;

                //this is just for the option of avoiding the AD lookup
                if (resolveRls)
                {
                    ExternalGroupInfo egi = new ExternalGroupInfo(LdapRoot, true, GlobalExternalGroupsCsv);
                    egi.BuildGroupsList(userName);

                    sg.SqlResult result = user.ResolveByName(true, egi.GroupsList);
                    //sometimes multithreaded requests to create a new user get too close together, causing a dup-username error
                    //this is a cheap retry
                    if (result.SqlException != null)
                    {
                        if (result.SqlException.Number == 2601)  //2601 == duplicate value error
                        {
                            System.Threading.Thread.Sleep(500);
                            result = user.ResolveByName(true, egi.GroupsList);
                        }

                        //if err not duplicate or it still didn't work in retry, throw the exeption
                        if (result.SqlException != null)
                        {
                            throw result.SqlException;
                        }
                    }
                }
                else
                {
                    user.ResolveByName();
                }
            }

            if (user.RlsMask == null)
            {
                user.RlsMask = new byte[] { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
            }

            return(user);
        }
Пример #2
0
        /// <summary>
        /// Selects and loads security for the given UniqueName into a SplxRecordManager
        /// </summary>
        /// <param name="uniqueName"></param>
        /// <returns>A loaded and resolved SplxRecordManager</returns>
        SplxSecureManagerBase GetSecureManagerSecurityRecurseUp(string userName, AceType aceType, string uniqueName, SecurityLoadParameters slp)
        {
            string          rootUniqueName = ContainerRootUniqueName;
            SecureContainer root           = new SecureContainer()
            {
                UniqueName = rootUniqueName
            };

            #region setup SecurityLoadParameters, load ExternalGroupInfo
            if (slp == null)
            {
                slp = new SecurityLoadParameters()
                {
                    ExternalGroupInfo = new ExternalGroupInfo(LdapRoot, true, GlobalExternalGroupsCsv),
                    User = this.GetSuplexUser(userName)
                }
            }
            ;

            ExternalGroupInfo egi =
                new ExternalGroupInfo(LdapRoot, true, GlobalExternalGroupsCsv);
            egi.BuildGroupsList(slp.User.Name);
            #endregion

            SecureContainer       ctrl    = root;
            SplxSecureManagerBase context = null;

            #region IsFileStore = true
            if (IsFileStore)
            {
                context = new SplxRecordManager()
                {
                    UniqueName = uniqueName
                };
                if (aceType == AceType.FileSystem)
                {
                    context = new SplxFileSystemManager()
                    {
                        UniqueName = uniqueName
                    }
                }
                ;

                splxApi.UIElement uie = _splxStore.UIElements.GetByUniqueNameRecursiveIgnoreCase(uniqueName);
                if (uie == null)
                {
                    throw new SecurityException($"Could not find security element [{uniqueName}] in the permissione configuration.");
                }


                ISecureControl curr      = context;
                IObjectModel   parentObj = uie.ParentObject;
                while (parentObj != null)
                {
                    SecureContainer par = new SecureContainer()
                    {
                        UniqueName = ((splxApi.UIElement)parentObj).UniqueName
                    };
                    par.Children.Add(curr);
                    curr = par;

                    parentObj = parentObj.ParentObject;
                }

                curr.Security.Load(_splxStore, slp);
            }
            #endregion
            #region IsFileStore = false
            else
            {
                DataSet ds = _da.GetDataSet("splx.splx_dal_sel_security_byuserbyuie_up",
                                            new System.Collections.sSortedList(
                                                "@UIE_UNIQUE_NAME", uniqueName,
                                                "@SPLX_USER_ID", slp.User.Id,
                                                "@EXTERNAL_GROUP_LIST", egi.GroupsList));

                _da.NameTablesFromCompositeSelect(ref ds);

                //todo, when suplex is ready
                //DataSet ds = _splxApi.GetSecurity( rootUniqueName, slp.User, slp.ExternalGroupInfo, future:recurseUp );

                DataTable acl  = ds.Tables["AclInfo"];
                DataRow[] rows = acl.Select(string.Format("UIE_UNIQUE_NAME = '{0}'", rootUniqueName));
                if (rows.Length > 0)
                {
                    rows = acl.Select(string.Format("UIE_PARENT_ID = '{0}'", rows[0]["SPLX_UI_ELEMENT_ID"]));
                }

                while (rows.Length > 0)
                {
                    string un = rows[0]["UIE_UNIQUE_NAME"].ToString();
                    if (un.StartsWith(ContainerUniqueNamePrefix))
                    {
                        context = new SplxRecordManager()
                        {
                            UniqueName = un
                        };
                        if (aceType == AceType.FileSystem)
                        {
                            context = new SplxFileSystemManager()
                            {
                                UniqueName = un
                            }
                        }
                        ;

                        ctrl.Children.Add(context);
                    }
                    else
                    {
                        SecureContainer child = new SecureContainer()
                        {
                            UniqueName = un
                        };
                        ctrl.Children.Add(child);
                        ctrl = child;
                    }

                    rows = acl.Select(string.Format("UIE_PARENT_ID = '{0}'", rows[0]["SPLX_UI_ELEMENT_ID"]));
                }

                root.Security.Load(ds, slp);
            }
            #endregion


            return(context);
        }