Exemplo n.º 1
0
        // es-4959 - new syntax for security clause -- called iff (Sys.SecurityInEngine() == true) --
        // _RightsAsSqlStrXb ::= CHECKACLS('AccessLists="accesslist1,accesslist2,...", DeniedLists="deniedlist1,..."{%F%}') FOR('identity1',...) OPTIONAL('opt_identity1',...) VIRTUAL('virt_identity1',...)
        // where {%F%} is the placeholder for ",FieldRightsAsTextPartWeights="true""
        // when Query.RespectFieldPermissions or Session.Profile.RespectFieldPermissions are true
        private static string RightsAsSqlStrXb(string userId, ListStr otherIdentities, ListStr otherVirtualIdentities)
        {
            if (Str.IsEmpty(userId))
            {
                return(null);
            }
            int deniedcount = CC.Current.Global.DeniedListCount;
            int accesscount = CC.Current.Global.AccessListCount;

            if (accesscount + deniedcount == 0)
            {
                return(null);
            }

            StringBuilder sb = new StringBuilder();

            sb.Append("CHECKACLS('");
            if (accesscount > 0)
            {
                sb.Append("accesslists=\"");
                // accesslist1,accesslist2...
                for (int accessindex = 1; accessindex <= accesscount; accessindex++)
                {
                    if (accessindex > 1)
                    {
                        sb.Append(',');
                    }
                    sb.Append("accesslist"); sb.Append(Sys.ToStr(accessindex));
                }
                sb.Append('"');
            }

            if (deniedcount > 0)
            {
                if (accesscount > 0)
                {
                    sb.Append(',');
                }
                sb.Append("deniedlists=\"");
                // deniedlist1,deniedlist2...
                for (int deniedindex = 1; deniedindex <= deniedcount; deniedindex++)
                {
                    if (deniedindex > 1)
                    {
                        sb.Append(',');
                    }
                    sb.Append("deniedlist"); sb.Append(Sys.ToStr(deniedindex));
                }
                sb.Append('"');
            }

            //sb.Append("{%F%}"); // either ",FieldRightsAsTextPartWeights=\"true\"" or ""

            // add userId.... (required) ; es-5480 - quote ids with Str.SqlValue()
            sb.Append("') FOR ("); sb.Append(Str.SqlValue(userId)); sb.Append(")");

            // add other identities (optional) ....
            int nOptional = ListStr.GetCount(otherIdentities);

            if (nOptional > 0)
            {
                sb.Append(" OPTIONAL("); sb.Append(Str.SqlValue(otherIdentities)); sb.Append(')');
            }

            // add virtualIdentities ...
            int nVirtual = otherVirtualIdentities?.Count ?? 0;

            if (nVirtual > 0)
            {
                sb.Append(" VIRTUAL("); sb.Append(Str.SqlValue(otherVirtualIdentities)); sb.Append(')');
            }

            return(sb.ToString());
        }